From f1f186c4cc2d943f2474b25f724fa091bd8e7160 Mon Sep 17 00:00:00 2001 From: Caleb Warren Date: Tue, 13 Feb 2024 15:40:33 -0800 Subject: [PATCH] make out-of-tree helpers public for additional testing during upgrades --- extensions/charts/awsoutoftree.go | 9 ++++++--- extensions/charts/verify.go | 5 +++++ extensions/clusters/clusters.go | 24 ++++++++++++++++++++---- extensions/kubectl/template.go | 2 +- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/extensions/charts/awsoutoftree.go b/extensions/charts/awsoutoftree.go index abd35a2b..4d606c10 100644 --- a/extensions/charts/awsoutoftree.go +++ b/extensions/charts/awsoutoftree.go @@ -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 @@ -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 { @@ -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", @@ -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, diff --git a/extensions/charts/verify.go b/extensions/charts/verify.go index d5129d68..7c51745a 100644 --- a/extensions/charts/verify.go +++ b/extensions/charts/verify.go @@ -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" @@ -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 diff --git a/extensions/clusters/clusters.go b/extensions/clusters/clusters.go index 860aa175..1be0f047 100644 --- a/extensions/clusters/clusters.go +++ b/extensions/clusters/clusters.go @@ -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{ @@ -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 { @@ -488,7 +490,7 @@ func awsOutOfTreeSystemConfig() (rkeConfig []rkev1.RKESystemConfig) { } configData := map[string]interface{}{ - cloudProviderAnnotationName: provisioninginput.AWSProviderName, + cloudProviderAnnotationName: providerName, protectKernelDefaults: false, } @@ -496,6 +498,20 @@ func awsOutOfTreeSystemConfig() (rkeConfig []rkev1.RKESystemConfig) { 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{ diff --git a/extensions/kubectl/template.go b/extensions/kubectl/template.go index e28b00c4..a0f35f43 100644 --- a/extensions/kubectl/template.go +++ b/extensions/kubectl/template.go @@ -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.