Skip to content

Commit

Permalink
remove exponentialBackOffValues keys when input clears + prevent send…
Browse files Browse the repository at this point in the history
…ing unnecessary data (#11185)

Co-authored-by: Mo Mesgin <[email protected]>
  • Loading branch information
momesgin and Mo Mesgin authored Jun 6, 2024
1 parent bf902e7 commit bb6f8af
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
8 changes: 8 additions & 0 deletions cypress/e2e/po/edit/chart-repositories.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export default class ChartRepositoriesCreateEditPo extends PagePo {
return LabeledInputPo.byLabel(this.self(), 'OCI Repository Host URL');
}

ociMinWaitInput() {
return new LabeledInputPo('[data-testid="clusterrepo-oci-min-wait-input"]');
}

ociMaxWaitInput() {
return new LabeledInputPo('[data-testid="clusterrepo-oci-max-wait-input"]');
}

authentication(): LabeledSelectPo {
return new LabeledSelectPo('.vs__dropdown-toggle');
}
Expand Down
9 changes: 9 additions & 0 deletions cypress/e2e/tests/pages/manager/repositories.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,19 @@ describe('Cluster Management Helm Repositories', { testIsolation: 'off', tags: [
repositoriesPage.create();
repositoriesPage.createEditRepositories().waitForPage();
const ociUrl = 'oci://test.rancher.io/charts/mychart';
const ociMinWait = '2';
const expectedOciMinWaitInPayload = 2;
const ociMaxWait = '7';

repositoriesPage.createEditRepositories().nameNsDescription().name().set(this.repoName);
repositoriesPage.createEditRepositories().nameNsDescription().description().set(`${ this.repoName }-description`);
repositoriesPage.createEditRepositories().repoRadioBtn().set(2);
repositoriesPage.createEditRepositories().ociUrl().set(ociUrl);
repositoriesPage.createEditRepositories().clusterRepoAuthSelectOrCreate().createBasicAuth('test', 'test');
repositoriesPage.createEditRepositories().ociMinWaitInput().set(ociMinWait);
// setting a value and removing it so in the intercept we test that the key(e.g. maxWait) is not included in the request
repositoriesPage.createEditRepositories().ociMaxWaitInput().set(ociMaxWait);
repositoriesPage.createEditRepositories().ociMaxWaitInput().clear();

cy.intercept('POST', '/v1/catalog.cattle.io.clusterrepos').as('createRepository');

Expand All @@ -218,6 +225,8 @@ describe('Cluster Management Helm Repositories', { testIsolation: 'off', tags: [
cy.wait('@createRepository', { requestTimeout: 10000 }).then((req) => {
expect(req.response?.statusCode).to.equal(201);
expect(req.request?.body?.spec.url).to.equal(ociUrl);
expect(req.request?.body?.spec.exponentialBackOffValues.minWait).to.equal(expectedOciMinWaitInPayload);
expect(req.request?.body?.spec.exponentialBackOffValues.maxWait).to.equal(undefined);
// insecurePlainHttp should always be included in the payload for oci repo creation
expect(req.request?.body?.spec.insecurePlainHttp).to.equal(false);
});
Expand Down
39 changes: 24 additions & 15 deletions shell/edit/catalog.cattle.io.clusterrepo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,45 +61,54 @@ export default {
// reset input fields when switching options
switch (clusterRepoType) {
case CLUSTER_REPO_TYPES.GIT_REPO:
Vue.set(this.value.spec, 'url', '');
Vue.set(this.value.spec, 'clientSecret', null);
this.resetOciValues();
this.resetHelmValues();
break;
case CLUSTER_REPO_TYPES.OCI_URL:
Vue.set(this.value.spec, 'url', '');
// set insecurePlainHttp to false as a secondary flag, alongside checking for 'oci://' in the URL, to determine OCI type later
Vue.set(this.value.spec, 'insecurePlainHttp', false);
Vue.set(this.value.spec, 'gitRepo', '');
Vue.set(this.value.spec, 'clientSecret', null);
if (!!this.value.spec.gitBranch) {
Vue.set(this.value.spec, 'gitBranch', '');
}
this.resetGitRepoValues();
this.resetHelmValues();
break;
case CLUSTER_REPO_TYPES.HELM_URL:
Vue.set(this.value.spec, 'url', '');
Vue.set(this.value.spec, 'gitRepo', '');
Vue.set(this.value.spec, 'clientSecret', null);
this.resetOciValues();
if (!!this.value.spec.gitBranch) {
Vue.set(this.value.spec, 'gitBranch', '');
}
this.resetGitRepoValues();
break;
}
this.resetClientSecret();
},
updateExponentialBackOffValues(key, newVal) {
if (!Object.prototype.hasOwnProperty.call(this.value.spec, 'exponentialBackOffValues')) {
Vue.set(this.value.spec, 'exponentialBackOffValues', {});
}
// when user removes the value we remove the key too, backend will set the default value
if (newVal === '') {
Vue.delete(this.value.spec.exponentialBackOffValues, key);
return;
}
Vue.set(this.value.spec.exponentialBackOffValues, key, Number(newVal));
},
resetGitRepoValues() {
Vue.delete(this.value.spec, 'gitRepo');
Vue.delete(this.value.spec, 'gitBranch');
},
resetOciValues() {
Vue.delete(this.value.spec, 'url');
Vue.delete(this.value.spec, 'insecurePlainHttp');
Vue.delete(this.value.spec, 'insecureSkipTLSVerify');
Vue.delete(this.value.spec, 'caBundle');
Vue.set(this.value.spec, 'exponentialBackOffValues', {});
Vue.delete(this.value.spec, 'exponentialBackOffValues');
this.ociMinWait = undefined;
this.ociMaxWait = undefined;
this.ociMaxRetries = undefined;
},
resetHelmValues() {
Vue.delete(this.value.spec, 'url');
},
resetClientSecret() {
Vue.set(this.value.spec, 'clientSecret', null);
}
},
};
Expand Down

0 comments on commit bb6f8af

Please sign in to comment.