Skip to content

Commit

Permalink
Merge pull request #144 from slickwarren/cwarren/v2.7/out-of-tree-mig…
Browse files Browse the repository at this point in the history
…ration

[2.7]  make out-of-tree helpers public for additional testing during upgrades
  • Loading branch information
Israel Gomez authored Apr 5, 2024
2 parents aefa636 + 40fd3f6 commit 5ced0bf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
9 changes: 6 additions & 3 deletions extensions/charts/awsoutoftree.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
)

// InstallAWSOutOfTreeChart installs the CSI chart for aws cloud provider in a given cluster.
func InstallAWSOutOfTreeChart(client *rancher.Client, installOptions *InstallOptions, repoName, clusterID string) error {
func InstallAWSOutOfTreeChart(client *rancher.Client, installOptions *InstallOptions, repoName, clusterID string, isLeaderMigration bool) error {
serverSetting, err := client.Management.Setting.ByID(serverURLSettingID)
if err != nil {
return err
Expand All @@ -42,7 +42,7 @@ func InstallAWSOutOfTreeChart(client *rancher.Client, installOptions *InstallOpt
DefaultRegistry: registrySetting.Value,
}

chartInstallAction := awsChartInstallAction(awsChartInstallActionPayload, repoName, kubeSystemNamespace, installOptions.ProjectID)
chartInstallAction := awsChartInstallAction(awsChartInstallActionPayload, repoName, kubeSystemNamespace, installOptions.ProjectID, isLeaderMigration)

catalogClient, err := client.GetClusterCatalogClient(installOptions.ClusterID)
if err != nil {
Expand Down Expand Up @@ -73,7 +73,7 @@ func InstallAWSOutOfTreeChart(client *rancher.Client, installOptions *InstallOpt
}

// awsChartInstallAction is a helper function that returns a chartInstallAction for aws out-of-tree chart.
func awsChartInstallAction(awsChartInstallActionPayload *payloadOpts, repoName, chartNamespace, chartProject string) *types.ChartInstallAction {
func awsChartInstallAction(awsChartInstallActionPayload *payloadOpts, repoName, chartNamespace, chartProject string, isLeaderMigration bool) *types.ChartInstallAction {
chartValues := map[string]interface{}{
"args": []interface{}{
"--use-service-account-credentials=true",
Expand Down Expand Up @@ -217,6 +217,9 @@ func awsChartInstallAction(awsChartInstallActionPayload *payloadOpts, repoName,
},
},
}
if isLeaderMigration {
chartValues["args"] = append(chartValues["args"].([]interface{}), "--enable-leader-migration=true")
}

chartInstall := newChartInstall(
awsChartInstallActionPayload.Name,
Expand Down
5 changes: 5 additions & 0 deletions extensions/charts/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package charts

import (
"context"
"errors"

v1 "github.com/rancher/rancher/pkg/apis/catalog.cattle.io/v1"
"github.com/rancher/shepherd/clients/rancher/catalog"
Expand All @@ -28,6 +29,10 @@ func VerifyChartInstall(client *catalog.Client, chartNamespace, chartName string
if state == string(v1.StatusDeployed) {
return true, nil
}

if state == string(v1.StatusFailed) {
return false, errors.New("chart install has failed")
}
return false, nil
})
return err
Expand Down
24 changes: 20 additions & 4 deletions extensions/clusters/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@ func NewK3SRKE2ClusterConfig(clusterName, namespace string, clustersConfig *Clus
}

if clustersConfig.CloudProvider == provisioninginput.AWSProviderName.String() {
machineSelectorConfigs = append(machineSelectorConfigs, awsOutOfTreeSystemConfig()...)
machineSelectorConfigs = append(machineSelectorConfigs, OutOfTreeSystemConfig(clustersConfig.CloudProvider)...)
} else if strings.Contains(clustersConfig.CloudProvider, "-in-tree") {
machineSelectorConfigs = append(machineSelectorConfigs, InTreeSystemConfig(strings.Split(clustersConfig.CloudProvider, "-in-tree")[0])...)
}

rkeSpecCommon := rkev1.RKEClusterSpecCommon{
Expand Down Expand Up @@ -460,9 +462,9 @@ func NewK3SRKE2ClusterConfig(clusterName, namespace string, clustersConfig *Clus
return v1Cluster
}

// awsOutOfTreeSystemConfig constructs the proper rkeSystemConfig slice for enabling the aws cloud provider
// OutOfTreeSystemConfig constructs the proper rkeSystemConfig slice for enabling the aws cloud provider
// out-of-tree services
func awsOutOfTreeSystemConfig() (rkeConfig []rkev1.RKESystemConfig) {
func OutOfTreeSystemConfig(providerName string) (rkeConfig []rkev1.RKESystemConfig) {
roles := []string{etcdRole, controlPlaneRole, workerRole}

for _, role := range roles {
Expand All @@ -488,14 +490,28 @@ func awsOutOfTreeSystemConfig() (rkeConfig []rkev1.RKESystemConfig) {
}

configData := map[string]interface{}{
cloudProviderAnnotationName: provisioninginput.AWSProviderName,
cloudProviderAnnotationName: providerName,
protectKernelDefaults: false,
}

rkeConfig = append(rkeConfig, RKESystemConfigTemplate(configData, nil))
return
}

// InTreeSystemConfig constructs the proper rkeSystemConfig slice for enabling cloud provider
// in-tree services.
// Vsphere deprecated 1.21+
// AWS deprecated 1.27+
// Azure deprecated 1.28+
func InTreeSystemConfig(providerName string) (rkeConfig []rkev1.RKESystemConfig) {
configData := map[string]interface{}{
cloudProviderAnnotationName: providerName,
protectKernelDefaults: false,
}
rkeConfig = append(rkeConfig, RKESystemConfigTemplate(configData, nil))
return
}

// RKESYstemConfigTemplate constructs an RKESystemConfig object given config data and a selector
func RKESystemConfigTemplate(config map[string]interface{}, selector *metav1.LabelSelector) rkev1.RKESystemConfig {
return rkev1.RKESystemConfig{
Expand Down
2 changes: 1 addition & 1 deletion extensions/kubectl/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
JobName = "kubectl"
)

var importTimeout = int64(60 * 1)
var importTimeout = int64(60 * 2)

// CreateJobAndRunKubectlCommands is a helper to create a job and run the kubectl commands in the pods of the Job.
// It then returns errors or nil from the job.
Expand Down

0 comments on commit 5ced0bf

Please sign in to comment.