Skip to content

Commit aed7eed

Browse files
author
Irfan Ur Rehman
committed
[Federation] Wait for control plane pods in kubefed init
1 parent de59ede commit aed7eed

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

federation/pkg/kubefed/init/init.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,23 @@ func initFederation(cmdOut io.Writer, config util.AdminConfig, cmd *cobra.Comman
230230
}
231231

232232
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)
241+
}
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)
249+
}
233250
return printSuccess(cmdOut, ips, hostnames)
234251
}
235252
_, err = fmt.Fprintf(cmdOut, "Federation control plane runs (dry run)\n")
@@ -576,6 +593,21 @@ func createControllerManager(clientset *client.Clientset, namespace, name, svcNa
576593
return clientset.Extensions().Deployments(namespace).Create(dep)
577594
}
578595

596+
func podRunning(clientset *client.Clientset, name, nameSpace string) bool {
597+
podList, err := clientset.Core().Pods(nameSpace).List(api.ListOptions{})
598+
if err != nil {
599+
//Problem in getting pods at this time
600+
return false
601+
}
602+
603+
for _, pod := range podList.Items {
604+
if strings.Contains(pod.Name, name) && pod.Status.Phase == "Running" {
605+
return true
606+
}
607+
}
608+
return false
609+
}
610+
579611
func printSuccess(cmdOut io.Writer, ips, hostnames []string) error {
580612
svcEndpoints := append(ips, hostnames...)
581613
_, err := fmt.Fprintf(cmdOut, "Federation API server is running at: %s\n", strings.Join(svcEndpoints, ", "))

0 commit comments

Comments
 (0)