From aed7eedaf3846c8fcc30918736622cc5fe21668e Mon Sep 17 00:00:00 2001 From: Irfan Ur Rehman Date: Mon, 26 Dec 2016 14:31:36 +0530 Subject: [PATCH] [Federation] Wait for control plane pods in kubefed init --- federation/pkg/kubefed/init/init.go | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/federation/pkg/kubefed/init/init.go b/federation/pkg/kubefed/init/init.go index 197328a6026..423f7115027 100644 --- a/federation/pkg/kubefed/init/init.go +++ b/federation/pkg/kubefed/init/init.go @@ -230,6 +230,23 @@ func initFederation(cmdOut io.Writer, config util.AdminConfig, cmd *cobra.Comman } if !dryRun { + fmt.Fprintf(cmdOut, "Waiting for control plane to come up") + for !podRunning(hostClientset, serverName, initFlags.FederationSystemNamespace) { + _, err := fmt.Fprintf(cmdOut, ".") + if err != nil { + return err + } + //wait indefinite if the pod doesn't show up with correct status + time.Sleep(2 * time.Second) + } + for !podRunning(hostClientset, cmName, initFlags.FederationSystemNamespace) { + _, err := fmt.Fprintf(cmdOut, ".") + if err != nil { + return err + } + //wait indefinite if the pod doesn't show up with correct status + time.Sleep(2 * time.Second) + } return printSuccess(cmdOut, ips, hostnames) } _, err = fmt.Fprintf(cmdOut, "Federation control plane runs (dry run)\n") @@ -576,6 +593,21 @@ func createControllerManager(clientset *client.Clientset, namespace, name, svcNa return clientset.Extensions().Deployments(namespace).Create(dep) } +func podRunning(clientset *client.Clientset, name, nameSpace string) bool { + podList, err := clientset.Core().Pods(nameSpace).List(api.ListOptions{}) + if err != nil { + //Problem in getting pods at this time + return false + } + + for _, pod := range podList.Items { + if strings.Contains(pod.Name, name) && pod.Status.Phase == "Running" { + return true + } + } + return false +} + func printSuccess(cmdOut io.Writer, ips, hostnames []string) error { svcEndpoints := append(ips, hostnames...) _, err := fmt.Fprintf(cmdOut, "Federation API server is running at: %s\n", strings.Join(svcEndpoints, ", "))