diff --git a/pkg/client/cluster.go b/pkg/client/cluster.go index 4f2a9ad2..6047070b 100644 --- a/pkg/client/cluster.go +++ b/pkg/client/cluster.go @@ -42,6 +42,7 @@ import ( runtimeErr "github.com/rancher/k3d/v4/pkg/runtimes/errors" "github.com/rancher/k3d/v4/pkg/types" k3d "github.com/rancher/k3d/v4/pkg/types" + "github.com/rancher/k3d/v4/pkg/types/k3s" "github.com/rancher/k3d/v4/pkg/util" "github.com/rancher/k3d/v4/version" log "github.com/sirupsen/logrus" @@ -97,8 +98,10 @@ func ClusterRun(ctx context.Context, runtime k3drt.Runtime, clusterConfig *confi } // create the registry hosting configmap - if err := prepCreateLocalRegistryHostingConfigMap(ctx, runtime, &clusterConfig.Cluster); err != nil { - log.Warnf("Failed to create LocalRegistryHosting ConfigMap: %+v", err) + if len(clusterConfig.ClusterCreateOpts.Registries.Use) > 0 { + if err := prepCreateLocalRegistryHostingConfigMap(ctx, runtime, &clusterConfig.Cluster); err != nil { + log.Warnf("Failed to create LocalRegistryHosting ConfigMap: %+v", err) + } } return nil @@ -171,6 +174,8 @@ func ClusterPrep(ctx context.Context, runtime k3drt.Runtime, clusterConfig *conf // Use existing registries (including the new one, if created) log.Tracef("Using Registries: %+v", clusterConfig.ClusterCreateOpts.Registries.Use) + var registryConfig *k3s.Registry + if len(clusterConfig.ClusterCreateOpts.Registries.Use) > 0 { // ensure that all selected registries exist and connect them to the cluster network for _, externalReg := range clusterConfig.ClusterCreateOpts.Registries.Use { @@ -189,41 +194,48 @@ func ClusterPrep(ctx context.Context, runtime k3drt.Runtime, clusterConfig *conf return fmt.Errorf("Failed to generate registry config file for k3s: %+v", err) } - // merge with pre-existing, referenced registries.yaml - if clusterConfig.ClusterCreateOpts.Registries.Config != nil { - if err := RegistryMergeConfig(ctx, regConf, clusterConfig.ClusterCreateOpts.Registries.Config); err != nil { - return err - } - log.Tracef("Merged registry config: %+v", regConf) - } - regConfBytes, err := yaml.Marshal(®Conf) + // generate the LocalRegistryHosting configmap + regCm, err := RegistryGenerateLocalRegistryHostingConfigMapYAML(ctx, clusterConfig.ClusterCreateOpts.Registries.Use) if err != nil { - return fmt.Errorf("Failed to marshal registry configuration: %+v", err) + return fmt.Errorf("Failed to generate LocalRegistryHosting configmap: %+v", err) } + log.Tracef("Writing LocalRegistryHosting YAML:\n%s", string(regCm)) clusterConfig.ClusterCreateOpts.NodeHooks = append(clusterConfig.ClusterCreateOpts.NodeHooks, k3d.NodeHook{ Stage: k3d.LifecycleStagePreStart, Action: actions.WriteFileAction{ Runtime: runtime, - Content: regConfBytes, - Dest: k3d.DefaultRegistriesFilePath, + Content: regCm, + Dest: "/tmp/reg.yaml", }, }) - // generate the LocalRegistryHosting configmap - regCm, err := RegistryGenerateLocalRegistryHostingConfigMapYAML(ctx, clusterConfig.ClusterCreateOpts.Registries.Use) + registryConfig = regConf + + } + // merge with pre-existing, referenced registries.yaml + if clusterConfig.ClusterCreateOpts.Registries.Config != nil { + if registryConfig != nil { + if err := RegistryMergeConfig(ctx, registryConfig, clusterConfig.ClusterCreateOpts.Registries.Config); err != nil { + return err + } + log.Tracef("Merged registry config: %+v", registryConfig) + } else { + registryConfig = clusterConfig.ClusterCreateOpts.Registries.Config + } + } + if registryConfig != nil { + regConfBytes, err := yaml.Marshal(®istryConfig) if err != nil { - return fmt.Errorf("Failed to generate LocalRegistryHosting configmap: %+v", err) + return fmt.Errorf("Failed to marshal registry configuration: %+v", err) } - log.Tracef("Writing LocalRegistryHosting YAML:\n%s", string(regCm)) clusterConfig.ClusterCreateOpts.NodeHooks = append(clusterConfig.ClusterCreateOpts.NodeHooks, k3d.NodeHook{ Stage: k3d.LifecycleStagePreStart, Action: actions.WriteFileAction{ Runtime: runtime, - Content: regCm, - Dest: "/tmp/reg.yaml", + Content: regConfBytes, + Dest: k3d.DefaultRegistriesFilePath, }, }) - } return nil diff --git a/tests/common.sh b/tests/common.sh index ae06586b..fe5227c9 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -82,7 +82,7 @@ check_clusters() { check_cluster_count() { expectedClusterCount=$1 - actualClusterCount=$($EXE cluster list --no-headers | wc -l) + actualClusterCount=$(LOG_LEVEL=warn $EXE cluster list --no-headers | wc -l) # this must always have a loglevel of <= warn or it will fail if [[ $actualClusterCount != $expectedClusterCount ]]; then failed "incorrect number of clusters available: $actualClusterCount != $expectedClusterCount" return 1 diff --git a/tests/test_full_lifecycle.sh b/tests/test_full_lifecycle.sh index f64bcf2d..d4fd8db6 100755 --- a/tests/test_full_lifecycle.sh +++ b/tests/test_full_lifecycle.sh @@ -24,7 +24,7 @@ info "Creating cluster $clustername..." $EXE cluster create "$clustername" --agents 1 --api-port 6443 --wait --timeout 360s $EXTRA_FLAG || failed "could not create cluster $clustername $EXTRA_TITLE" info "Sleeping for 5 seconds to give the cluster enough time to get ready..." -sleep 5 +sleep 10 # 1. check initial access to the cluster info "Checking that we have access to the cluster..."