Commit 01f6e0e6 authored by Erik Wilson's avatar Erik Wilson

Add context to server daemon functions that wait

parent 7aa3d083
...@@ -91,7 +91,7 @@ func Server(ctx context.Context, cfg *config.Control) error { ...@@ -91,7 +91,7 @@ func Server(ctx context.Context, cfg *config.Control) error {
return err return err
} }
if err := waitForAPIServer(runtime); err != nil { if err := waitForAPIServer(ctx, runtime); err != nil {
return err return err
} }
...@@ -105,7 +105,7 @@ func Server(ctx context.Context, cfg *config.Control) error { ...@@ -105,7 +105,7 @@ func Server(ctx context.Context, cfg *config.Control) error {
controllerManager(cfg, runtime) controllerManager(cfg, runtime)
if !cfg.DisableCCM { if !cfg.DisableCCM {
cloudControllerManager(cfg, runtime) cloudControllerManager(ctx, cfg, runtime)
} }
return nil return nil
...@@ -782,7 +782,7 @@ func expired(certFile string) bool { ...@@ -782,7 +782,7 @@ func expired(certFile string) bool {
return certutil.IsCertExpired(certificates[0]) return certutil.IsCertExpired(certificates[0])
} }
func cloudControllerManager(cfg *config.Control, runtime *config.ControlRuntime) { func cloudControllerManager(ctx context.Context, cfg *config.Control, runtime *config.ControlRuntime) {
argsMap := map[string]string{ argsMap := map[string]string{
"kubeconfig": runtime.KubeConfigCloudController, "kubeconfig": runtime.KubeConfigCloudController,
"allocate-node-cidrs": "true", "allocate-node-cidrs": "true",
...@@ -808,8 +808,12 @@ func cloudControllerManager(cfg *config.Control, runtime *config.ControlRuntime) ...@@ -808,8 +808,12 @@ func cloudControllerManager(cfg *config.Control, runtime *config.ControlRuntime)
// check for the cloud controller rbac binding // check for the cloud controller rbac binding
if err := checkForCloudControllerPrivileges(runtime); err != nil { if err := checkForCloudControllerPrivileges(runtime); err != nil {
logrus.Infof("Waiting for cloudcontroller rbac role to be created") logrus.Infof("Waiting for cloudcontroller rbac role to be created")
time.Sleep(time.Second) select {
continue case <-ctx.Done():
logrus.Fatalf("cloud-controller-manager context canceled: %v", ctx.Err())
case <-time.After(time.Second):
continue
}
} }
break break
} }
...@@ -831,7 +835,7 @@ func checkForCloudControllerPrivileges(runtime *config.ControlRuntime) error { ...@@ -831,7 +835,7 @@ func checkForCloudControllerPrivileges(runtime *config.ControlRuntime) error {
return nil return nil
} }
func waitForAPIServer(runtime *config.ControlRuntime) error { func waitForAPIServer(ctx context.Context, runtime *config.ControlRuntime) error {
restConfig, err := clientcmd.BuildConfigFromFlags("", runtime.KubeConfigAdmin) restConfig, err := clientcmd.BuildConfigFromFlags("", runtime.KubeConfigAdmin)
if err != nil { if err != nil {
return err return err
...@@ -849,7 +853,12 @@ func waitForAPIServer(runtime *config.ControlRuntime) error { ...@@ -849,7 +853,12 @@ func waitForAPIServer(runtime *config.ControlRuntime) error {
return nil return nil
} }
logrus.Infof("waiting for apiserver to become available") logrus.Infof("waiting for apiserver to become available")
time.Sleep(1 * time.Second) select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(time.Second):
continue
}
} }
return fmt.Errorf("timeout waiting for apiserver") return fmt.Errorf("timeout waiting for apiserver")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment