Skip to content

Commit

Permalink
Add custom upgrade option to e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
mboukhalfa committed Oct 13, 2022
1 parent a2d988f commit 4afdbd1
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 24 deletions.
38 changes: 31 additions & 7 deletions test/e2e/clusterctl_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ type ClusterctlUpgradeSpecInput struct {
MgmtFlavor string
CNIManifestPath string
WorkloadFlavor string
// Custom providers can be specified to upgrade to a pre-release or a custom version instead of upgrading to the latest using contact
CoreProvider string
BootstrapProviders []string
ControlPlaneProviders []string
InfrastructureProviders []string
}

// ClusterctlUpgradeSpec implements a test that verifies clusterctl upgrade of a management cluster.
Expand Down Expand Up @@ -327,13 +332,32 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
)
Expect(err).NotTo(HaveOccurred())

By("Upgrading providers to the latest version available")
clusterctl.UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{
ClusterctlConfigPath: input.ClusterctlConfigPath,
ClusterProxy: managementClusterProxy,
Contract: clusterv1.GroupVersion.Version,
LogFolder: filepath.Join(input.ArtifactFolder, "clusters", cluster.Name),
}, input.E2EConfig.GetIntervals(specName, "wait-controllers")...)
// Check if the user want a custom upgrade
isCustomUpgrade := input.CoreProvider != "" ||
len(input.BootstrapProviders) > 0 ||
len(input.ControlPlaneProviders) > 0 ||
len(input.InfrastructureProviders) > 0

if isCustomUpgrade {
By("Upgrading providers to custom versions")
clusterctl.UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{
ClusterctlConfigPath: input.ClusterctlConfigPath,
ClusterProxy: managementClusterProxy,
CoreProvider: input.CoreProvider,
BootstrapProviders: input.BootstrapProviders,
ControlPlaneProviders: input.ControlPlaneProviders,
InfrastructureProviders: input.InfrastructureProviders,
LogFolder: filepath.Join(input.ArtifactFolder, "clusters", cluster.Name),
}, input.E2EConfig.GetIntervals(specName, "wait-controllers")...)
} else {
By("Upgrading providers to the latest version available")
clusterctl.UpgradeManagementClusterAndWait(ctx, clusterctl.UpgradeManagementClusterAndWaitInput{
ClusterctlConfigPath: input.ClusterctlConfigPath,
ClusterProxy: managementClusterProxy,
Contract: clusterv1.GroupVersion.Version,
LogFolder: filepath.Join(input.ArtifactFolder, "clusters", cluster.Name),
}, input.E2EConfig.GetIntervals(specName, "wait-controllers")...)
}

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

Expand Down
48 changes: 40 additions & 8 deletions test/framework/clusterctl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,56 @@ func InitWithBinary(_ context.Context, binary string, input InitInput) {

// UpgradeInput is the input for Upgrade.
type UpgradeInput struct {
LogFolder string
ClusterctlConfigPath string
KubeconfigPath string
Contract string
LogFolder string
ClusterctlConfigPath string
ClusterName string
KubeconfigPath string
Contract string
CoreProvider string
BootstrapProviders []string
ControlPlaneProviders []string
InfrastructureProviders []string
}

// Upgrade calls clusterctl upgrade apply with the list of providers defined in the local repository.
func Upgrade(ctx context.Context, input UpgradeInput) {
log.Logf("clusterctl upgrade apply --contract %s",
input.Contract,
)
// Check if the user want a custom upgrade
isCustomUpgrade := input.CoreProvider != "" ||
len(input.BootstrapProviders) > 0 ||
len(input.ControlPlaneProviders) > 0 ||
len(input.InfrastructureProviders) > 0

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:
input.CoreProvider, input.BootstrapProviders, input.ControlPlaneProviders, input.InfrastructureProviders, input.IPAMProviders, input.RuntimeExtensionProviders`)

if isCustomUpgrade {
log.Logf("clusterctl upgrade apply --core %s --bootstrap %s --control-plane %s --infrastructure %s --config %s --kubeconfig %s",
input.CoreProvider,
strings.Join(input.BootstrapProviders, ","),
strings.Join(input.ControlPlaneProviders, ","),
strings.Join(input.InfrastructureProviders, ","),
input.ClusterctlConfigPath,
input.KubeconfigPath,
)
} else {
log.Logf("clusterctl upgrade apply --contract %s --config %s --kubeconfig %s",
input.Contract,
input.ClusterctlConfigPath,
input.KubeconfigPath,
)
}

upgradeOpt := clusterctlclient.ApplyUpgradeOptions{
Kubeconfig: clusterctlclient.Kubeconfig{
Path: input.KubeconfigPath,
Context: "",
},
Contract: input.Contract,
Contract: input.Contract,
CoreProvider: input.CoreProvider,
BootstrapProviders: input.BootstrapProviders,
ControlPlaneProviders: input.ControlPlaneProviders,
InfrastructureProviders: input.InfrastructureProviders,
WaitProviders: true,
}

clusterctlClient, log := getClusterctlClientWithLogger(input.ClusterctlConfigPath, "clusterctl-upgrade.log", input.LogFolder)
Expand Down
35 changes: 26 additions & 9 deletions test/framework/clusterctl/clusterctl_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,42 @@ func InitManagementClusterAndWatchControllerLogs(ctx context.Context, input Init

// UpgradeManagementClusterAndWaitInput is the input type for UpgradeManagementClusterAndWait.
type UpgradeManagementClusterAndWaitInput struct {
ClusterProxy framework.ClusterProxy
ClusterctlConfigPath string
Contract string
LogFolder string
ClusterProxy framework.ClusterProxy
ClusterctlConfigPath string
Contract string
CoreProvider string
BootstrapProviders []string
ControlPlaneProviders []string
InfrastructureProviders []string
LogFolder string
}

// UpgradeManagementClusterAndWait upgrades provider a management cluster using clusterctl, and waits for the cluster to be ready.
func UpgradeManagementClusterAndWait(ctx context.Context, input UpgradeManagementClusterAndWaitInput, intervals ...interface{}) {
Expect(ctx).NotTo(BeNil(), "ctx is required for UpgradeManagementClusterAndWait")
Expect(input.ClusterProxy).ToNot(BeNil(), "Invalid argument. input.ClusterProxy can't be nil when calling UpgradeManagementClusterAndWait")
Expect(input.ClusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling UpgradeManagementClusterAndWait")
Expect(input.Contract).ToNot(BeEmpty(), "Invalid argument. input.Contract can't be empty when calling UpgradeManagementClusterAndWait")
// Check if the user want a custom upgrade
isCustomUpgrade := input.CoreProvider != "" ||
len(input.BootstrapProviders) > 0 ||
len(input.ControlPlaneProviders) > 0 ||
len(input.InfrastructureProviders) > 0

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:
input.CoreProvider, input.BootstrapProviders, input.ControlPlaneProviders, input.InfrastructureProviders, input.IPAMProviders, input.RuntimeExtensionProviders`)

Expect(os.MkdirAll(input.LogFolder, 0750)).To(Succeed(), "Invalid argument. input.LogFolder can't be created for UpgradeManagementClusterAndWait")

Upgrade(ctx, UpgradeInput{
ClusterctlConfigPath: input.ClusterctlConfigPath,
KubeconfigPath: input.ClusterProxy.GetKubeconfigPath(),
Contract: input.Contract,
LogFolder: input.LogFolder,
ClusterctlConfigPath: input.ClusterctlConfigPath,
ClusterName: input.ClusterProxy.GetName(),
KubeconfigPath: input.ClusterProxy.GetKubeconfigPath(),
Contract: input.Contract,
CoreProvider: input.CoreProvider,
BootstrapProviders: input.BootstrapProviders,
ControlPlaneProviders: input.ControlPlaneProviders,
InfrastructureProviders: input.InfrastructureProviders,
LogFolder: input.LogFolder,
})

client := input.ClusterProxy.GetClient()
Expand Down

0 comments on commit 4afdbd1

Please sign in to comment.