Skip to content

Commit

Permalink
Add warning when edit managed App
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Torchia <[email protected]>
  • Loading branch information
torchiaf committed Mar 5, 2024
1 parent 7d1cb87 commit 275d17f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
8 changes: 8 additions & 0 deletions shell/assets/translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,14 @@ catalog:
appReadmeMissing: This chart doesn't have any additional chart information.
appReadmeTitle: Chart Information (Helm README)
chart: Chart
warning:
managed:
edit:
Warning, Rancher manages deployment and upgrade of the {name} app. Upgrading this app is not supported.<br>
{version, select,
null { }
other { Under most circumstances, no user intervention should be needed to ensure that the {version} version is compatible with the version of Rancher that you are running.}
}
error:
requiresFound: '<a href="{url}">{name}</a> must be installed before you can install this chart.'
requiresMissing: 'This chart requires another chart that provides {name}, but none was was found.'
Expand Down
54 changes: 48 additions & 6 deletions shell/mixins/__tests__/chart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@ import ChartMixin from '@shell/mixins/chart';
import { OPA_GATE_KEEPER_ID } from '@shell/pages/c/_cluster/gatekeeper/index.vue';

describe('chartMixin', () => {
const testCases = [[null, 0], [OPA_GATE_KEEPER_ID, 1], ['any_other_id', 0]];
const testCases = {
opa: [
[null, 0],
[OPA_GATE_KEEPER_ID, 1],
['any_other_id', 0]
],
managedApps: [
[false, false, 0],
[true, null, 0],
[true, true, 0],
[true, false, 1],
],
};

it.each(testCases)(
'should add OPA deprecation warning properly', (chartId, expected) => {
const localVue = createLocalVue();
const localVue = createLocalVue();

localVue.use(Vuex);
localVue.mixin(ChartMixin);
localVue.use(Vuex);
localVue.mixin(ChartMixin);

it.each(testCases.opa)(
'should add OPA deprecation warning properly', (chartId, expected) => {
const store = new Vuex.Store({
getters: {
currentCluster: () => {},
Expand All @@ -37,4 +49,34 @@ describe('chartMixin', () => {
expect(warnings).toHaveLength(expected);
}
);

it.each(testCases.managedApps)(
'should add managed apps warning properly', (isEdit, upgradeAvailable, expected) => {
const id = 'cattle-fleet-local-system/fleet-agent-local';
const data = isEdit ? { existing: { id, upgradeAvailable } } : undefined;

const store = new Vuex.Store({
getters: {
currentCluster: () => {},
isRancher: () => true,
'catalog/repo': () => {
return () => 'repo';
},
'catalog/chart': () => {
return () => ({ id });
},
'i18n/t': () => jest.fn()
}
});

const vm = localVue.extend({});
const instance = new vm({ store, data });

instance.$route = { query: { chart: 'chart_name' } };

const warnings = instance.warnings;

expect(warnings).toHaveLength(expected as number);
}
);
});
7 changes: 7 additions & 0 deletions shell/mixins/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ export default {
warnings.unshift(this.t('gatekeeperIndex.deprecated', {}, true));
}

if (this.existing && this.existing.upgradeAvailable === false) {
warnings.unshift(this.t('catalog.install.warning.managed.edit', {
name: this.existing.name,
version: this.chart ? this.query.versionName : null
}, true));
}

return warnings;
},

Expand Down

0 comments on commit 275d17f

Please sign in to comment.