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

AKS - fix editing imported clusters #11120

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 10 additions & 2 deletions pkg/aks/components/CruAks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
} from '../util/aks';
import { parseTaint } from '../util/taints';

import { diffUpstreamSpec } from '@shell/utils/kontainer';
import { diffUpstreamSpec, syncUpstreamConfig } from '@shell/utils/kontainer';
import {
requiredInCluster,
clusterNameChars,
Expand Down Expand Up @@ -144,6 +144,12 @@ export default defineComponent({
const liveNormanCluster = await this.value.findNormanCluster();

this.normanCluster = await store.dispatch(`rancher/clone`, { resource: liveNormanCluster });

// ensure any fields editable through this UI that have been altered in azure portal are shown here - see syncUpstreamConfig jsdoc for details
if (!this.isNewOrUnprovisioned) {
syncUpstreamConfig('aks', this.normanCluster);
}

// track original version on edit to ensure we don't offer k8s downgrades
this.originalVersion = this.normanCluster?.aksConfig?.kubernetesVersion;
} else {
Expand Down Expand Up @@ -736,12 +742,14 @@ export default defineComponent({
}
},

setAuthorizedIpRanges(neu) {
setAuthorizedIPRanges(neu) {
if (neu) {
this.$set(this.config, 'privateCluster', false);
delete this.config.managedIdentity;
delete this.config.privateDnsZone;
delete this.config.userAssignedIdentity;
} else {
this.$set(this.config, 'authorizedIpRanges', []);
}
},

Expand Down
25 changes: 24 additions & 1 deletion shell/utils/kontainer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
import { isArray } from '@shell/utils/array';
import { set, get } from '@shell/utils/object';
import { set, get, isEmpty } from '@shell/utils/object';

/**
* This function accepts a v3 cluster object and mutates its config field to sync values that were set outside Rancher (eg, when an imported cluster is created in its respective cloud provider).
* Values configured outside of rancher are not automatically propagated to the config field that the UI edits; they are reflected in the aksStatus/eksStatus/gkeStatus.upstreamSpec field.
* This function works in tandem with diffUpstreamSpec: the former runs when the edit form is initialized and the latter runs when the cluster is saved.
* @param configPrefix one of aks, eks, gke
* @param normanCluster v3 cluster object
*/
export function syncUpstreamConfig(configPrefix: string, normanCluster: {[key: string]: any}): void {
const configKey = `${ configPrefix }Config`;
const statusKey = `${ configPrefix }Status`;

const rancherConfig = normanCluster[configKey] || {};
const upstreamConfig = normanCluster?.[statusKey]?.upstreamSpec || {};

if (!isEmpty(upstreamConfig)) {
Object.keys(upstreamConfig).forEach((key) => {
if (isEmpty(rancherConfig[key]) && !isEmpty(upstreamConfig.key)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be !isEmpty(upstreamConfig[key])?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call - updated now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i still see this as the old version.

i made the tweak locally and i think it fixed an issue i was seeing (deployed in ukwest, availability zones in edit screen incorrectly shown)

set(rancherConfig, key, upstreamConfig[key]);
}
});
}
}

/**
* Hosted provider (aks gke eks) edit functionality differs from other k8s resources
Expand Down
Loading