From 9cd85f7b20c544bc127ca75582535d8601332754 Mon Sep 17 00:00:00 2001 From: Vince Prignano Date: Fri, 14 Jun 2019 12:56:22 -0700 Subject: [PATCH] Add CLUSTER_API_KUBECONFIG_READY_TIMEOUT to clusterctl (#1026) Signed-off-by: Vince Prignano --- cmd/clusterctl/README.md | 1 + cmd/clusterctl/phases/getkubeconfig.go | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/clusterctl/README.md b/cmd/clusterctl/README.md index 5b3147030417..222af00d02a1 100644 --- a/cmd/clusterctl/README.md +++ b/cmd/clusterctl/README.md @@ -63,6 +63,7 @@ Additional advanced flags can be found via help. Also, some environment variables are supported: `CLUSTER_API_MACHINE_READY_TIMEOUT`: set this value to adjust the timeout value in minutes for a machine to become ready, The default timeout is currently 30 minutes, `export CLUSTER_API_MACHINE_READY_TIMEOUT=45` will extend the timeout value to 45 minutes. +`CLUSTER_API_KUBECONFIG_READY_TIMEOUT`: set this value to adjust the timeout value in minutes to wait for the KubeConfig to be ready. Defaults to 20 minutes. ```shell ./clusterctl create cluster --help diff --git a/cmd/clusterctl/phases/getkubeconfig.go b/cmd/clusterctl/phases/getkubeconfig.go index a119a883c0eb..47589b004fec 100644 --- a/cmd/clusterctl/phases/getkubeconfig.go +++ b/cmd/clusterctl/phases/getkubeconfig.go @@ -20,6 +20,7 @@ import ( "fmt" "io/ioutil" "os" + "strconv" "time" "k8s.io/klog" @@ -29,8 +30,9 @@ import ( ) const ( - retryKubeConfigReady = 10 * time.Second - timeoutKubeconfigReady = 20 * time.Minute + TimeoutMachineReadyEnv = "CLUSTER_API_KUBECONFIG_READY_TIMEOUT" + defaultTimeoutKubeconfigReady = 20 * time.Minute + retryKubeConfigReady = 10 * time.Second ) // GetKubeconfig returns a kubeconfig for the target cluster @@ -49,8 +51,17 @@ func GetKubeconfig(bootstrapClient clusterclient.Client, provider provider.Deplo } func waitForKubeconfigReady(bootstrapClient clusterclient.Client, provider provider.Deployer, clusterName, namespace string) (string, error) { + timeout := defaultTimeoutKubeconfigReady + if v := os.Getenv(TimeoutMachineReadyEnv); v != "" { + t, err := strconv.Atoi(v) + if err == nil { + timeout = time.Duration(t) * time.Minute + klog.V(4).Infof("Setting KubeConfg timeout to %v", timeout) + } + } + kubeconfig := "" - err := util.PollImmediate(retryKubeConfigReady, timeoutKubeconfigReady, func() (bool, error) { + err := util.PollImmediate(retryKubeConfigReady, timeout, func() (bool, error) { cluster, controlPlane, _, err := clusterclient.GetClusterAPIObject(bootstrapClient, clusterName, namespace) if err != nil { return false, err