Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix storage class not being selected properly #10808

Merged
merged 8 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion cypress/e2e/tests/pages/charts/rancher-backup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { ChartsPage } from '@/cypress/e2e/po/pages/charts.po';
import RadioGroupInputPo from '@/cypress/e2e/po/components/radio-group-input.po';
import { exampleStorageClass, defaultStorageClass } from '@/cypress/e2e/blueprints/charts/rancher-backup-chart';
import LabeledSelectPo from '@/cypress/e2e/po/components/labeled-select.po';
import TabbedPo from '@/cypress/e2e/po/components/tabbed.po';

const STORAGE_CLASS_RESOURCE = 'storage.k8s.io.storageclasses';

describe('Charts', { tags: ['@adminUser'] }, () => {
describe('Charts', { tags: ['@charts', '@adminUser'] }, () => {
const chartsPageUrl = '/c/local/apps/charts/chart?repo-type=cluster&repo=rancher-charts';

describe('Rancher Backups', () => {
Expand All @@ -18,6 +19,9 @@ describe('Charts', { tags: ['@adminUser'] }, () => {

describe('Rancher Backups storage class config', () => {
beforeEach(() => {
cy.intercept('/v1/storage.k8s.io.storageclasses?exclude=metadata.managedFields').as('storageClasses');
cy.intercept('/v1/persistentvolumes?exclude=metadata.managedFields').as('persistentVolumes');
cy.intercept('/v1/secrets?exclude=metadata.managedFields').as('secrets');
cy.createRancherResource('v1', STORAGE_CLASS_RESOURCE, JSON.stringify(defaultStorageClass));
cy.createRancherResource('v1', STORAGE_CLASS_RESOURCE, JSON.stringify(exampleStorageClass));
});
Expand All @@ -30,6 +34,9 @@ describe('Charts', { tags: ['@adminUser'] }, () => {
it('Should auto-select default storage class', () => {
chartsPage.goTo();
chartsPage.goToInstall().nextPage();
cy.wait('@storageClasses', { timeout: 10000 }).its('response.statusCode').should('eq', 200);
cy.wait('@persistentVolumes', { timeout: 10000 }).its('response.statusCode').should('eq', 200);
cy.wait('@secrets', { timeout: 10000 }).its('response.statusCode').should('eq', 200);

// Select the 'Use an existing storage class' option
const storageOptions = new RadioGroupInputPo('[chart="[chart: cluster/rancher-charts/rancher-backup]"]');
Expand All @@ -41,6 +48,15 @@ describe('Charts', { tags: ['@adminUser'] }, () => {

select.checkExists();
select.checkOptionSelected('test-default-storage-class');

// Verify that changing tabs doesn't reset the last selected storage class option
chartsPage.editYaml();
const tabbedOptions = new TabbedPo();

chartsPage.editOptions(tabbedOptions, '[data-testid="button-group-child-0"]');

select.checkExists();
select.checkOptionSelected('test-default-storage-class');
});
});
});
Expand Down
9 changes: 8 additions & 1 deletion shell/chart/rancher-backup/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ export default {
case 'pickSC':
this.value.persistence.enabled = true;
this.value.s3.enabled = false;
if (this.value.persistence.storageClass) {
const matchedStorageClass = this.storageClasses.find((sc) => sc.id === this.value.persistence.storageClass);

if (matchedStorageClass) {
this.storageClass = matchedStorageClass;
}
}
if (this.defaultStorageClass && (!this.value.persistence.storageClass || this.value.persistence.storageClass === '-' )) {
this.value.persistence.storageClass = this.defaultStorageClass.id;
this.storageClass = this.defaultStorageClass;
Expand Down Expand Up @@ -155,7 +162,7 @@ export default {
},
updatePageValid(update) {
this.$emit('valid', update);
}
},
},
get
};
Expand Down
Loading