diff --git a/shell/dialog/AddCustomBadgeDialog.vue b/shell/dialog/AddCustomBadgeDialog.vue index 319c687e973..f5e32fd8543 100644 --- a/shell/dialog/AddCustomBadgeDialog.vue +++ b/shell/dialog/AddCustomBadgeDialog.vue @@ -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'; @@ -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'; @@ -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(); diff --git a/shell/dialog/AssignToDialog.vue b/shell/dialog/AssignToDialog.vue index aa1e60572d5..80da0a08b6f 100644 --- a/shell/dialog/AssignToDialog.vue +++ b/shell/dialog/AssignToDialog.vue @@ -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; @@ -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; diff --git a/shell/edit/fleet.cattle.io.cluster.vue b/shell/edit/fleet.cattle.io.cluster.vue index 38e74760d54..4af0163ed82 100644 --- a/shell/edit/fleet.cattle.io.cluster.vue +++ b/shell/edit/fleet.cattle.io.cluster.vue @@ -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() { @@ -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); diff --git a/shell/models/fleet.cattle.io.cluster.js b/shell/models/fleet.cattle.io.cluster.js index 9ef5fe18820..0039185d5b0 100644 --- a/shell/models/fleet.cattle.io.cluster.js +++ b/shell/models/fleet.cattle.io.cluster.js @@ -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 }); } @@ -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(); + } } } diff --git a/shell/models/provisioning.cattle.io.cluster.js b/shell/models/provisioning.cattle.io.cluster.js index fd663492722..4fc29c2cc90 100644 --- a/shell/models/provisioning.cattle.io.cluster.js +++ b/shell/models/provisioning.cattle.io.cluster.js @@ -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 }); }