Skip to content

Commit d0c419d

Browse files
committed
Modify ConfigClusterWithBinary to support ControlPlaneMachineCount of 0
1 parent 4c6f899 commit d0c419d

File tree

2 files changed

+20
-46
lines changed

2 files changed

+20
-46
lines changed

test/e2e/clusterctl_upgrade.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
391391
kubernetesVersion = input.E2EConfig.GetVariable(KubernetesVersion)
392392
}
393393
controlPlaneMachineCount := ptr.To[int64](1)
394-
395-
// Don't set controlPlaneMachineCount to 0 to satisfy the validation in the cluster template.
396-
if input.ControlPlaneMachineCount != nil && *input.ControlPlaneMachineCount != int64(0) {
394+
if input.ControlPlaneMachineCount != nil {
397395
controlPlaneMachineCount = input.ControlPlaneMachineCount
398396
}
399397
workerMachineCount := ptr.To[int64](1)
@@ -445,10 +443,6 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
445443
expectedMachinePoolMachineCount, err := calculateExpectedMachinePoolMachineCount(ctx, managementClusterProxy.GetClient(), workloadClusterNamespace, workloadClusterName)
446444
Expect(err).ToNot(HaveOccurred())
447445

448-
// Account for clusters that have a control plane count of 0.
449-
if input.ControlPlaneMachineCount != nil && *input.ControlPlaneMachineCount == int64(0) {
450-
controlPlaneMachineCount = input.ControlPlaneMachineCount
451-
}
452446
expectedMachineCount := *controlPlaneMachineCount + expectedMachineDeploymentMachineCount + expectedMachinePoolMachineCount
453447

454448
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)