diff --git a/lib/shared/addon/components/cluster-driver/driver-aks/component.js b/lib/shared/addon/components/cluster-driver/driver-aks/component.js index 2f0513933..9b693c16b 100644 --- a/lib/shared/addon/components/cluster-driver/driver-aks/component.js +++ b/lib/shared/addon/components/cluster-driver/driver-aks/component.js @@ -175,7 +175,8 @@ export default Component.extend(ClusterDriver, { }, async loadRegions(cb) { const store = get(this, 'globalStore') - const { selectedCloudCredential, regionsWithAZs } = this; + const selectedCloudCredential = this.selectedCloudCredential; + const regionsWithAZs = this.regionsWithAZs const data = { cloudCredentialId: get(selectedCloudCredential, 'id'), // tenantId: get(this, 'config.tenantId'), @@ -218,9 +219,11 @@ export default Component.extend(ClusterDriver, { }) } } catch (error) { - cb(false, error); + this.send('errorHandler', error); + cb(false); } }, + authenticate(cb) { const store = get(this, 'globalStore') const { selectedCloudCredential } = this; @@ -469,10 +472,8 @@ export default Component.extend(ClusterDriver, { return this.mode === 'edit' && !this.hasProvisioned; }), - cloudCredentials: computed('model.cloudCredentials', function() { - const { model: { cloudCredentials } } = this; - - return cloudCredentials.filter((cc) => { + cloudCredentials: computed('config.azureCredentialSecret', 'model.cloudCredentials', function() { + const out = this.model.cloudCredentials.filter((cc) => { const isAzure = Object.prototype.hasOwnProperty.call(cc, 'azurecredentialConfig'); if (isAzure) { @@ -481,18 +482,36 @@ export default Component.extend(ClusterDriver, { return false; }); + + + let cur = this.config?.azureCredentialSecret; + + if ( cur && !cur.startsWith('cattle-global-data:') ) { + cur = `cattle-global-data:${ cur }`; + } + + if ( cur && !out.find((x) => x.id === cur ) ) { + const obj = this.globalStore.createRecord({ + name: `${ cur.replace(/^cattle-global-data:/, '') } (current)`, + id: cur, + type: 'cloudCredential', + azurecredentialConfig: {}, + }); + + out.push(obj); + } + + return out; }), - selectedCloudCredential: computed('config.azureCredentialSecret', function() { - const { - model: { cloudCredentials = [] }, - config: { azureCredentialSecret } - } = this; + selectedCloudCredential: computed('cloudCredentials.@each.id', 'config.azureCredentialSecret', function() { + const cur = this.config?.azureCredentialSecret; + const cloudCredentials = this.cloudCredentials; - if (isEmpty(cloudCredentials) && isEmpty(azureCredentialSecret)) { + if (isEmpty(cloudCredentials) && isEmpty(cur)) { return null; } else { - return cloudCredentials.findBy('id', azureCredentialSecret.includes('cattle-global-data:') ? azureCredentialSecret : `cattle-global-data:${ azureCredentialSecret }`); + return cloudCredentials.findBy('id', cur.includes('cattle-global-data:') ? cur : `cattle-global-data:${ cur }`); } }),