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

Kubernetes config payload fix #19184

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed that this was causing a warning to display since role is not an accepted value in the post body.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this also be added to the serializer as serialize: false ?

Copy link
Contributor Author

@zofskeez zofskeez Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a custom adapter method the serializer is not hit. We decided not to have a dedicated model for role credentials since they are not persisted in the app which is why we are using the role adapter for the request. The payload is also not the role model but a pojo of values from the form.

Copy link
Contributor

@hellobontempo hellobontempo Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right! I missed the method - thanks for explaining

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 @@ -241,4 +241,34 @@ 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);
const expected = {
disable_local_ca_jwt: false,
kubernetes_ca_cert: null,
kubernetes_host: null,
service_account_jwt: null,
};
assert.deepEqual(json, expected, '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]');
});
});