From 4c6f8990f2e54945e1b0348fa31ad75a5ac60a0c Mon Sep 17 00:00:00 2001 From: willie-yao Date: Thu, 9 May 2024 22:58:18 +0000 Subject: [PATCH 1/2] Allow control plane count to be configurable in clusterctl upgrade test. --- test/e2e/clusterctl_upgrade.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/e2e/clusterctl_upgrade.go b/test/e2e/clusterctl_upgrade.go index 7168b71d66f2..0f8c3e917736 100644 --- a/test/e2e/clusterctl_upgrade.go +++ b/test/e2e/clusterctl_upgrade.go @@ -130,6 +130,9 @@ type ClusterctlUpgradeSpecInput struct { // If not set, the test will upgrade once to the v1beta1 contract. // For some examples see clusterctl_upgrade_test.go Upgrades []ClusterctlUpgradeSpecInputUpgrade + + // ControlPlaneMachineCount specifies the number of control plane machines to create in the workload cluster. + ControlPlaneMachineCount *int64 } // ClusterctlUpgradeSpecInputUpgrade defines an upgrade. @@ -388,6 +391,11 @@ 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) { + controlPlaneMachineCount = input.ControlPlaneMachineCount + } workerMachineCount := ptr.To[int64](1) log.Logf("Creating the workload cluster with name %q using the %q template (Kubernetes %s, %d control-plane machines, %d worker machines)", @@ -436,6 +444,11 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg expectedMachinePoolNodeCount := calculateExpectedMachinePoolNodeCount(ctx, managementClusterProxy.GetClient(), workloadClusterUnstructured, coreCAPIStorageVersion) 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) From d0c419dc2202a575b7a426350747f5e6d575f55d Mon Sep 17 00:00:00 2001 From: willie-yao Date: Mon, 13 May 2024 20:26:46 +0000 Subject: [PATCH 2/2] 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