Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix azure multi-environment support #4869

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Component from '@ember/component';
import layout from './template';
import { inject as service } from '@ember/service';
import { environments } from 'ui/utils/azure-choices';

export default Component.extend({
router: service(),

layout,
environments,

tag: null,
config: null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
<div class="row">
<div class="col span-6">
<label class="acc-label">
{{t "nodeDriver.azure.environment.label"}}
</label>
{{new-select
classNames="form-control"
content=environments
optionLabelPath="value"
value=config.environment
}}
</div>
<div class="col span-6">
<label class="acc-label" for="azure-subscription-id">
{{t "modalAddCloudKey.azure.subscriptionId.label"}}
<FieldRequired />
</label>
<Input
@classNames="form-control"
@id="azure-subscription-id"
@type="text"
@value={{mut config.subscriptionId}}
/>
</div>
</div>
<div class="row">
<div class="col span-6">
<label class="acc-label" for="azure-client-id">
Expand All @@ -24,17 +49,3 @@
/>
</div>
</div>
<div class="row">
<div class="col span-6">
<label class="acc-label" for="azure-subscription-id">
{{t "modalAddCloudKey.azure.subscriptionId.label"}}
<FieldRequired />
</label>
<Input
@classNames="form-control"
@id="azure-subscription-id"
@type="text"
@value={{mut config.subscriptionId}}
/>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export default Component.extend(ViewNewEdit, {
}

const { cloudCredentialType } = this;
const keysThatWeCanValidate = ['amazon', 'digitalOcean', 'linode', 'oci', 'google'];
const keysThatWeCanValidate = ['amazon', 'digitalOcean', 'linode', 'oci', 'google', 'azure'];
const auth = {
type: 'validate',
token: null,
Expand Down Expand Up @@ -372,6 +372,26 @@ export default Component.extend(ViewNewEdit, {
return this.setError(`${ err.message }`);
});
}

if (cloudCredentialType === 'azure') {
return get(this, 'globalStore').rawRequest({
url: '/meta/aksCheckCredentials',
method: 'POST',
data: {
environment: get(this, 'config.environment'),
clientId: get(this, 'config.clientId'),
clientSecret: get(this, 'config.clientSecret'),
subscriptionId: get(this, 'config.subscriptionId'),
},
redirectUnauthorized: false,
}).then(() => {
set(this, 'validatingKeys', false);

return true;
}).catch((err) => {
return this.setError(`${ err.message }`);
});
}
}

set(this, 'validatingKeys', false);
Expand Down
26 changes: 23 additions & 3 deletions lib/nodes/addon/components/driver-azure/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export default Component.extend(NodeDriver, {
this._super(...arguments);

scheduleOnce('afterRender', this, this.setupComponent);

this.initEnvironment();
},

actions: {
Expand All @@ -75,10 +77,24 @@ export default Component.extend(NodeDriver, {
set(this, 'config.managedDisks', get(this, 'managedDisks') === MANAGED);
}),

evironmentChoiceObserver: observer('config.environment', function() {
let environment = get(this, 'config.environment');
cloudCredentialChoiceObserver: observer('model.cloudCredentialId', function() {
const cloudCredentialId = get(this, 'model.cloudCredentialId');

if (!cloudCredentialId){
return;
}

get(this, 'store').find('cloudCredential', cloudCredentialId, { forceReload: true }).then((credential) => {
const environment = get(credential, 'azurecredentialConfig.environment');

environment && set(this, 'config.environment', environment);

set(this, 'config.location', regions[environment][0].name);
const location = get(this, 'config.location');

if (!location || !regions[environment].findBy('name', location)){
set(this, 'config.location', regions[environment][0].name);
}
});
}),

ipChoiceObserver: observer('publicIpChoice', function() {
Expand Down Expand Up @@ -197,4 +213,8 @@ export default Component.extend(NodeDriver, {
}
},

initEnvironment(){
this.cloudCredentialChoiceObserver();
},

});
1 change: 1 addition & 0 deletions lib/nodes/addon/components/driver-azure/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
content=environments
optionLabelPath="value"
value=config.environment
disabled=true
}}
</div>
<div class="col span-6">
Expand Down
21 changes: 16 additions & 5 deletions lib/shared/addon/components/cluster-driver/driver-aks/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ export default Component.extend(ClusterDriver, {

set(this, 'regions', filteredRegions);

const location = get(this, 'config.resourceLocation');

if (!location || !filteredRegions.findBy('name', location)){
set(this, 'config.resourceLocation', filteredRegions[0].name || '');
}

cb(true);

set(this, 'step', 2);
Expand Down Expand Up @@ -321,11 +327,11 @@ export default Component.extend(ClusterDriver, {

cb(true);
}).catch((xhr) => {
const err = xhr.body.message || xhr.body.code || xhr.body.error;

setProperties(this, { errors: [err], });
const err = get(xhr, 'body.message') || get(xhr, 'body.code') || get(xhr, 'body.error') || xhr;
const translation = this.intl.t('clusterNew.azureaks.location.error', { error: err });

cb(false, [err]);
setProperties(this, { errors: [translation], });
cb(true);
});
},

Expand Down Expand Up @@ -355,8 +361,13 @@ export default Component.extend(ClusterDriver, {
}
}),

resourceLocationChanged: observer('config.resourceLocation', function() {
resourceLocationChanged: observer('config.resourceLocation', 'regions', function() {
const { regions, config: { resourceLocation } } = this;

if (!regions){
return;
}

const match = regions.findBy('name', resourceLocation);

const regionHasAz = this.regionsWithAZs.includes(match?.displayName || '');
Expand Down
9 changes: 9 additions & 0 deletions lib/shared/addon/utils/azure-choices.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const regionsWithAZs = [
'US Gov Virginia',
'West Europe',
'West US 2',
'China North 3',
]
export let regions = {
'AzurePublicCloud': [
Expand Down Expand Up @@ -199,6 +200,10 @@ export let regions = {
{
'name': 'chinaeast2',
'displayName': 'China East 2',
},
{
'name': 'chinanorth3',
'displayName': 'China North 3',
}
].sortBy('name'),
'AzureUSGovernmentCloud': [
Expand Down Expand Up @@ -501,6 +506,10 @@ export let aksRegions = [
'name': 'chinaeast2',
'displayName': 'China East 2',
},
{
'name': 'chinanorth3',
'displayName': 'China North 3',
},
{
'name': 'eastasia',
'displayName': 'East Asia',
Expand Down
1 change: 1 addition & 0 deletions translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3577,6 +3577,7 @@ clusterNew:
location:
label: Location
prompt: Choose a location...
error: '{error}: There was a problem verifying the location. Choose valid location and try again.'
machineType:
label: VM Size
prompt: Choose a size...
Expand Down
1 change: 1 addition & 0 deletions translations/zh-hans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3561,6 +3561,7 @@ clusterNew:
location:
label: 位置
prompt: 选择位置...
error: '{error}: 验证位置时出现问题,请更换有效位置,然后重试。'
accountAccessSection:
label: 账户访问
subscriptionId:
Expand Down
1 change: 1 addition & 0 deletions translations/zh-hant-tw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3416,6 +3416,7 @@ clusterNew:
location:
label: 位置
prompt: 選擇一個位置...
error: '{error}: 驗證位置時出現問題,請更換有效位置,然後重試。'
accountAccessSection:
label: 帳號訪問
subscriptionId:
Expand Down
1 change: 1 addition & 0 deletions translations/zh-hant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,7 @@ clusterNew:
location:
label: 位置
prompt: 選擇一個位置...
error: '{error}: 驗證位置時出現問題,請更換有效位置,然後重試。'
accountAccessSection:
label: 賬戶訪問
subscriptionId:
Expand Down