mirror of
https://github.com/rancher/k3k.git
synced 2026-08-18 20:07:06 +00:00
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:
@@ -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.
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user