Skip to content

Commit e739a1f

Browse files
momesginMo Mesgin
andauthored
Preserve custom registry value when selecting a different version (#16186)
* preserve custom registry value when selecting a different version * minor refactor * fix e2e test * fix e2e test --------- Co-authored-by: Mo Mesgin <[email protected]>
1 parent e7e5d0b commit e739a1f

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

cypress/e2e/po/pages/explorer/charts/install-charts.po.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import PagePo from '@/cypress/e2e/po/pages/page.po';
22
import AsyncButtonPo from '@/cypress/e2e/po/components/async-button.po';
33
import TabbedPo from '~/cypress/e2e/po/components/tabbed.po';
4+
import CheckboxInputPo from '~/cypress/e2e/po/components/checkbox-input.po';
5+
import LabeledInputPo from '~/cypress/e2e/po/components/labeled-input.po';
6+
import LabeledSelectPo from '~/cypress/e2e/po/components/labeled-select.po';
47

58
export class InstallChartPage extends PagePo {
69
private static createPath(clusterId: string) {
@@ -54,4 +57,16 @@ export class InstallChartPage extends PagePo {
5457
chartName() {
5558
return this.self().get('[data-testid="NameNsDescriptionNameInput"]');
5659
}
60+
61+
chartVersionSelector(): LabeledSelectPo {
62+
return new LabeledSelectPo('[data-testid="chart-version-selector"]');
63+
}
64+
65+
customRegistryCheckbox(): CheckboxInputPo {
66+
return new CheckboxInputPo('[data-testid="custom-registry-checkbox"]');
67+
}
68+
69+
customRegistryInput(): LabeledInputPo {
70+
return new LabeledInputPo('[data-testid="custom-registry-input"]');
71+
}
5772
}

cypress/e2e/tests/pages/charts/chart-install-wizard.spec.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { InstallChartPage } from '@/cypress/e2e/po/pages/explorer/charts/install
44
import { MEDIUM_TIMEOUT_OPT } from '@/cypress/support/utils/timeouts';
55
import TabbedPo from '@/cypress/e2e/po/components/tabbed.po';
66
import LabeledSelectPo from '@/cypress/e2e/po/components/labeled-select.po';
7+
import ChartInstalledAppsListPagePo from '@/cypress/e2e/po/pages/chart-installed-apps.po';
8+
import { NamespaceFilterPo } from '@/cypress/e2e/po/components/namespace-filter.po';
79

810
const configMapPayload = {
911
apiVersion: 'v1',
@@ -67,4 +69,61 @@ describe('Charts Wizard', { testIsolation: 'off', tags: ['@charts', '@adminUser'
6769
cy.updateNamespaceFilter('local', 'none', '{"local":["all://user"]}');
6870
});
6971
});
72+
73+
describe('Custom registry', () => {
74+
const namespacePicker = new NamespaceFilterPo();
75+
const installChartPage = new InstallChartPage();
76+
const chartPage = new ChartPage();
77+
const chartName = 'Rancher Backups';
78+
const customRegistry = 'my.custom.registry:5000';
79+
80+
it('should persist custom registry when changing chart version', () => {
81+
const installedAppsPage = new ChartInstalledAppsListPagePo('local', 'apps');
82+
83+
// We need to install the chart first to have the versions selector show up later when we come back to the install page
84+
ChartPage.navTo(null, chartName);
85+
chartPage.waitForChartHeader(chartName, MEDIUM_TIMEOUT_OPT);
86+
chartPage.goToInstall();
87+
installChartPage.nextPage();
88+
89+
cy.intercept('POST', '/v1/catalog.cattle.io.clusterrepos/rancher-charts?action=install').as('installApp');
90+
installChartPage.installChart();
91+
namespacePicker.toggle();
92+
namespacePicker.clickOptionByLabel('All Namespaces');
93+
namespacePicker.isChecked('All Namespaces');
94+
namespacePicker.closeDropdown();
95+
installedAppsPage.waitForInstallCloseTerminal('installApp', ['rancher-backup', 'rancher-backup-crd']);
96+
97+
ChartPage.navTo(null, chartName);
98+
chartPage.waitForChartHeader(chartName, MEDIUM_TIMEOUT_OPT);
99+
chartPage.goToInstall();
100+
101+
// The version selector should now be visible
102+
installChartPage.chartVersionSelector().self().should('be.visible');
103+
104+
installChartPage.customRegistryCheckbox().set();
105+
106+
// Enter custom registry
107+
installChartPage.customRegistryInput().self().should('be.visible');
108+
installChartPage.customRegistryInput().set(customRegistry);
109+
110+
// Change chart version
111+
installChartPage.chartVersionSelector().toggle();
112+
installChartPage.chartVersionSelector().clickOption(2);
113+
114+
// Verify custom registry is still there
115+
installChartPage.customRegistryCheckbox().isChecked();
116+
installChartPage.customRegistryInput().self().should('have.value', customRegistry);
117+
});
118+
119+
after('clean up', () => {
120+
const chartNamespace = 'cattle-resources-system';
121+
const chartApp = 'rancher-backup';
122+
const chartCrd = 'rancher-backup-crd';
123+
124+
cy.createRancherResource('v1', `catalog.cattle.io.apps/${ chartNamespace }/${ chartApp }?action=uninstall`, '{}');
125+
cy.createRancherResource('v1', `catalog.cattle.io.apps/${ chartNamespace }/${ chartCrd }?action=uninstall`, '{}');
126+
cy.updateNamespaceFilter('local', 'none', '{"local":["all://user"]}');
127+
});
128+
});
70129
});

shell/pages/c/_cluster/apps/charts/install.vue

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ export default {
310310
two different Helm chart versions is a "user value," or
311311
a user-selected customization.
312312
*/
313+
this.preserveCustomRegistryValue();
313314
userValues = diff(this.loadedVersionValues, this.chartValues);
314315
} else if ( this.existing ) {
315316
await this.existing.fetchValues(); // In theory this has already been called, but do again to be safe
@@ -824,6 +825,35 @@ export default {
824825
},
825826
826827
methods: {
828+
/**
829+
* The custom registry UI fields (checkbox and input) are not directly bound to chartValues.
830+
* Before calculating the diff to carry over user customizations, we must
831+
* first synchronize the state of these UI fields with chartValues. This
832+
* ensures any user changes to the custom registry settings are
833+
* included in the diff and preserved when changing versions.
834+
*/
835+
preserveCustomRegistryValue() {
836+
if (!this.showCustomRegistry) {
837+
return;
838+
}
839+
840+
if (this.showCustomRegistryInput) {
841+
set(this.chartValues, 'global.systemDefaultRegistry', this.customRegistrySetting);
842+
set(this.chartValues, 'global.cattle.systemDefaultRegistry', this.customRegistrySetting);
843+
} else {
844+
// Note: Using `delete` here is safe because this is not a reactive property update
845+
// that the UI needs to track. This is a one-time mutation before a diff.
846+
if (get(this.chartValues, 'global.systemDefaultRegistry')) {
847+
delete this.chartValues.global.systemDefaultRegistry;
848+
}
849+
if (get(this.chartValues, 'global.cattle.systemDefaultRegistry')) {
850+
// It's possible `this.chartValues.global.cattle` doesn't exist,
851+
// but `get` ensures we only proceed if the full path exists.
852+
delete this.chartValues.global.cattle.systemDefaultRegistry;
853+
}
854+
}
855+
},
856+
827857
async getClusterRegistry() {
828858
const hasPermissionToSeeProvCluster = this.$store.getters[`management/schemaFor`](CAPI.RANCHER_CLUSTER);
829859
@@ -1367,6 +1397,7 @@ export default {
13671397
<!-- We have a chart for the app, let the user select a new version -->
13681398
<LabeledSelect
13691399
v-if="chart"
1400+
data-testid="chart-version-selector"
13701401
:label="t('catalog.install.version')"
13711402
:value="query.versionName"
13721403
:options="filteredVersions"
@@ -1435,6 +1466,7 @@ export default {
14351466
v-if="showCustomRegistry"
14361467
v-model:value="showCustomRegistryInput"
14371468
class="mb-20"
1469+
data-testid="custom-registry-checkbox"
14381470
:label="t('catalog.chart.registry.custom.checkBoxLabel')"
14391471
:tooltip="t('catalog.chart.registry.tooltip')"
14401472
/>
@@ -1443,6 +1475,7 @@ export default {
14431475
<LabeledInput
14441476
v-if="showCustomRegistryInput"
14451477
v-model:value="customRegistrySetting"
1478+
data-testid="custom-registry-input"
14461479
label-key="catalog.chart.registry.custom.inputLabel"
14471480
placeholder-key="catalog.chart.registry.custom.placeholder"
14481481
:min-height="30"

0 commit comments

Comments
 (0)