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

Backport of Kubernetes config payload fix into release/1.13.x #19189

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
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]');
});
});