[Federation] Wait for control plane pods in kubefed init

This commit is contained in:
Irfan Ur Rehman
2016-12-26 14:31:36 +05:30
parent de59ede6b2
commit aed7eedaf3

View File

@@ -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, ", "))