@@ -63,6 +63,7 @@ const (
63
63
HostClusterLocalDNSZoneName = "cluster.local."
64
64
65
65
lbAddrRetryInterval = 5 * time .Second
66
+ podWaitInterval = 2 * time .Second
66
67
)
67
68
68
69
var (
@@ -230,22 +231,14 @@ func initFederation(cmdOut io.Writer, config util.AdminConfig, cmd *cobra.Comman
230
231
}
231
232
232
233
if ! dryRun {
233
- fmt .Fprintf (cmdOut , "Waiting for control plane to come up" )
234
- for ! podRunning (hostClientset , serverName , initFlags .FederationSystemNamespace ) {
235
- _ , err := fmt .Fprintf (cmdOut , "." )
236
- if err != nil {
237
- return err
238
- }
239
- //wait indefinite if the pod doesn't show up with correct status
240
- time .Sleep (2 * time .Second )
234
+ fedPods := []string {serverName , cmName }
235
+ err = waitForPods (hostClientset , fedPods , initFlags .FederationSystemNamespace )
236
+ if err != nil {
237
+ return err
241
238
}
242
- for ! podRunning (hostClientset , cmName , initFlags .FederationSystemNamespace ) {
243
- _ , err := fmt .Fprintf (cmdOut , "." )
244
- if err != nil {
245
- return err
246
- }
247
- //wait indefinite if the pod doesn't show up with correct status
248
- time .Sleep (2 * time .Second )
239
+ err = waitSrvHealthy (config , initFlags .Name , initFlags .Kubeconfig )
240
+ if err != nil {
241
+ return err
249
242
}
250
243
return printSuccess (cmdOut , ips , hostnames )
251
244
}
@@ -593,19 +586,46 @@ func createControllerManager(clientset *client.Clientset, namespace, name, svcNa
593
586
return clientset .Extensions ().Deployments (namespace ).Create (dep )
594
587
}
595
588
596
- func podRunning (clientset * client.Clientset , name , nameSpace string ) bool {
597
- podList , err := clientset .Core ().Pods (nameSpace ).List (api.ListOptions {})
589
+ func waitForPods (clientset * client.Clientset , fedPods []string , namespace string ) error {
590
+ err := wait .PollInfinite (podWaitInterval , func () (bool , error ) {
591
+ podCheck := len (fedPods )
592
+ podList , err := clientset .Core ().Pods (namespace ).List (api.ListOptions {})
593
+ if err != nil {
594
+ return false , nil
595
+ }
596
+ for _ , pod := range podList .Items {
597
+ for _ , fedPod := range fedPods {
598
+ if strings .HasPrefix (pod .Name , fedPod ) && pod .Status .Phase == "Running" {
599
+ podCheck -= 1
600
+ }
601
+ }
602
+ //ensure that all pods are in running state or keep waiting
603
+ if podCheck == 0 {
604
+ return true , nil
605
+ }
606
+ }
607
+ return false , nil
608
+ })
609
+ return err
610
+ }
611
+
612
+ func waitSrvHealthy (config util.AdminConfig , context , kubeconfig string ) error {
613
+ fedClientSet , err := config .FederationClientset (context , kubeconfig )
598
614
if err != nil {
599
- //Problem in getting pods at this time
600
- return false
615
+ return err
601
616
}
602
-
603
- for _ , pod := range podList .Items {
604
- if strings .Contains (pod .Name , name ) && pod .Status .Phase == "Running" {
605
- return true
617
+ fedDiscoveryClient := fedClientSet .Discovery ()
618
+ err = wait .PollInfinite (podWaitInterval , func () (bool , error ) {
619
+ body , err := fedDiscoveryClient .RESTClient ().Get ().AbsPath ("/healthz" ).Do ().Raw ()
620
+ if err != nil {
621
+ return false , nil
606
622
}
607
- }
608
- return false
623
+ if strings .EqualFold (string (body ), "ok" ) {
624
+ return true , nil
625
+ }
626
+ return false , nil
627
+ })
628
+ return err
609
629
}
610
630
611
631
func printSuccess (cmdOut io.Writer , ips , hostnames []string ) error {
0 commit comments