Add K3K prefix to k3kcli env vars, align cli test, add failCount (#962)

* align test-cli

* test context

* increase timeout

* Enhance cluster readiness check with failure count limit
Add prefix K3K to env vars
This commit is contained in:
Enrico Candino
2026-07-01 11:14:37 +02:00
committed by GitHub
parent 3abffae92d
commit ed3e901229
4 changed files with 69 additions and 11 deletions
+9 -2
View File
@@ -77,7 +77,7 @@ func NewClusterCreateCmd(appCtx *AppContext) *cobra.Command {
func createAction(appCtx *AppContext, config *CreateConfig) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
ctx := cmd.Context()
client := appCtx.Client
name := args[0]
@@ -311,6 +311,7 @@ func waitForClusterReconciled(ctx context.Context, k8sClient client.Client, clus
func waitForClusterReady(ctx context.Context, k8sClient client.Client, cluster *v1beta1.Cluster, timeout time.Duration) error {
interval := 5 * time.Second
failCount := 0
return wait.PollUntilContextTimeout(ctx, interval, timeout, true, func(ctx context.Context) (bool, error) {
key := client.ObjectKeyFromObject(cluster)
@@ -325,7 +326,13 @@ func waitForClusterReady(ctx context.Context, k8sClient client.Client, cluster *
// If resource failed -> stop polling with an error
if cluster.Status.Phase == v1beta1.ClusterFailed {
return true, fmt.Errorf("cluster creation failed: %s", cluster.Status.Phase)
failCount++
if failCount > 3 {
return true, fmt.Errorf("cluster creation failed: %s", cluster.Status.Phase)
}
return false, nil
}
// Condition not met, continue polling.
+1
View File
@@ -92,6 +92,7 @@ func CobraFlagNamespace(appCtx *AppContext, flag *pflag.FlagSet) {
}
func InitializeConfig(cmd *cobra.Command) {
viper.SetEnvPrefix("K3K")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()