Skip to content

Commit

Permalink
remove $set usage in eks provisioning and gatekeeper constraints (#12447
Browse files Browse the repository at this point in the history
)

* remove $set usage in eks provisioning and gatekeeper constraints

* fix lint

* fix gatekeeper constraint  parameters event handling
  • Loading branch information
mantis-toboggan-md authored Nov 15, 2024
1 parent 20f7490 commit 4dcbc1d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 0 additions & 2 deletions pkg/aks/util/__tests__/validators.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as validators from '@pkg/aks/util/validators';
import { set } from '@shell/utils/object';
import { AKSNodePool } from 'types';

validators.requiredTranslation = (ctx, label) => `${ label } is required.`;
Expand All @@ -11,7 +10,6 @@ const MOCK_TRANSLATION = 'abc';
const mockCtx = {
normanCluster: { },
t: () => MOCK_TRANSLATION,
$set: set
};

describe('fx: requiredInCluster', () => {
Expand Down
2 changes: 0 additions & 2 deletions pkg/eks/util/__tests__/validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@ describe('validate EKS node group names', () => {
[{
nodeGroups: [{ nodegroupName: 'abc' }, { nodegroupName: 'def' }],
t: mockTranslation,
$set: () => {}
} as any as CruEKSContext, null],
[{
nodeGroups: [{ nodegroupName: 'abc' }, { nodegroupName: 'abc' }, { nodegroupName: 'def' }],
t: mockTranslation,
$set: () => {}
} as any as CruEKSContext, 'eks.errors.nodeGroups.nameUnique']
])('should return an error if any node group within ctx has non-unique name, if not passed a name', (ctx, expected) => {
const res = EKSValidators.nodeGroupNamesUnique(ctx)(undefined);
Expand Down
4 changes: 2 additions & 2 deletions pkg/eks/util/validators.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { set } from '@shell/utils/object';
import { EKSConfig, EKSNodeGroup } from 'types';

export interface CruEKSContext {
$set: Function,
t: Function,
config: EKSConfig,
nodeGroups: EKSNodeGroup[],
Expand Down Expand Up @@ -38,7 +38,7 @@ const nodeGroupNamesUnique = (ctx: CruEKSContext) => {
const name = group.nodegroupName;

if (names.filter((n) => n === name).length > 1) {
ctx.$set(group, '__nameUnique', false);
set(group, '__nameUnique', false);
if (!out) {
out = ctx.t('eks.errors.nodeGroups.nameUnique');
}
Expand Down
7 changes: 5 additions & 2 deletions shell/edit/constraints.gatekeeper.sh.constraint/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import merge from 'lodash/merge';
import { ucFirst } from '@shell/utils/string';
import { isSimpleKeyValue } from '@shell/utils/object';
import { isSimpleKeyValue, set } from '@shell/utils/object';
import { _CREATE, _VIEW } from '@shell/config/query-params';
import { SCHEMA, NAMESPACE } from '@shell/config/types';
import CreateEditView from '@shell/mixins/create-edit-view';
Expand Down Expand Up @@ -222,6 +222,9 @@ export default {
this.value.spec.match.namespaces = [];
this.value.spec.match.excludedNamespaces = [];
}
},
setParameters(e) {
return set(this.value.spec, 'parameters', e);
}
}
};
Expand Down Expand Up @@ -356,7 +359,7 @@ export default {
v-model:value="parametersYaml"
class="yaml-editor"
:editor-mode="editorMode"
@newObject="$set(value.spec, 'parameters', $event)"
@newObject="setParameters"
/>
</Tab>
</Tabbed>
Expand Down

0 comments on commit 4dcbc1d

Please sign in to comment.