From 275d17f86483c8ba8688530d167460b319e7392d Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Tue, 5 Mar 2024 18:39:14 +0100 Subject: [PATCH 1/2] Add warning when edit managed App Signed-off-by: Francesco Torchia --- shell/assets/translations/en-us.yaml | 8 +++++ shell/mixins/__tests__/chart.test.ts | 54 ++++++++++++++++++++++++---- shell/mixins/chart.js | 7 ++++ 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/shell/assets/translations/en-us.yaml b/shell/assets/translations/en-us.yaml index e4de89d3cf9..60dd757d3c1 100644 --- a/shell/assets/translations/en-us.yaml +++ b/shell/assets/translations/en-us.yaml @@ -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.
+ {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: '{name} must be installed before you can install this chart.' requiresMissing: 'This chart requires another chart that provides {name}, but none was was found.' diff --git a/shell/mixins/__tests__/chart.test.ts b/shell/mixins/__tests__/chart.test.ts index 3699a2eae11..a9d8a8139e7 100644 --- a/shell/mixins/__tests__/chart.test.ts +++ b/shell/mixins/__tests__/chart.test.ts @@ -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: () => {}, @@ -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); + } + ); }); diff --git a/shell/mixins/chart.js b/shell/mixins/chart.js index 78d9e19001a..aa153032a7d 100644 --- a/shell/mixins/chart.js +++ b/shell/mixins/chart.js @@ -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; }, From bbea223f984cbbbe6db4c07c23f237e6dc6b3dc4 Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Tue, 5 Mar 2024 19:08:56 +0100 Subject: [PATCH 2/2] Add warning when delete managed App Signed-off-by: Francesco Torchia --- shell/assets/translations/en-us.yaml | 14 ++++++++------ shell/mixins/chart.js | 2 +- shell/models/catalog.cattle.io.app.js | 8 ++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/shell/assets/translations/en-us.yaml b/shell/assets/translations/en-us.yaml index 60dd757d3c1..7525b117115 100644 --- a/shell/assets/translations/en-us.yaml +++ b/shell/assets/translations/en-us.yaml @@ -890,12 +890,11 @@ catalog: chart: Chart warning: managed: - edit: - Warning, Rancher manages deployment and upgrade of the {name} app. Upgrading this app is not supported.
- {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.} - } + Warning, Rancher manages deployment and upgrade of the {name} app. Upgrading this app is not supported.
+ {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: '{name} must be installed before you can install this chart.' requiresMissing: 'This chart requires another chart that provides {name}, but none was was found.' @@ -989,6 +988,9 @@ catalog: current: '{ver} (Current)' linux: '{ver} (Linux-only)' windows: '{ver} (Windows-only)' + delete: + warning: + managed: Warning, Rancher manages deployment and upgrade of the {name} app. Deleting this app is not supported. operation: tableHeaders: action: Action diff --git a/shell/mixins/chart.js b/shell/mixins/chart.js index aa153032a7d..9803cad350b 100644 --- a/shell/mixins/chart.js +++ b/shell/mixins/chart.js @@ -191,7 +191,7 @@ export default { } if (this.existing && this.existing.upgradeAvailable === false) { - warnings.unshift(this.t('catalog.install.warning.managed.edit', { + warnings.unshift(this.t('catalog.install.warning.managed', { name: this.existing.name, version: this.chart ? this.query.versionName : null }, true)); diff --git a/shell/models/catalog.cattle.io.app.js b/shell/models/catalog.cattle.io.app.js index cf423bba1af..233a1e6153b 100644 --- a/shell/models/catalog.cattle.io.app.js +++ b/shell/models/catalog.cattle.io.app.js @@ -39,6 +39,14 @@ export default class CatalogApp extends SteveModel { return out; } + get warnDeletionMessage() { + if (this.upgradeAvailable === false) { + return this.t('catalog.delete.warning.managed', { name: this.name }); + } + + return null; + } + matchingChart(includeHidden) { const chart = this.spec?.chart;