From caa06f267aa5eb366c7587c025f726dcdee55c77 Mon Sep 17 00:00:00 2001 From: Jordan Reimer Date: Fri, 10 Feb 2023 11:38:23 -0700 Subject: [PATCH] fixes issue saving edited k8s role (#19133) --- .../components/page/role/create-and-edit.js | 7 +++-- .../page/role/create-and-edit-test.js | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ui/lib/kubernetes/addon/components/page/role/create-and-edit.js b/ui/lib/kubernetes/addon/components/page/role/create-and-edit.js index 1d874426d..d02a81d46 100644 --- a/ui/lib/kubernetes/addon/components/page/role/create-and-edit.js +++ b/ui/lib/kubernetes/addon/components/page/role/create-and-edit.js @@ -27,7 +27,10 @@ export default class CreateAndEditRolePageComponent extends Component { constructor() { super(...arguments); - this.initRoleRules(); + // generated role rules are only rendered for the full object chain option + if (this.args.model.generationPreference === 'full') { + this.initRoleRules(); + } // if editing and annotations or labels exist expand the section const { extraAnnotations, extraLabels } = this.args.model; if (extraAnnotations || extraLabels) { @@ -127,7 +130,7 @@ export default class CreateAndEditRolePageComponent extends Component { *save() { try { // set generatedRoleRoles to value of selected template - const selectedTemplate = this.roleRulesTemplates.findBy('id', this.selectedTemplateId); + const selectedTemplate = this.roleRulesTemplates?.findBy('id', this.selectedTemplateId); if (selectedTemplate) { this.args.model.generatedRoleRules = selectedTemplate.rules; } diff --git a/ui/tests/integration/components/kubernetes/page/role/create-and-edit-test.js b/ui/tests/integration/components/kubernetes/page/role/create-and-edit-test.js index f93bbcadc..6bf0f99a5 100644 --- a/ui/tests/integration/components/kubernetes/page/role/create-and-edit-test.js +++ b/ui/tests/integration/components/kubernetes/page/role/create-and-edit-test.js @@ -321,4 +321,30 @@ module('Integration | Component | kubernetes | Page::Role::CreateAndEdit', funct .dom('[data-test-invalid-form-alert] [data-test-inline-error-message]') .hasText('There is an error with this form.'); }); + + test('it should save edited role with correct properties', async function (assert) { + assert.expect(1); + + this.role = this.getRole(); + + this.server.post('/kubernetes-test/roles/:name', (schema, req) => { + const data = JSON.parse(req.requestBody); + const expected = { + name: 'role-0', + service_account_name: 'demo', + kubernetes_role_type: 'Role', + allowed_kubernetes_namespaces: '*', + token_max_ttl: 86400, + token_default_ttl: 600, + }; + assert.deepEqual(expected, data, 'POST request made to save role with correct properties'); + }); + + await render(hbs``, { + owner: this.engine, + }); + + await fillIn('[data-test-input="serviceAccountName"]', 'demo'); + await click('[data-test-save]'); + }); });