Skip to content

Commit e032bec

Browse files
authored
Merge pull request #7341 from Nordix/Add-custom-upgrade-option/mohammed
🌱 Add custom upgrade option to e2e
2 parents bb6df67 + 48ad7f5 commit e032bec

File tree

3 files changed

+122
-34
lines changed

3 files changed

+122
-34
lines changed

test/e2e/clusterctl_upgrade.go

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ type ClusterctlUpgradeSpecInput struct {
8787
MgmtFlavor string
8888
CNIManifestPath string
8989
WorkloadFlavor string
90+
// Custom providers can be specified to upgrade to a pre-release or a custom version instead of upgrading to the latest using contact
91+
CoreProvider string
92+
BootstrapProviders []string
93+
ControlPlaneProviders []string
94+
InfrastructureProviders []string
95+
IPAMProviders []string
96+
RuntimeExtensionProviders []string
9097
}
9198

9299
// ClusterctlUpgradeSpec implements a test that verifies clusterctl upgrade of a management cluster.
@@ -345,15 +352,38 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
345352
client.MatchingLabels{clusterv1.ClusterLabelName: workLoadClusterName},
346353
)
347354
Expect(err).NotTo(HaveOccurred())
348-
349-
By("Upgrading providers to the latest version available")
350-
clusterctl.UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{
351-
ClusterctlConfigPath: input.ClusterctlConfigPath,
352-
ClusterctlVariables: input.UpgradeClusterctlVariables,
353-
ClusterProxy: managementClusterProxy,
354-
Contract: clusterv1.GroupVersion.Version,
355-
LogFolder: filepath.Join(input.ArtifactFolder, "clusters", cluster.Name),
356-
}, input.E2EConfig.GetIntervals(specName, "wait-controllers")...)
355+
// Check if the user want a custom upgrade
356+
isCustomUpgrade := input.CoreProvider != "" ||
357+
len(input.BootstrapProviders) > 0 ||
358+
len(input.ControlPlaneProviders) > 0 ||
359+
len(input.InfrastructureProviders) > 0 ||
360+
len(input.IPAMProviders) > 0 ||
361+
len(input.RuntimeExtensionProviders) > 0
362+
363+
if isCustomUpgrade {
364+
By("Upgrading providers to custom versions")
365+
clusterctl.UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{
366+
ClusterctlConfigPath: input.ClusterctlConfigPath,
367+
ClusterctlVariables: input.UpgradeClusterctlVariables,
368+
ClusterProxy: managementClusterProxy,
369+
CoreProvider: input.CoreProvider,
370+
BootstrapProviders: input.BootstrapProviders,
371+
ControlPlaneProviders: input.ControlPlaneProviders,
372+
InfrastructureProviders: input.InfrastructureProviders,
373+
IPAMProviders: input.IPAMProviders,
374+
RuntimeExtensionProviders: input.RuntimeExtensionProviders,
375+
LogFolder: filepath.Join(input.ArtifactFolder, "clusters", cluster.Name),
376+
}, input.E2EConfig.GetIntervals(specName, "wait-controllers")...)
377+
} else {
378+
By("Upgrading providers to the latest version available")
379+
clusterctl.UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{
380+
ClusterctlConfigPath: input.ClusterctlConfigPath,
381+
ClusterctlVariables: input.UpgradeClusterctlVariables,
382+
ClusterProxy: managementClusterProxy,
383+
Contract: clusterv1.GroupVersion.Version,
384+
LogFolder: filepath.Join(input.ArtifactFolder, "clusters", cluster.Name),
385+
}, input.E2EConfig.GetIntervals(specName, "wait-controllers")...)
386+
}
357387

358388
By("THE MANAGEMENT CLUSTER WAS SUCCESSFULLY UPGRADED!")
359389

test/framework/clusterctl/client.go

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,18 @@ func InitWithBinary(_ context.Context, binary string, input InitInput) {
139139

140140
// UpgradeInput is the input for Upgrade.
141141
type UpgradeInput struct {
142-
LogFolder string
143-
ClusterctlConfigPath string
144-
ClusterctlVariables map[string]string
145-
ClusterName string
146-
KubeconfigPath string
147-
Contract string
142+
LogFolder string
143+
ClusterctlConfigPath string
144+
ClusterctlVariables map[string]string
145+
ClusterName string
146+
KubeconfigPath string
147+
Contract string
148+
CoreProvider string
149+
BootstrapProviders []string
150+
ControlPlaneProviders []string
151+
InfrastructureProviders []string
152+
IPAMProviders []string
153+
RuntimeExtensionProviders []string
148154
}
149155

150156
// Upgrade calls clusterctl upgrade apply with the list of providers defined in the local repository.
@@ -159,19 +165,49 @@ func Upgrade(ctx context.Context, input UpgradeInput) {
159165
input.ClusterctlConfigPath = outputPath
160166
}
161167

162-
log.Logf("clusterctl upgrade apply --contract %s --config %s --kubeconfig %s",
163-
input.Contract,
164-
input.ClusterctlConfigPath,
165-
input.KubeconfigPath,
166-
)
168+
// Check if the user want a custom upgrade
169+
isCustomUpgrade := input.CoreProvider != "" ||
170+
len(input.BootstrapProviders) > 0 ||
171+
len(input.ControlPlaneProviders) > 0 ||
172+
len(input.InfrastructureProviders) > 0 ||
173+
len(input.IPAMProviders) > 0 ||
174+
len(input.RuntimeExtensionProviders) > 0
175+
176+
Expect((input.Contract != "" && !isCustomUpgrade) || (input.Contract == "" && isCustomUpgrade)).To(BeTrue(), `Invalid arguments. Either the input.Contract parameter or at least one of the following providers has to be set:
177+
input.CoreProvider, input.BootstrapProviders, input.ControlPlaneProviders, input.InfrastructureProviders, input.IPAMProviders, input.RuntimeExtensionProviders`)
178+
179+
if isCustomUpgrade {
180+
log.Logf("clusterctl upgrade apply --core %s --bootstrap %s --control-plane %s --infrastructure %s --ipam %s --runtime-extension %s --config %s --kubeconfig %s",
181+
input.CoreProvider,
182+
strings.Join(input.BootstrapProviders, ","),
183+
strings.Join(input.ControlPlaneProviders, ","),
184+
strings.Join(input.InfrastructureProviders, ","),
185+
strings.Join(input.IPAMProviders, ","),
186+
strings.Join(input.RuntimeExtensionProviders, ","),
187+
input.ClusterctlConfigPath,
188+
input.KubeconfigPath,
189+
)
190+
} else {
191+
log.Logf("clusterctl upgrade apply --contract %s --config %s --kubeconfig %s",
192+
input.Contract,
193+
input.ClusterctlConfigPath,
194+
input.KubeconfigPath,
195+
)
196+
}
167197

168198
upgradeOpt := clusterctlclient.ApplyUpgradeOptions{
169199
Kubeconfig: clusterctlclient.Kubeconfig{
170200
Path: input.KubeconfigPath,
171201
Context: "",
172202
},
173-
Contract: input.Contract,
174-
WaitProviders: true,
203+
Contract: input.Contract,
204+
CoreProvider: input.CoreProvider,
205+
BootstrapProviders: input.BootstrapProviders,
206+
ControlPlaneProviders: input.ControlPlaneProviders,
207+
InfrastructureProviders: input.InfrastructureProviders,
208+
IPAMProviders: input.IPAMProviders,
209+
RuntimeExtensionProviders: input.RuntimeExtensionProviders,
210+
WaitProviders: true,
175211
}
176212

177213
clusterctlClient, log := getClusterctlClientWithLogger(input.ClusterctlConfigPath, "clusterctl-upgrade.log", input.LogFolder)

test/framework/clusterctl/clusterctl_helpers.go

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,50 @@ func InitManagementClusterAndWatchControllerLogs(ctx context.Context, input Init
127127

128128
// UpgradeManagementClusterAndWaitInput is the input type for UpgradeManagementClusterAndWait.
129129
type UpgradeManagementClusterAndWaitInput struct {
130-
ClusterProxy framework.ClusterProxy
131-
ClusterctlConfigPath string
132-
ClusterctlVariables map[string]string
133-
Contract string
134-
LogFolder string
130+
ClusterProxy framework.ClusterProxy
131+
ClusterctlConfigPath string
132+
ClusterctlVariables map[string]string
133+
Contract string
134+
CoreProvider string
135+
BootstrapProviders []string
136+
ControlPlaneProviders []string
137+
InfrastructureProviders []string
138+
IPAMProviders []string
139+
RuntimeExtensionProviders []string
140+
LogFolder string
135141
}
136142

137143
// UpgradeManagementClusterAndWait upgrades provider a management cluster using clusterctl, and waits for the cluster to be ready.
138144
func UpgradeManagementClusterAndWait(ctx context.Context, input UpgradeManagementClusterAndWaitInput, intervals ...interface{}) {
139145
Expect(ctx).NotTo(BeNil(), "ctx is required for UpgradeManagementClusterAndWait")
140146
Expect(input.ClusterProxy).ToNot(BeNil(), "Invalid argument. input.ClusterProxy can't be nil when calling UpgradeManagementClusterAndWait")
141147
Expect(input.ClusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling UpgradeManagementClusterAndWait")
142-
Expect(input.Contract).ToNot(BeEmpty(), "Invalid argument. input.Contract can't be empty when calling UpgradeManagementClusterAndWait")
148+
// Check if the user want a custom upgrade
149+
isCustomUpgrade := input.CoreProvider != "" ||
150+
len(input.BootstrapProviders) > 0 ||
151+
len(input.ControlPlaneProviders) > 0 ||
152+
len(input.InfrastructureProviders) > 0 ||
153+
len(input.IPAMProviders) > 0 ||
154+
len(input.RuntimeExtensionProviders) > 0
155+
156+
Expect((input.Contract != "" && !isCustomUpgrade) || (input.Contract == "" && isCustomUpgrade)).To(BeTrue(), `Invalid argument. Either the input.Contract parameter or at least one of the following providers has to be set:
157+
input.CoreProvider, input.BootstrapProviders, input.ControlPlaneProviders, input.InfrastructureProviders, input.IPAMProviders, input.RuntimeExtensionProviders`)
158+
143159
Expect(os.MkdirAll(input.LogFolder, 0750)).To(Succeed(), "Invalid argument. input.LogFolder can't be created for UpgradeManagementClusterAndWait")
144160

145161
Upgrade(ctx, UpgradeInput{
146-
ClusterctlConfigPath: input.ClusterctlConfigPath,
147-
ClusterctlVariables: input.ClusterctlVariables,
148-
ClusterName: input.ClusterProxy.GetName(),
149-
KubeconfigPath: input.ClusterProxy.GetKubeconfigPath(),
150-
Contract: input.Contract,
151-
LogFolder: input.LogFolder,
162+
ClusterctlConfigPath: input.ClusterctlConfigPath,
163+
ClusterctlVariables: input.ClusterctlVariables,
164+
ClusterName: input.ClusterProxy.GetName(),
165+
KubeconfigPath: input.ClusterProxy.GetKubeconfigPath(),
166+
Contract: input.Contract,
167+
CoreProvider: input.CoreProvider,
168+
BootstrapProviders: input.BootstrapProviders,
169+
ControlPlaneProviders: input.ControlPlaneProviders,
170+
InfrastructureProviders: input.InfrastructureProviders,
171+
IPAMProviders: input.IPAMProviders,
172+
RuntimeExtensionProviders: input.RuntimeExtensionProviders,
173+
LogFolder: input.LogFolder,
152174
})
153175

154176
client := input.ClusterProxy.GetClient()

0 commit comments

Comments
 (0)