Skip to content

Commit

Permalink
Ensure Azure RKE2 default region is available with selected cloud cre…
Browse files Browse the repository at this point in the history
…dential (rancher#10471)

* Fix(aks) Ensure AKS RKE2 default loaded region aligns with Credentials

* fix azure machine pool default on edit

* remove always-disabled azure environment input

* force re-run ci

---------

Co-authored-by: Siye Wang <[email protected]>
  • Loading branch information
mantis-toboggan-md and smallteeths authored Mar 8, 2024
1 parent 20462e2 commit ad75211
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
1 change: 1 addition & 0 deletions shell/assets/translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,7 @@ cluster:
label: DNS Label
environment:
label: Environment
tooltip: The environment is configured when cloud credentials are created.
faultDomainCount:
help: If the availability set has already been created, the fault domain count will be ignored.
label: Fault Domain Count
Expand Down
58 changes: 37 additions & 21 deletions shell/machine-config/azure.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { Checkbox } from '@components/Form/Checkbox';
import ArrayList from '@shell/components/form/ArrayList';
import { randomStr } from '@shell/utils/string';
import { addParam, addParams } from '@shell/utils/url';
import { NORMAN } from '@shell/config/types';
import { findBy } from '@shell/utils/array';
import KeyValue from '@shell/components/form/KeyValue';
import { RadioGroup } from '@components/Form/Radio';
import { _CREATE, _EDIT } from '@shell/config/query-params';
Expand Down Expand Up @@ -92,7 +94,6 @@ const storageTypes = [
value: 'StandardSSD_LRS'
}
];
const DEFAULT_REGION = 'westus';
export default {
components: {
Expand Down Expand Up @@ -148,6 +149,12 @@ export default {
}
if (!isEmpty(environment)) {
this.value.environment = environment;
} else if (this.loadedCredentialIdFor !== this.credentialId) {
this.allCredentials = await this.$store.dispatch('rancher/findAll', { type: NORMAN.CLOUD_CREDENTIAL });
const currentCredential = this.allCredentials.find((obj) => obj.id === this.credentialId);
this.value.environment = currentCredential.azurecredentialConfig.environment;
}
if (!isEmpty(subscriptionId)) {
this.value.subscriptionId = subscriptionId;
Expand All @@ -156,26 +163,31 @@ export default {
this.value.tenantId = tenantId;
}
this.locationOptions = await this.$store.dispatch('management/request', {
url: addParam('/meta/aksLocations', 'cloudCredentialId', this.credentialId),
method: 'GET',
});
if (this.loadedCredentialIdFor !== this.credentialId) {
this.locationOptions = await this.$store.dispatch('management/request', {
url: addParam('/meta/aksLocations', 'cloudCredentialId', this.credentialId),
method: 'GET',
});
if (this.mode === _CREATE) {
this.value.location = DEFAULT_REGION;
this.loadedCredentialIdFor = this.credentialId;
}
// when you edit an Azure cluster and add a new machine pool (edit)
// the location field doesn't come populated which causes the vmSizes request
// to return 200 but with a null response (also a bunch of other fields are undefined...)
// so let's prefill them with the defaults
} else if (this.mode === _EDIT && !this.value?.location) {
if (this.mode === _EDIT && !this.value?.location) {
for (const key in this.defaultConfig) {
if (this.value[key] === undefined) {
this.$set(this.value, key, this.defaultConfig[key]);
}
}
}
if (!this.value.location || !findBy(this.locationOptions, 'name', this.value.location)) {
this.locationOptions?.length && this.setLocation(this.locationOptions[this.locationOptions.length - 1]);
}
this.vmSizes = await this.$store.dispatch('management/request', {
url: addParams('/meta/aksVMSizesV2', {
cloudCredentialId: this.credentialId,
Expand Down Expand Up @@ -206,6 +218,8 @@ export default {
useAvailabilitySet: false,
vmSizes: [],
valueCopy: this.value,
loadedCredentialIdFor: null
};
},
Expand All @@ -214,6 +228,10 @@ export default {
this.$fetch();
},
'value.location'() {
this.$fetch();
},
'value.availabilityZone'(neu) {
if (neu && (!this.value.managedDisks || !this.value.enablePublicIpStandardSku || !this.value.staticPublicIp)) {
this.$emit('expandAdvanced');
Expand Down Expand Up @@ -499,19 +517,6 @@ export default {
</div>
<div v-else>
<div class="row mt-20">
<div class="col span-6">
<LabeledSelect
v-model="value.environment"
:mode="mode"
:options="azureEnvironments"
option-key="value"
option-label="value"
:searchable="false"
:required="true"
:label="t('cluster.machineConfig.azure.environment.label')"
:disabled="disabled"
/>
</div>
<div class="col span-6">
<LabeledSelect
:value="value.location"
Expand All @@ -526,6 +531,17 @@ export default {
@input="setLocation"
/>
</div>
<div>
<label
v-clean-tooltip="t('cluster.machineConfig.azure.environment.tooltip')"
:style="{'display':'block'}"
class="text-label"
>
{{ t('cluster.machineConfig.azure.environment.label') }}
<i class="icon icon-sm icon-info" />
</label>
<span>{{ value.environment }}</span>
</div>
</div>
<div class="row mt-20">
<div class="col span-4">
Expand Down

0 comments on commit ad75211

Please sign in to comment.