From a3076af38f3d869bb6c6cd482b7811ac9542e606 Mon Sep 17 00:00:00 2001 From: Hussein Galal Date: Fri, 17 Oct 2025 16:51:40 +0300 Subject: [PATCH] Increase timeout and add timeout option (#514) * Increase timeout and add timeout option Signed-off-by: galal-hussein * Increase timeout and add timeout option Signed-off-by: galal-hussein --------- Signed-off-by: galal-hussein --- cli/cmds/cluster_create.go | 6 +++--- cli/cmds/cluster_create_flags.go | 2 ++ docs/cli/k3kcli_cluster_create.md | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cli/cmds/cluster_create.go b/cli/cmds/cluster_create.go index e033199b..2e4f1797 100644 --- a/cli/cmds/cluster_create.go +++ b/cli/cmds/cluster_create.go @@ -46,6 +46,7 @@ type CreateConfig struct { policy string mirrorHostNodes bool customCertsPath string + timeout time.Duration } func NewClusterCreateCmd(appCtx *AppContext) *cobra.Command { @@ -141,7 +142,7 @@ func createAction(appCtx *AppContext, config *CreateConfig) func(cmd *cobra.Comm logrus.Infof("Waiting for cluster to be available..") - if err := waitForCluster(ctx, client, cluster); err != nil { + if err := waitForCluster(ctx, client, cluster, config.timeout); err != nil { return fmt.Errorf("failed to wait for cluster to become ready (status: %s): %w", cluster.Status.Phase, err) } @@ -256,9 +257,8 @@ func env(envSlice []string) []v1.EnvVar { return envVars } -func waitForCluster(ctx context.Context, k8sClient client.Client, cluster *v1beta1.Cluster) error { +func waitForCluster(ctx context.Context, k8sClient client.Client, cluster *v1beta1.Cluster, timeout time.Duration) error { interval := 5 * time.Second - timeout := 2 * time.Minute return wait.PollUntilContextTimeout(ctx, interval, timeout, true, func(ctx context.Context) (bool, error) { key := client.ObjectKeyFromObject(cluster) diff --git a/cli/cmds/cluster_create_flags.go b/cli/cmds/cluster_create_flags.go index 9a84c40d..8b194deb 100644 --- a/cli/cmds/cluster_create_flags.go +++ b/cli/cmds/cluster_create_flags.go @@ -2,6 +2,7 @@ package cmds import ( "errors" + "time" "github.com/spf13/cobra" "k8s.io/apimachinery/pkg/api/resource" @@ -28,6 +29,7 @@ func createFlags(cmd *cobra.Command, cfg *CreateConfig) { cmd.Flags().StringVar(&cfg.kubeconfigServerHost, "kubeconfig-server", "", "override the kubeconfig server host") cmd.Flags().StringVar(&cfg.policy, "policy", "", "The policy to create the cluster in") cmd.Flags().StringVar(&cfg.customCertsPath, "custom-certs", "", "The path for custom certificate directory") + cmd.Flags().DurationVar(&cfg.timeout, "timeout", 3*time.Minute, "The timeout for waiting for the cluster to become ready (e.g., 10s, 5m, 1h).") } func validateCreateConfig(cfg *CreateConfig) error { diff --git a/docs/cli/k3kcli_cluster_create.md b/docs/cli/k3kcli_cluster_create.md index fcd1c9af..823a8663 100644 --- a/docs/cli/k3kcli_cluster_create.md +++ b/docs/cli/k3kcli_cluster_create.md @@ -33,6 +33,7 @@ k3kcli cluster create [command options] NAME --service-cidr string service CIDR --storage-class-name string storage class name for dynamic persistence type --storage-request-size string storage size for dynamic persistence type + --timeout duration The timeout for waiting for the cluster to become ready (e.g., 10s, 5m, 1h). (default 3m0s) --token string token of the cluster --version string k3s version ```