From c3deb5bbc70c932ccb5202743ab482b7596600ca Mon Sep 17 00:00:00 2001 From: Jordan Reimer Date: Tue, 14 Feb 2023 22:47:23 +0000 Subject: [PATCH] backport of commit 93f7b4f33c772c11f3bf43b1f4af0bc1e8906082 --- ui/app/adapters/kubernetes/role.js | 2 +- ui/app/serializers/kubernetes/config.js | 6 ++++ .../kubernetes/page/configure-test.js | 32 ++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/ui/app/adapters/kubernetes/role.js b/ui/app/adapters/kubernetes/role.js index 1bb268d2e201..301ae6419888 100644 --- a/ui/app/adapters/kubernetes/role.js +++ b/ui/app/adapters/kubernetes/role.js @@ -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; diff --git a/ui/app/serializers/kubernetes/config.js b/ui/app/serializers/kubernetes/config.js index fccf63dce6ff..3de98f8a2f61 100644 --- a/ui/app/serializers/kubernetes/config.js +++ b/ui/app/serializers/kubernetes/config.js @@ -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; } } diff --git a/ui/tests/integration/components/kubernetes/page/configure-test.js b/ui/tests/integration/components/kubernetes/page/configure-test.js index d3bc1e824af0..439907e7f127 100644 --- a/ui/tests/integration/components/kubernetes/page/configure-test.js +++ b/ui/tests/integration/components/kubernetes/page/configure-test.js @@ -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) { @@ -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, {}); }); @@ -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``, { + 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]'); + }); });