diff --git a/pkg/kubewarden/models/policies.kubewarden.io.clusteradmissionpolicy.js b/pkg/kubewarden/models/policies.kubewarden.io.clusteradmissionpolicy.js index 49c335f3..44a1bfa7 100644 --- a/pkg/kubewarden/models/policies.kubewarden.io.clusteradmissionpolicy.js +++ b/pkg/kubewarden/models/policies.kubewarden.io.clusteradmissionpolicy.js @@ -29,6 +29,12 @@ export default class ClusterAdmissionPolicy extends PolicyModel { } editPolicySettings() { - this.currentRouter().push(this.kubewardenDefaultsRoute); + const route = this.kubewardenDefaultsRoute; + + if (route) { + this.currentRouter().push(route); + } else { + console.error('Could not determine the route to the Kubewarden Defaults chart.'); + } } } diff --git a/pkg/kubewarden/plugins/policy-class.js b/pkg/kubewarden/plugins/policy-class.js index 2fc2e6de..66626c22 100644 --- a/pkg/kubewarden/plugins/policy-class.js +++ b/pkg/kubewarden/plugins/policy-class.js @@ -1,4 +1,5 @@ import jsyaml from 'js-yaml'; +import semver from 'semver'; import { colorForState, stateBackground, stateDisplay } from '@shell/plugins/dashboard-store/resource-class'; import { get } from '@shell/utils/object'; @@ -36,28 +37,34 @@ export default class PolicyModel extends KubewardenModel { const cluster = this.$rootGetters['currentCluster']?.id || '_'; const helmChart = this.metadata?.labels?.['helm.sh/chart'] || ''; - if (helmChart && helmChart.includes('-')) { - const arr = helmChart.split('-'); + if (helmChart) { + const parts = helmChart.split('-'); - if (arr[arr.length - 1].includes('rc')) { - version = `${ arr[arr.length - 2] }-${ arr[arr.length - 1] }`; - } else { - version = arr[arr.length - 1]; + // Start checking from the end of the array to find a valid semver + for (let i = parts.length - 1; i >= 0; i--) { + const potentialVersion = parts.slice(i).join('-'); + + if (semver.valid(potentialVersion)) { + version = potentialVersion; + break; + } } - } - const query = { - [REPO_TYPE]: 'cluster', - [REPO]: 'kubewarden-charts', - [CHART]: 'kubewarden-defaults', - [VERSION]: version - }; + const query = { + [REPO_TYPE]: 'cluster', + [REPO]: 'kubewarden-charts', + [CHART]: 'kubewarden-defaults', + [VERSION]: version + }; + + return { + name: 'c-cluster-apps-charts-install', + params: { cluster }, + query, + }; + } - return { - name: 'c-cluster-apps-charts-install', - params: { cluster }, - query, - }; + return null; } get isKubewardenDefaultPolicy() {