Skip to content

Commit

Permalink
Add custom upgrade option
Browse files Browse the repository at this point in the history
  • Loading branch information
mboukhalfa committed Oct 4, 2022
1 parent 640d431 commit 1b69f90
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
24 changes: 16 additions & 8 deletions test/framework/clusterctl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,16 @@ func InitWithBinary(_ context.Context, binary string, input InitInput) {

// UpgradeInput is the input for Upgrade.
type UpgradeInput struct {
LogFolder string
ClusterctlConfigPath string
ClusterctlVariables map[string]string
ClusterName string
KubeconfigPath string
Contract string
LogFolder string
ClusterctlConfigPath string
ClusterctlVariables map[string]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.
Expand All @@ -152,8 +156,12 @@ func Upgrade(ctx context.Context, input UpgradeInput) {
Path: input.KubeconfigPath,
Context: "",
},
Contract: input.Contract,
WaitProviders: true,
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
39 changes: 27 additions & 12 deletions test/framework/clusterctl/clusterctl_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,43 @@ func InitManagementClusterAndWatchControllerLogs(ctx context.Context, input Init

// UpgradeManagementClusterAndWaitInput is the input type for UpgradeManagementClusterAndWait.
type UpgradeManagementClusterAndWaitInput struct {
ClusterProxy framework.ClusterProxy
ClusterctlConfigPath string
ClusterctlVariables map[string]string
Contract string
LogFolder string
ClusterProxy framework.ClusterProxy
ClusterctlConfigPath string
ClusterctlVariables map[string]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
if !isCustomUpgrade {
Expect(input.Contract).ToNot(BeEmpty(), "Invalid argument. input.Contract can't be empty when calling UpgradeManagementClusterAndWait without custom providers")
}
Expect(os.MkdirAll(input.LogFolder, 0750)).To(Succeed(), "Invalid argument. input.LogFolder can't be created for UpgradeManagementClusterAndWait")

Upgrade(ctx, UpgradeInput{
ClusterctlConfigPath: input.ClusterctlConfigPath,
ClusterctlVariables: input.ClusterctlVariables,
ClusterName: input.ClusterProxy.GetName(),
KubeconfigPath: input.ClusterProxy.GetKubeconfigPath(),
Contract: input.Contract,
LogFolder: input.LogFolder,
ClusterctlConfigPath: input.ClusterctlConfigPath,
ClusterctlVariables: input.ClusterctlVariables,
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 1b69f90

Please sign in to comment.