Skip to content

Commit 0a1f790

Browse files
authored
Merge pull request #5377 from randomvariable/moar-capi-upgrade-variables
🌱 Allow passing in provider contract and clusterctl binary in the clusterctl upgrade spec
2 parents 613bf91 + d939d43 commit 0a1f790

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

test/e2e/clusterctl_upgrade.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,22 @@ const (
5353

5454
// ClusterctlUpgradeSpecInput is the input for ClusterctlUpgradeSpec.
5555
type ClusterctlUpgradeSpecInput struct {
56-
E2EConfig *clusterctl.E2EConfig
57-
ClusterctlConfigPath string
58-
BootstrapClusterProxy framework.ClusterProxy
59-
ArtifactFolder string
60-
SkipCleanup bool
61-
PreUpgrade func(managementClusterProxy framework.ClusterProxy)
62-
PostUpgrade func(managementClusterProxy framework.ClusterProxy)
63-
MgmtFlavor string
64-
WorkloadFlavor string
56+
E2EConfig *clusterctl.E2EConfig
57+
ClusterctlConfigPath string
58+
BootstrapClusterProxy framework.ClusterProxy
59+
ArtifactFolder string
60+
InitWithBinary string
61+
InitWithProvidersContract string
62+
SkipCleanup bool
63+
PreUpgrade func(managementClusterProxy framework.ClusterProxy)
64+
PostUpgrade func(managementClusterProxy framework.ClusterProxy)
65+
MgmtFlavor string
66+
WorkloadFlavor string
6567
}
6668

6769
// ClusterctlUpgradeSpec implements a test that verifies clusterctl upgrade of a management cluster.
6870
//
69-
// NOTE: this test is designed to test v1alpha3 --> v1alpha4 upgrades.
71+
// NOTE: this test is designed to test older versions of Cluster API --> v1beta1 upgrades.
7072
func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpgradeSpecInput) {
7173
var (
7274
specName = "clusterctl-upgrade"
@@ -76,6 +78,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
7678
testCancelWatches context.CancelFunc
7779

7880
managementClusterName string
81+
clusterctlBinaryURL string
7982
managementClusterNamespace *corev1.Namespace
8083
managementClusterCancelWatches context.CancelFunc
8184
managementClusterResources *clusterctl.ApplyClusterTemplateAndWaitResult
@@ -90,8 +93,16 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
9093
Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil when calling %s spec", specName)
9194
Expect(input.ClusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling %s spec", specName)
9295
Expect(input.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil when calling %s spec", specName)
93-
Expect(input.E2EConfig.Variables).To(HaveKey(initWithBinaryVariableName), "Invalid argument. %s variable must be defined when calling %s spec", initWithBinaryVariableName, specName)
94-
Expect(input.E2EConfig.Variables[initWithBinaryVariableName]).ToNot(BeEmpty(), "Invalid argument. %s variable can't be empty when calling %s spec", initWithBinaryVariableName, specName)
96+
var clusterctlBinaryURLTemplate string
97+
if input.InitWithBinary == "" {
98+
Expect(input.E2EConfig.Variables).To(HaveKey(initWithBinaryVariableName), "Invalid argument. %s variable must be defined when calling %s spec", initWithBinaryVariableName, specName)
99+
Expect(input.E2EConfig.Variables[initWithBinaryVariableName]).ToNot(BeEmpty(), "Invalid argument. %s variable can't be empty when calling %s spec", initWithBinaryVariableName, specName)
100+
clusterctlBinaryURLTemplate = input.E2EConfig.GetVariable(initWithBinaryVariableName)
101+
} else {
102+
clusterctlBinaryURLTemplate = input.InitWithBinary
103+
}
104+
clusterctlBinaryURLReplacer := strings.NewReplacer("{OS}", runtime.GOOS, "{ARCH}", runtime.GOARCH)
105+
clusterctlBinaryURL = clusterctlBinaryURLReplacer.Replace(clusterctlBinaryURLTemplate)
95106
Expect(input.E2EConfig.Variables).To(HaveKey(initWithKubernetesVersion))
96107
Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersion))
97108
Expect(os.MkdirAll(input.ArtifactFolder, 0750)).To(Succeed(), "Invalid argument. input.ArtifactFolder can't be created for %s spec", specName)
@@ -143,10 +154,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
143154
// Get a ClusterProxy so we can interact with the workload cluster
144155
managementClusterProxy = input.BootstrapClusterProxy.GetWorkloadCluster(ctx, cluster.Namespace, cluster.Name)
145156

146-
// Download the v1alpha3 clusterctl version to be used for setting up the management cluster to be upgraded
147-
clusterctlBinaryURL := input.E2EConfig.GetVariable(initWithBinaryVariableName)
148-
clusterctlBinaryURL = strings.ReplaceAll(clusterctlBinaryURL, "{OS}", runtime.GOOS)
149-
clusterctlBinaryURL = strings.ReplaceAll(clusterctlBinaryURL, "{ARCH}", runtime.GOARCH)
157+
// Download the older clusterctl version to be used for setting up the management cluster to be upgraded
150158

151159
log.Logf("Downloading clusterctl binary from %s", clusterctlBinaryURL)
152160
clusterctlBinaryPath := downloadToTmpFile(clusterctlBinaryURL)
@@ -164,6 +172,9 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
164172
if input.E2EConfig.HasVariable(initWithProvidersContract) {
165173
contract = input.E2EConfig.GetVariable(initWithProvidersContract)
166174
}
175+
if input.InitWithProvidersContract != "" {
176+
contract = input.InitWithProvidersContract
177+
}
167178

168179
clusterctl.InitManagementClusterAndWatchControllerLogs(ctx, clusterctl.InitManagementClusterAndWatchControllerLogsInput{
169180
ClusterctlBinaryPath: clusterctlBinaryPath, // use older version of clusterctl to init the management cluster

0 commit comments

Comments
 (0)