From b8b3779b991031725d991cd0acf385345c3493cd Mon Sep 17 00:00:00 2001 From: Mo Mesgin Date: Tue, 13 Aug 2024 15:20:05 -0700 Subject: [PATCH 1/2] backport azure changes for rke1 --- .../cru-cloud-provider/component.js | 58 +++++++++++++++++-- .../cru-cloud-provider/template.hbs | 17 +++++- translations/en-us.yaml | 1 + 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/lib/shared/addon/components/cru-cloud-provider/component.js b/lib/shared/addon/components/cru-cloud-provider/component.js index 3b7374af72..61441c397a 100644 --- a/lib/shared/addon/components/cru-cloud-provider/component.js +++ b/lib/shared/addon/components/cru-cloud-provider/component.js @@ -16,6 +16,8 @@ const azureDefaults = C.AZURE_DEFAULTS; const GENERIC_PATH = 'cluster.rancherKubernetesEngineConfig.cloudProvider.cloudConfig'; const AWS_PATH = 'cluster.rancherKubernetesEngineConfig.cloudProvider.awsCloudProvider'; const AZURE_PATH = 'cluster.rancherKubernetesEngineConfig.cloudProvider.azureCloudProvider'; +const AZURE_IN_TREE_MINIMUM_VERSION = 'v1.27.0'; +const AZURE_IN_TREE_DEPRICATE_VERSION = 'v1.30.0'; export default Component.extend({ globalStore: service(), @@ -39,6 +41,7 @@ export default Component.extend({ // track the original configuration to revert the switch to 'external' when the selected provider is not supported initialCloudProvider: null, initialConfigAnswers: null, + showChangedToExternal: false, configName: alias('cluster.rancherKubernetesEngineConfig.cloudProvider.name'), @@ -60,11 +63,14 @@ export default Component.extend({ this.setCpFields(`azureCloudProvider`, reorderedAnswers); + const shouldAllowEditingCloudProvider = this.mode === 'edit' && this.isAzureInTreeSupported; + setProperties(this, { - selectedCloudProvider: 'azure', - configAnswers: reorderedAnswers, - initialCloudProvider: 'azure', - initialConfigAnswers: reorderedAnswers + selectedCloudProvider: 'azure', + configAnswers: reorderedAnswers, + initialCloudProvider: 'azure', + initialConfigAnswers: reorderedAnswers, + unsupportedProviderSelected: shouldAllowEditingCloudProvider }); } else if ( !cloudProviderName ) { set(this, 'selectedCloudProvider', 'none'); @@ -84,6 +90,7 @@ export default Component.extend({ modeChanged: observer('selectedCloudProvider', function() { let selectedCloudProvider = get(this, 'selectedCloudProvider'); + const showChangedToExternal = get(this, 'showChangedToExternal'); if ( selectedCloudProvider !== 'none' ) { this.constructConfig(); @@ -94,6 +101,11 @@ export default Component.extend({ delete config.cloudProvider; } } + + // remove azure warning banner when selection changes + if (selectedCloudProvider !== 'external' && showChangedToExternal) { + set(this, 'showChangedToExternal', false); + } }), harvesterCloudProviderDisabledChange: observer('harvesterCloudProviderDisabled', function() { @@ -104,13 +116,34 @@ export default Component.extend({ k8sVersionDidChange: observer( 'cluster.rancherKubernetesEngineConfig.kubernetesVersion', function(){ const kubernetesVersion = get(this, 'cluster.rancherKubernetesEngineConfig.kubernetesVersion') - const initialCloudProvider = get(this, 'initialCloudProvider') + const initialCloudProvider = get(this, 'initialCloudProvider'); + const selectedCloudProvider = get(this, 'selectedCloudProvider'); + const isAzureCurrentlySelected = selectedCloudProvider === 'azure'; + const isAzureInTreeSupported = get(this, 'isAzureInTreeSupported'); + const showChangedToExternal = get(this, 'showChangedToExternal'); if (initialCloudProvider === 'amazonec2' && Semver.gte(Semver.coerce(kubernetesVersion), '1.27.0')){ set(this, 'unsupportedProviderSelected', true); set(this, 'selectedCloudProvider', 'external-aws'); set(this, 'showChangedToAmazonExternal', true); - this.constructConfig() + this.constructConfig(); + } else if (initialCloudProvider === 'azure') { // Edit mode for Azure + if (!isAzureInTreeSupported && isAzureCurrentlySelected) { + set(this, 'unsupportedProviderSelected', true); + set(this, 'selectedCloudProvider', 'external'); + set(this, 'showChangedToExternal', true); + this.constructConfig(); + } else if (showChangedToExternal) { + set(this, 'showChangedToExternal', false); + } + } else if (isAzureCurrentlySelected) { // Create mode for Azure + if (!isAzureInTreeSupported){ + set(this, 'selectedCloudProvider', 'external'); + set(this, 'showChangedToExternal', true); + this.constructConfig() + } else if (showChangedToExternal) { + set(this, 'showChangedToExternal', false); + } } else if (get(this, 'unsupportedProviderSelected')){ setProperties(this, { unsupportedProviderSelected: false, @@ -118,6 +151,8 @@ export default Component.extend({ selectedCloudProvider: get(this, 'initialCloudProvider'), configAnswers: get(this, 'initialConfigAnswers') }) + } else if (showChangedToExternal) { // Remove azure warning + set(this, 'showChangedToExternal', false); } }), @@ -148,6 +183,11 @@ export default Component.extend({ set(configAnswersOut, answer.key, answer.value); }); + // Avoid setting cloud provider-specific configs in edit mode if the path doesn't exist (caused issues with Azure) + if (!this.pathForSet && this.mode === 'edit') { + return; + } + set(this, pathForSet, configAnswersOut); }), @@ -193,6 +233,12 @@ export default Component.extend({ } }), + isAzureInTreeSupported: computed('cluster.rancherKubernetesEngineConfig.kubernetesVersion', function() { + const kubernetesVersion = get(this, 'cluster.rancherKubernetesEngineConfig.kubernetesVersion'); + + return Semver.satisfies(Semver.coerce(kubernetesVersion), `>=${ AZURE_IN_TREE_MINIMUM_VERSION } <${ AZURE_IN_TREE_DEPRICATE_VERSION }`); + }), + mappedConfigAnswers: computed('configAnswers', function() { const configAnswers = (get(this, 'configAnswers') || {}); const out = []; diff --git a/lib/shared/addon/components/cru-cloud-provider/template.hbs b/lib/shared/addon/components/cru-cloud-provider/template.hbs index 9893317a58..4190759ef8 100644 --- a/lib/shared/addon/components/cru-cloud-provider/template.hbs +++ b/lib/shared/addon/components/cru-cloud-provider/template.hbs @@ -39,6 +39,16 @@ @isCreateClusterOrClusterTemplate={{isCreateClusterOrClusterTemplate}} @computedState={{not (eq selectedCloudProvider "none")}} > + {{#if showChangedToExternal}} +
+ +
+ {{/if}} + {{#input-or-display editable=(or (and (eq mode "new") (or (not applyClusterTemplate) (and (eq mode "new") selectedCloudProviderOverrideAvailable))) canEditProvider) value=selectedCloudProvider @@ -89,7 +99,7 @@ {{t "cloudProvider.azure"}} - {{else if isCreateClusterOrClusterTemplate}} + {{else if (and isCreateClusterOrClusterTemplate isAzureInTreeSupported)}}
+ {{#if (get azureDescriptions answer.key)}} +

+ {{t (get (get azureDescriptions answer.key) "description") htmlSafe=true}} +

+ {{/if}}

{{t (get (get azureDescriptions answer.key) "description") htmlSafe=true}}

diff --git a/translations/en-us.yaml b/translations/en-us.yaml index 40f4a9c208..6c29cd136a 100644 --- a/translations/en-us.yaml +++ b/translations/en-us.yaml @@ -3145,6 +3145,7 @@ cloudProvider: label: External Amazon (Out-Of-Tree) helpText: External Amazon enables use of useInstanceMetadataHostname. When useInstanceMetadataHostname is enabled, RKE will configure node name from ec2 metadata service. Configuring a Cloud Provider in your cluster without configuring the prerequisites will cause your cluster to not provision correctly. Prerequisites needed for supported cloud providers can be found in the documentation. azure: Azure (In-Tree) + azureUnsupported: 'Azure (In-Tree) is not supported by this version of Kubernetes. The Cloud Provider has been changed to External. Please use the Cloud Provider Config to supply an out-of-tree configuration as needed.' external: label: External (Out-Of-Tree) helpText: 'Please edit the YAML to specify the required addon for cloud controller manager.' From 296a949af28da2dd019e8549e7a2d9e98ad61a3c Mon Sep 17 00:00:00 2001 From: Mo Mesgin Date: Tue, 13 Aug 2024 15:30:31 -0700 Subject: [PATCH 2/2] fix lint error --- lib/shared/addon/components/cru-cloud-provider/component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shared/addon/components/cru-cloud-provider/component.js b/lib/shared/addon/components/cru-cloud-provider/component.js index 61441c397a..129cf6f5ea 100644 --- a/lib/shared/addon/components/cru-cloud-provider/component.js +++ b/lib/shared/addon/components/cru-cloud-provider/component.js @@ -41,7 +41,7 @@ export default Component.extend({ // track the original configuration to revert the switch to 'external' when the selected provider is not supported initialCloudProvider: null, initialConfigAnswers: null, - showChangedToExternal: false, + showChangedToExternal: false, configName: alias('cluster.rancherKubernetesEngineConfig.cloudProvider.name'),