Skip to content

Commit

Permalink
backport of commit 93f7b4f (hashicorp#19189)
Browse files Browse the repository at this point in the history
Co-authored-by: Jordan Reimer <zofskeez@gmail.com>
  • Loading branch information
1 parent 02bc254 commit 105881d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ui/app/adapters/kubernetes/role.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class KubernetesRoleAdapter extends NamedPathAdapter {
}
generateCredentials(backend, data) {
const generateCredentialsUrl = `${this.buildURL()}/${encodePath(backend)}/creds/${data.role}`;

delete data.role;
return this.ajax(generateCredentialsUrl, 'POST', { data }).then((response) => {
const { lease_id, lease_duration, data } = response;

Expand Down
6 changes: 6 additions & 0 deletions ui/app/serializers/kubernetes/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export default class KubernetesConfigSerializer extends ApplicationSerializer {
const json = super.serialize(...arguments);
// remove backend value from payload
delete json.backend;
// ensure that values from a previous manual configuration are unset
if (json.disable_local_ca_jwt === false) {
json.kubernetes_ca_cert = null;
json.kubernetes_host = null;
json.service_account_jwt = null;
}
return json;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ module('Integration | Component | kubernetes | Page::Configure', function (hooks
{ label: 'kubernetes', route: 'overview' },
{ label: 'configure' },
];
this.expectedInferred = {
disable_local_ca_jwt: false,
kubernetes_ca_cert: null,
kubernetes_host: null,
service_account_jwt: null,
};
});

test('it should display proper options when toggling radio cards', async function (assert) {
Expand Down Expand Up @@ -223,7 +229,7 @@ module('Integration | Component | kubernetes | Page::Configure', function (hooks
this.server.get('/:path/check', () => new Response(204, {}));
this.server.post('/:path/config', (schema, req) => {
const json = JSON.parse(req.requestBody);
assert.deepEqual(json, { disable_local_ca_jwt: false }, 'Values are passed to create endpoint');
assert.deepEqual(json, this.expectedInferred, 'Values are passed to create endpoint');
return new Response(204, {});
});

Expand All @@ -241,4 +247,28 @@ module('Integration | Component | kubernetes | Page::Configure', function (hooks
'Transitions to configuration route on save success'
);
});

test('it should unset manual config values when saving local cluster option', async function (assert) {
assert.expect(1);

this.server.get('/:path/check', () => new Response(204, {}));
this.server.post('/:path/config', (schema, req) => {
const json = JSON.parse(req.requestBody);
assert.deepEqual(json, this.expectedInferred, 'Manual config values are unset in server payload');
return new Response(204, {});
});

await render(hbs`<Page::Configure @model={{this.newModel}} @breadcrumbs={{this.breadcrumbs}} />`, {
owner: this.engine,
});

await click('[data-test-radio-card="manual"]');
await fillIn('[data-test-input="kubernetesHost"]', this.existingConfig.kubernetes_host);
await fillIn('[data-test-input="serviceAccountJwt"]', this.existingConfig.service_account_jwt);
await fillIn('[data-test-input="kubernetesCaCert"]', this.existingConfig.kubernetes_ca_cert);

await click('[data-test-radio-card="local"]');
await click('[data-test-config] button');
await click('[data-test-config-save]');
});
});

0 comments on commit 105881d

Please sign in to comment.