From b6973366fc25ce7a2cb2fb29c9163f2e5127f1e2 Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Thu, 6 Feb 2025 17:39:27 +0100 Subject: [PATCH] Fleet: Labels refactoring Signed-off-by: Francesco Torchia --- shell/config/labels-annotations.js | 5 ++++- shell/models/fleet.cattle.io.bundle.js | 7 ++++--- shell/models/fleet.cattle.io.gitrepo.js | 8 ++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/shell/config/labels-annotations.js b/shell/config/labels-annotations.js index 6b9ac1ab19..bfb2ecd75e 100644 --- a/shell/config/labels-annotations.js +++ b/shell/config/labels-annotations.js @@ -109,6 +109,7 @@ export const CATALOG = { }; export const FLEET = { + REPO_NAME: 'fleet.cattle.io/repo-name', CLUSTER_DISPLAY_NAME: 'management.cattle.io/cluster-display-name', CLUSTER_NAME: 'management.cattle.io/cluster-name', BUNDLE_ID: 'fleet.cattle.io/bundle-id', @@ -116,7 +117,9 @@ export const FLEET = { BUNDLE_NAMESPACE: 'fleet.cattle.io/bundle-namespace', MANAGED: 'fleet.cattle.io/managed', CLUSTER_NAMESPACE: 'fleet.cattle.io/cluster-namespace', - CLUSTER: 'fleet.cattle.io/cluster' + CLUSTER: 'fleet.cattle.io/cluster', + CREATED_BY_USER_ID: 'fleet.cattle.io/created-by-user-id', + CREATED_BY_USER_NAME: 'fleet.cattle.io/created-by-display-name', }; export const RBAC = { PRODUCT: 'management.cattle.io/ui-product' }; diff --git a/shell/models/fleet.cattle.io.bundle.js b/shell/models/fleet.cattle.io.bundle.js index 274410ea3e..0256b568c1 100644 --- a/shell/models/fleet.cattle.io.bundle.js +++ b/shell/models/fleet.cattle.io.bundle.js @@ -3,6 +3,7 @@ import SteveModel from '@shell/plugins/steve/steve-class'; import typeHelper from '@shell/utils/type-helpers'; import { addObject, addObjects, findBy } from '@shell/utils/array'; import { FLEET, MANAGEMENT } from '@shell/config/types'; +import { FLEET as FLEET_ANNOTATIONS } from '@shell/config/labels-annotations'; import { convertSelectorObj, matching } from '@shell/utils/selector'; export default class FleetBundle extends SteveModel { @@ -21,7 +22,7 @@ export default class FleetBundle extends SteveModel { get repoName() { const labels = this.metadata?.labels || {}; - return labels['fleet.cattle.io/repo-name']; + return labels[FLEET_ANNOTATIONS.REPO_NAME]; } get targetClusters() { @@ -129,7 +130,7 @@ export default class FleetBundle extends SteveModel { } get authorId() { - return this.metadata.labels['fleet.cattle.io/created-by-user-id']; + return this.metadata.labels[FLEET_ANNOTATIONS.CREATED_BY_USER_ID]; } get author() { @@ -141,7 +142,7 @@ export default class FleetBundle extends SteveModel { } get createdBy() { - const displayName = this.metadata.labels['fleet.cattle.io/created-by-display-name']; + const displayName = this.metadata.labels[FLEET_ANNOTATIONS.CREATED_BY_USER_NAME]; if (!displayName) { return null; diff --git a/shell/models/fleet.cattle.io.gitrepo.js b/shell/models/fleet.cattle.io.gitrepo.js index 3db5240a34..fb07387aad 100644 --- a/shell/models/fleet.cattle.io.gitrepo.js +++ b/shell/models/fleet.cattle.io.gitrepo.js @@ -352,11 +352,11 @@ export default class GitRepo extends SteveModel { } get bundles() { - return this.$getters['matching'](FLEET.BUNDLE, { 'fleet.cattle.io/repo-name': this.name }, this.namespace); + return this.$getters['matching'](FLEET.BUNDLE, { [FLEET_ANNOTATIONS.REPO_NAME]: this.name }, this.namespace); } get bundleDeployments() { - return this.$getters['matching'](FLEET.BUNDLE_DEPLOYMENT, { 'fleet.cattle.io/repo-name': this.name }); + return this.$getters['matching'](FLEET.BUNDLE_DEPLOYMENT, { [FLEET_ANNOTATIONS.REPO_NAME]: this.name }); } get allBundlesStatuses() { @@ -481,7 +481,7 @@ export default class GitRepo extends SteveModel { } get authorId() { - return this.metadata.labels['fleet.cattle.io/created-by-user-id']; + return this.metadata.labels[FLEET_ANNOTATIONS.CREATED_BY_USER_ID]; } get author() { @@ -493,7 +493,7 @@ export default class GitRepo extends SteveModel { } get createdBy() { - const displayName = this.metadata.labels['fleet.cattle.io/created-by-display-name']; + const displayName = this.metadata.labels[FLEET_ANNOTATIONS.CREATED_BY_USER_NAME]; if (!displayName) { return null;