Skip to content
Draft
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
30 changes: 18 additions & 12 deletions shell/dialog/AddCustomBadgeDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Checkbox } from '@components/Form/Checkbox';
import { LabeledInput } from '@components/Form/LabeledInput';
import ColorInput from '@shell/components/form/ColorInput';
import { parseColor, textColor } from '@shell/utils/color';
import { NORMAN } from '@shell/config/types';
import { MANAGEMENT } from '@shell/config/types';
import { abbreviateClusterName } from '@shell/utils/cluster';
import { _CREATE, _EDIT } from '@shell/config/query-params';
import ClusterIconMenu from '@shell/components/ClusterIconMenu';
Expand Down Expand Up @@ -67,10 +67,10 @@ export default {
if (this.isCreate || this.clusterExplorer) {
return;
}
// INFO: Fetch the cluster object if it's an edit
await this.$store.dispatch('rancher/find', { type: NORMAN.CLUSTER, id: this.currentCluster?.id });
// INFO: currentCluster is already a MANAGEMENT.CLUSTER with badge annotations, no need to fetch NORMAN.CLUSTER
// This also handles the case when MCM is disabled and NORMAN.CLUSTER schema doesn't exist

if (this.currentCluster.metadata?.annotations) {
if (this.currentCluster?.metadata?.annotations) {
this.badgeComment = this.currentCluster.metadata?.annotations[CLUSTER_BADGE.TEXT];
this.useCustomComment = this.badgeComment?.length > 0;
this.badgeBgColor = this.currentCluster.metadata?.annotations[CLUSTER_BADGE.COLOR] || 'transparent';
Expand Down Expand Up @@ -179,17 +179,23 @@ export default {
try {
// INFO: If we're editing a cluster, update the cluster object
if (!this.isCreate && !this.clusterExplorer) {
const norman = await this.$store.dispatch('rancher/find', { type: NORMAN.CLUSTER, id: this.currentCluster?.id });
// Use MANAGEMENT.CLUSTER (currentCluster) instead of NORMAN.CLUSTER
// This works with MCM disabled where NORMAN.CLUSTER schema doesn't exist
const cluster = await this.$store.dispatch('management/find', { type: MANAGEMENT.CLUSTER, id: this.currentCluster?.id });

delete norman.annotations[CLUSTER_BADGE.COLOR];
delete norman.annotations[CLUSTER_BADGE.ICON_TEXT];
delete norman.annotations[CLUSTER_BADGE.TEXT];
if (!cluster.metadata.annotations) {
cluster.metadata.annotations = {};
}

norman.annotations[CLUSTER_BADGE.COLOR] = this.badgeColorPicker ? this.badgeBgColor : 'transparent';
norman.annotations[CLUSTER_BADGE.ICON_TEXT] = this.letter.toUpperCase();
norman.annotations[CLUSTER_BADGE.TEXT] = this.badgeComment;
delete cluster.metadata.annotations[CLUSTER_BADGE.COLOR];
delete cluster.metadata.annotations[CLUSTER_BADGE.ICON_TEXT];
delete cluster.metadata.annotations[CLUSTER_BADGE.TEXT];

await norman.save();
cluster.metadata.annotations[CLUSTER_BADGE.COLOR] = this.badgeColorPicker ? this.badgeBgColor : 'transparent';
cluster.metadata.annotations[CLUSTER_BADGE.ICON_TEXT] = this.letter.toUpperCase();
cluster.metadata.annotations[CLUSTER_BADGE.TEXT] = this.badgeComment;

await cluster.save();

buttonDone(true);
this.close();
Expand Down
16 changes: 14 additions & 2 deletions shell/dialog/AssignToDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export default {
},

async fetch() {
await this.$store.dispatch('rancher/findAll', { type: NORMAN.CLUSTER });
// Check if NORMAN.CLUSTER schema exists (it won't when MCM is disabled)
const normanSchema = this.$store.getters['rancher/schemaFor'](NORMAN.CLUSTER, false, false);

if (normanSchema) {
await this.$store.dispatch('rancher/findAll', { type: NORMAN.CLUSTER });
}
this.allWorkspaces = await this.$store.dispatch('management/findAll', { type: FLEET.WORKSPACE });
this.moveTo = this.workspace;
this.loaded = true;
Expand Down Expand Up @@ -73,7 +78,14 @@ export default {
this.errors = [];

for ( const fleetCluster of this.toAssign ) {
const c = await this.$store.dispatch(`rancher/clone`, { resource: fleetCluster.norman });
// Skip if norman cluster is not available (MCM disabled)
const norman = await fleetCluster.norman;

if (!norman) {
continue;
}

const c = await this.$store.dispatch(`rancher/clone`, { resource: norman });

if ( !c ) {
continue;
Expand Down
26 changes: 17 additions & 9 deletions shell/edit/fleet.cattle.io.cluster.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ export default {
},

async fetch() {
const norman = await this.$store.dispatch('rancher/find', { type: NORMAN.CLUSTER, id: this.value.metadata.labels[FLEET.CLUSTER_NAME] });
const nc = await this.$store.dispatch(`rancher/clone`, { resource: norman });
// Check if NORMAN.CLUSTER schema exists (it won't when MCM is disabled)
const normanSchema = this.$store.getters['rancher/schemaFor'](NORMAN.CLUSTER, false, false);

if ( !nc.metadata ) {
nc.metadata = {};
}
if (normanSchema) {
const norman = await this.$store.dispatch('rancher/find', { type: NORMAN.CLUSTER, id: this.value.metadata.labels[FLEET.CLUSTER_NAME] });
const nc = await this.$store.dispatch(`rancher/clone`, { resource: norman });

if ( !nc.metadata ) {
nc.metadata = {};
}

this.normanCluster = nc;
this.normanCluster = nc;
}
},

data() {
Expand All @@ -59,10 +64,13 @@ export default {

await this.value.save();

await this.normanCluster.save();
// Only save norman cluster if it was loaded (MCM enabled)
if (this.normanCluster) {
await this.normanCluster.save();

// Changes (such as labels or annotations fields) to normanCluster are reflected in the fleet cluster via Rancher services, so wait for that to occur
await this.waitForFleetClusterLastRevision();
// Changes (such as labels or annotations fields) to normanCluster are reflected in the fleet cluster via Rancher services, so wait for that to occur
await this.waitForFleetClusterLastRevision();
}

this.done();
buttonDone(true);
Expand Down
20 changes: 17 additions & 3 deletions shell/models/fleet.cattle.io.cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ export default class FleetCluster extends SteveModel {
return this.basicNorman;
}

// Check if NORMAN.CLUSTER schema exists (it won't when MCM is disabled)
const normanSchema = this.$rootGetters['rancher/schemaFor'](NORMAN.CLUSTER, false, false);

if (!normanSchema) {
return null;
}

// If navigate to YAML view directly, norman is not loaded yet
return this.$dispatch('rancher/find', { type: NORMAN.CLUSTER, id: this.metadata.labels[FLEET_LABELS.CLUSTER_NAME] }, { root: true });
}
Expand Down Expand Up @@ -230,9 +237,16 @@ export default class FleetCluster extends SteveModel {

const norman = await this.normanClone();

norman.setLabels(parsed.metadata.labels);
norman.setAnnotations(parsed.metadata.annotations);
// Only save to norman cluster if it's available (MCM enabled)
if (norman) {
if (parsed.metadata?.labels) {
norman.setLabels(parsed.metadata.labels);
}
if (parsed.metadata?.annotations) {
norman.setAnnotations(parsed.metadata.annotations);
}

await norman.save();
await norman.save();
}
}
}
7 changes: 7 additions & 0 deletions shell/models/provisioning.cattle.io.cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ export default class ProvCluster extends SteveModel {
return null;
}

// Check if NORMAN.CLUSTER schema exists (it won't when MCM is disabled)
const normanSchema = this.$rootGetters['rancher/schemaFor'](NORMAN.CLUSTER, false, false);

if (!normanSchema) {
return null;
}

return await this.$dispatch('rancher/find', { type: NORMAN.CLUSTER, id: name }, { root: true });
}

Expand Down