From d0c419dc2202a575b7a426350747f5e6d575f55d Mon Sep 17 00:00:00 2001 From: willie-yao Date: Mon, 13 May 2024 20:26:46 +0000 Subject: [PATCH] Modify ConfigClusterWithBinary to support ControlPlaneMachineCount of 0 --- test/e2e/clusterctl_upgrade.go | 8 +--- test/framework/clusterctl/client.go | 58 ++++++++++------------------- 2 files changed, 20 insertions(+), 46 deletions(-) diff --git a/test/e2e/clusterctl_upgrade.go b/test/e2e/clusterctl_upgrade.go index 0f8c3e917736..f9d1fa576794 100644 --- a/test/e2e/clusterctl_upgrade.go +++ b/test/e2e/clusterctl_upgrade.go @@ -391,9 +391,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg kubernetesVersion = input.E2EConfig.GetVariable(KubernetesVersion) } controlPlaneMachineCount := ptr.To[int64](1) - - // Don't set controlPlaneMachineCount to 0 to satisfy the validation in the cluster template. - if input.ControlPlaneMachineCount != nil && *input.ControlPlaneMachineCount != int64(0) { + if input.ControlPlaneMachineCount != nil { controlPlaneMachineCount = input.ControlPlaneMachineCount } workerMachineCount := ptr.To[int64](1) @@ -445,10 +443,6 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg expectedMachinePoolMachineCount, err := calculateExpectedMachinePoolMachineCount(ctx, managementClusterProxy.GetClient(), workloadClusterNamespace, workloadClusterName) Expect(err).ToNot(HaveOccurred()) - // Account for clusters that have a control plane count of 0. - if input.ControlPlaneMachineCount != nil && *input.ControlPlaneMachineCount == int64(0) { - controlPlaneMachineCount = input.ControlPlaneMachineCount - } expectedMachineCount := *controlPlaneMachineCount + expectedMachineDeploymentMachineCount + expectedMachinePoolMachineCount Byf("Expect %d Machines and %d MachinePool replicas to exist", expectedMachineCount, expectedMachinePoolNodeCount) diff --git a/test/framework/clusterctl/client.go b/test/framework/clusterctl/client.go index 4f96da3e2306..95a02c993398 100644 --- a/test/framework/clusterctl/client.go +++ b/test/framework/clusterctl/client.go @@ -378,49 +378,29 @@ func ConfigClusterWithBinary(_ context.Context, clusterctlBinaryPath string, inp Expect(err).ToNot(HaveOccurred()) clusterctlSupportsGenerateCluster := version.GTE(semver.MustParse("1.0.0")) - var cmd *exec.Cmd + var command string if clusterctlSupportsGenerateCluster { - log.Logf("clusterctl generate cluster %s --infrastructure %s --kubernetes-version %s --control-plane-machine-count %d --worker-machine-count %d --flavor %s", - input.ClusterName, - valueOrDefault(input.InfrastructureProvider), - input.KubernetesVersion, - *input.ControlPlaneMachineCount, - *input.WorkerMachineCount, - valueOrDefault(input.Flavor), - ) - cmd = exec.Command(clusterctlBinaryPath, "generate", "cluster", //nolint:gosec // We don't care about command injection here. - input.ClusterName, - "--infrastructure", input.InfrastructureProvider, - "--kubernetes-version", input.KubernetesVersion, - "--control-plane-machine-count", fmt.Sprint(*input.ControlPlaneMachineCount), - "--worker-machine-count", fmt.Sprint(*input.WorkerMachineCount), - "--flavor", input.Flavor, - "--target-namespace", input.Namespace, - "--config", input.ClusterctlConfigPath, - "--kubeconfig", input.KubeconfigPath, - ) + command = "generate" } else { - log.Logf("clusterctl config cluster %s --infrastructure %s --kubernetes-version %s --control-plane-machine-count %d --worker-machine-count %d --flavor %s", - input.ClusterName, - valueOrDefault(input.InfrastructureProvider), - input.KubernetesVersion, - *input.ControlPlaneMachineCount, - *input.WorkerMachineCount, - valueOrDefault(input.Flavor), - ) - cmd = exec.Command(clusterctlBinaryPath, "config", "cluster", //nolint:gosec // We don't care about command injection here. - input.ClusterName, - "--infrastructure", input.InfrastructureProvider, - "--kubernetes-version", input.KubernetesVersion, - "--control-plane-machine-count", fmt.Sprint(*input.ControlPlaneMachineCount), - "--worker-machine-count", fmt.Sprint(*input.WorkerMachineCount), - "--flavor", input.Flavor, - "--target-namespace", input.Namespace, - "--config", input.ClusterctlConfigPath, - "--kubeconfig", input.KubeconfigPath, - ) + command = "config" } + args := []string{command, "cluster", + input.ClusterName, + "--infrastructure", input.InfrastructureProvider, + "--kubernetes-version", input.KubernetesVersion, + "--worker-machine-count", fmt.Sprint(*input.WorkerMachineCount), + "--flavor", input.Flavor, + "--target-namespace", input.Namespace, + "--config", input.ClusterctlConfigPath, + "--kubeconfig", input.KubeconfigPath, + } + if input.ControlPlaneMachineCount != nil && *input.ControlPlaneMachineCount > 0 { + args = append(args, "--control-plane-machine-count", fmt.Sprint(*input.ControlPlaneMachineCount)) + } + log.Logf("clusterctl %s", strings.Join(args, " ")) + + cmd := exec.Command(clusterctlBinaryPath, args...) //nolint:gosec // We don't care about command injection here. out, err := cmd.Output() _ = os.WriteFile(filepath.Join(input.LogFolder, fmt.Sprintf("%s-cluster-template.yaml", input.ClusterName)), out, 0644) //nolint:gosec // this is a log file to be shared via prow artifacts var stdErr string