Skip to content

Commit

Permalink
Fix version check for defaults chart settings route
Browse files Browse the repository at this point in the history
  • Loading branch information
jordojordo committed Oct 30, 2024
1 parent 2ddca88 commit 0a45177
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}
}
43 changes: 25 additions & 18 deletions pkg/kubewarden/plugins/policy-class.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 0a45177

Please sign in to comment.