Skip to content

Commit

Permalink
Merge pull request #5162 from momesgin/backport-azure-rke1-changes
Browse files Browse the repository at this point in the history
Backport Azure changes for RKE1
  • Loading branch information
gaktive authored Aug 14, 2024
2 parents cbc07c4 + 296a949 commit 76b6fd3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
58 changes: 52 additions & 6 deletions lib/shared/addon/components/cru-cloud-provider/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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'),

Expand All @@ -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');
Expand All @@ -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();
Expand All @@ -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() {
Expand All @@ -104,20 +116,43 @@ 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,
showChangedToAmazonExternal: false,
selectedCloudProvider: get(this, 'initialCloudProvider'),
configAnswers: get(this, 'initialConfigAnswers')
})
} else if (showChangedToExternal) { // Remove azure warning
set(this, 'showChangedToExternal', false);
}
}),

Expand Down Expand Up @@ -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);
}),

Expand Down Expand Up @@ -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 = [];
Expand Down
17 changes: 16 additions & 1 deletion lib/shared/addon/components/cru-cloud-provider/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
@isCreateClusterOrClusterTemplate={{isCreateClusterOrClusterTemplate}}
@computedState={{not (eq selectedCloudProvider "none")}}
>
{{#if showChangedToExternal}}
<div class="col span-12">
<BannerMessage
@color="bg-warning mt-0 mb-0"
@icon="icon-alert"
@message={{t "cloudProvider.azureUnsupported" htmlSafe=true}}
/>
</div>
{{/if}}

{{#input-or-display
editable=(or (and (eq mode "new") (or (not applyClusterTemplate) (and (eq mode "new") selectedCloudProviderOverrideAvailable))) canEditProvider)
value=selectedCloudProvider
Expand Down Expand Up @@ -89,7 +99,7 @@
{{t "cloudProvider.azure"}}
</label>
</div>
{{else if isCreateClusterOrClusterTemplate}}
{{else if (and isCreateClusterOrClusterTemplate isAzureInTreeSupported)}}
<div class="radio">
<label>
{{radio-button
Expand Down Expand Up @@ -248,6 +258,11 @@
/>
{{/if}}
</label>
{{#if (get azureDescriptions answer.key)}}
<p class="help-block mt-0">
{{t (get (get azureDescriptions answer.key) "description") htmlSafe=true}}
</p>
{{/if}}
<p class="help-block mt-0">
{{t (get (get azureDescriptions answer.key) "description") htmlSafe=true}}
</p>
Expand Down
1 change: 1 addition & 0 deletions translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://ranchermanager.docs.rancher.com/v2.9/how-to-guides/new-user-guides/kubernetes-clusters-in-rancher-setup/set-up-cloud-providers/azure#cloud-provider-configuration" target="_blank" rel="nofollow noopener noreferrer">Cloud Provider Config</a> 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.'
Expand Down

0 comments on commit 76b6fd3

Please sign in to comment.