Skip to content

Commit a066d37

Browse files
authored
Merge pull request #10584 from willie-yao/clusterctl-upgrade-cpcount
🌱 Allow control plane count to be configurable in clusterctl upgrade test.
2 parents abd5d8d + d0c419d commit a066d37

File tree

2 files changed

+26
-39
lines changed

2 files changed

+26
-39
lines changed

test/e2e/clusterctl_upgrade.go

+7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ type ClusterctlUpgradeSpecInput struct {
130130
// If not set, the test will upgrade once to the v1beta1 contract.
131131
// For some examples see clusterctl_upgrade_test.go
132132
Upgrades []ClusterctlUpgradeSpecInputUpgrade
133+
134+
// ControlPlaneMachineCount specifies the number of control plane machines to create in the workload cluster.
135+
ControlPlaneMachineCount *int64
133136
}
134137

135138
// ClusterctlUpgradeSpecInputUpgrade defines an upgrade.
@@ -388,6 +391,9 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
388391
kubernetesVersion = input.E2EConfig.GetVariable(KubernetesVersion)
389392
}
390393
controlPlaneMachineCount := ptr.To[int64](1)
394+
if input.ControlPlaneMachineCount != nil {
395+
controlPlaneMachineCount = input.ControlPlaneMachineCount
396+
}
391397
workerMachineCount := ptr.To[int64](1)
392398

393399
log.Logf("Creating the workload cluster with name %q using the %q template (Kubernetes %s, %d control-plane machines, %d worker machines)",
@@ -436,6 +442,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
436442
expectedMachinePoolNodeCount := calculateExpectedMachinePoolNodeCount(ctx, managementClusterProxy.GetClient(), workloadClusterUnstructured, coreCAPIStorageVersion)
437443
expectedMachinePoolMachineCount, err := calculateExpectedMachinePoolMachineCount(ctx, managementClusterProxy.GetClient(), workloadClusterNamespace, workloadClusterName)
438444
Expect(err).ToNot(HaveOccurred())
445+
439446
expectedMachineCount := *controlPlaneMachineCount + expectedMachineDeploymentMachineCount + expectedMachinePoolMachineCount
440447

441448
Byf("Expect %d Machines and %d MachinePool replicas to exist", expectedMachineCount, expectedMachinePoolNodeCount)

test/framework/clusterctl/client.go

+19-39
Original file line numberDiff line numberDiff line change
@@ -378,49 +378,29 @@ func ConfigClusterWithBinary(_ context.Context, clusterctlBinaryPath string, inp
378378
Expect(err).ToNot(HaveOccurred())
379379
clusterctlSupportsGenerateCluster := version.GTE(semver.MustParse("1.0.0"))
380380

381-
var cmd *exec.Cmd
381+
var command string
382382
if clusterctlSupportsGenerateCluster {
383-
log.Logf("clusterctl generate cluster %s --infrastructure %s --kubernetes-version %s --control-plane-machine-count %d --worker-machine-count %d --flavor %s",
384-
input.ClusterName,
385-
valueOrDefault(input.InfrastructureProvider),
386-
input.KubernetesVersion,
387-
*input.ControlPlaneMachineCount,
388-
*input.WorkerMachineCount,
389-
valueOrDefault(input.Flavor),
390-
)
391-
cmd = exec.Command(clusterctlBinaryPath, "generate", "cluster", //nolint:gosec // We don't care about command injection here.
392-
input.ClusterName,
393-
"--infrastructure", input.InfrastructureProvider,
394-
"--kubernetes-version", input.KubernetesVersion,
395-
"--control-plane-machine-count", fmt.Sprint(*input.ControlPlaneMachineCount),
396-
"--worker-machine-count", fmt.Sprint(*input.WorkerMachineCount),
397-
"--flavor", input.Flavor,
398-
"--target-namespace", input.Namespace,
399-
"--config", input.ClusterctlConfigPath,
400-
"--kubeconfig", input.KubeconfigPath,
401-
)
383+
command = "generate"
402384
} else {
403-
log.Logf("clusterctl config cluster %s --infrastructure %s --kubernetes-version %s --control-plane-machine-count %d --worker-machine-count %d --flavor %s",
404-
input.ClusterName,
405-
valueOrDefault(input.InfrastructureProvider),
406-
input.KubernetesVersion,
407-
*input.ControlPlaneMachineCount,
408-
*input.WorkerMachineCount,
409-
valueOrDefault(input.Flavor),
410-
)
411-
cmd = exec.Command(clusterctlBinaryPath, "config", "cluster", //nolint:gosec // We don't care about command injection here.
412-
input.ClusterName,
413-
"--infrastructure", input.InfrastructureProvider,
414-
"--kubernetes-version", input.KubernetesVersion,
415-
"--control-plane-machine-count", fmt.Sprint(*input.ControlPlaneMachineCount),
416-
"--worker-machine-count", fmt.Sprint(*input.WorkerMachineCount),
417-
"--flavor", input.Flavor,
418-
"--target-namespace", input.Namespace,
419-
"--config", input.ClusterctlConfigPath,
420-
"--kubeconfig", input.KubeconfigPath,
421-
)
385+
command = "config"
422386
}
423387

388+
args := []string{command, "cluster",
389+
input.ClusterName,
390+
"--infrastructure", input.InfrastructureProvider,
391+
"--kubernetes-version", input.KubernetesVersion,
392+
"--worker-machine-count", fmt.Sprint(*input.WorkerMachineCount),
393+
"--flavor", input.Flavor,
394+
"--target-namespace", input.Namespace,
395+
"--config", input.ClusterctlConfigPath,
396+
"--kubeconfig", input.KubeconfigPath,
397+
}
398+
if input.ControlPlaneMachineCount != nil && *input.ControlPlaneMachineCount > 0 {
399+
args = append(args, "--control-plane-machine-count", fmt.Sprint(*input.ControlPlaneMachineCount))
400+
}
401+
log.Logf("clusterctl %s", strings.Join(args, " "))
402+
403+
cmd := exec.Command(clusterctlBinaryPath, args...) //nolint:gosec // We don't care about command injection here.
424404
out, err := cmd.Output()
425405
_ = 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
426406
var stdErr string

0 commit comments

Comments
 (0)