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

HARVESTER: only change priority by select component #9266

Merged
merged 3 commits into from
Jul 6, 2023
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
4 changes: 2 additions & 2 deletions shell/components/form/NodeAffinity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default {
},

priorityDisplay(term) {
return term.weight ? this.t('workload.scheduling.affinity.preferred') : this.t('workload.scheduling.affinity.required');
return 'weight' in term ? this.t('workload.scheduling.affinity.preferred') : this.t('workload.scheduling.affinity.required');
},

updateExpressions(row, expressions) {
Expand Down Expand Up @@ -212,7 +212,7 @@ export default {
/>
</div>
<div
v-if="props.row.value.weight"
v-if="'weight' in props.row.value"
class="col span-3"
>
<LabeledInput
Expand Down
4 changes: 2 additions & 2 deletions shell/components/form/PodAffinity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export default {
},

priorityDisplay(term) {
return term.weight ? this.t('workload.scheduling.affinity.preferred') : this.t('workload.scheduling.affinity.required');
return 'weight' in term ? this.t('workload.scheduling.affinity.preferred') : this.t('workload.scheduling.affinity.required');
},

changeNamespaceMode(val, term, idx) {
Expand Down Expand Up @@ -468,7 +468,7 @@ export default {
/>
</div>
<div
v-if="props.row.value.weight"
v-if="'weight' in props.row.value"
class="col span-3"
>
<LabeledInput
Expand Down
38 changes: 38 additions & 0 deletions shell/components/form/__tests__/NodeAffinity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { mount } from '@vue/test-utils';
import NodeAffinity from '@shell/components/form/NodeAffinity.vue';
import { _CREATE } from '@shell/config/query-params';

describe('component: NodeAffinity', () => {
it('should display the weight input when the priority is preferred', () => {
const nodeAffinity = {
preferredDuringSchedulingIgnoredDuringExecution: [{
preference: { matchExpressions: [] },
weight: 1
}],
requiredDuringSchedulingIgnoredDuringExecution: { nodeSelectorTerms: [{ matchExpressions: [] }] }
};
const wrapper = mount(NodeAffinity, { propsData: { mode: _CREATE, value: nodeAffinity } });

expect(wrapper.find('[data-testid="node-affinity-weight-index0"]').exists()).toBeTruthy();
expect(wrapper.find('[data-testid="node-affinity-weight-index1"]').exists()).toBeFalsy();
});

it('should display the weight input when the value is cleared', async() => {
const nodeAffinity = {
preferredDuringSchedulingIgnoredDuringExecution: [{
preference: { matchExpressions: [] },
weight: 1
}],
};

const wrapper = mount(NodeAffinity, { propsData: { mode: _CREATE, value: nodeAffinity } });

const weightInput = wrapper.find('[data-testid="node-affinity-weight-index0"]');

weightInput.setValue('');

await wrapper.vm.$nextTick();

expect(wrapper.find('[data-testid="node-affinity-weight-index0"]').exists()).toBeTruthy();
});
});
46 changes: 46 additions & 0 deletions shell/components/form/__tests__/PodAffinity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { mount } from '@vue/test-utils';
import PodAffinity from '@shell/components/form/PodAffinity.vue';
import { _CREATE } from '@shell/config/query-params';

describe('component: PodAffinity', () => {
it('should display the weight input when the priority is preferred', () => {
const podAffinity = {
preferredDuringSchedulingIgnoredDuringExecution: [{
podAffinityTerm: { topologyKey: 'test topology key 1' },
weight: 1
}],
requiredDuringSchedulingIgnoredDuringExecution: [{ topologyKey: 'test topology key 2' }]
};
const wrapper = mount(PodAffinity, {
propsData: {
mode: _CREATE, field: 'overrideAffinity', value: { overrideAffinity: { podAffinity } }
}
});

expect(wrapper.find('[data-testid="pod-affinity-weight-index0"]').exists()).toBeTruthy();
expect(wrapper.find('[data-testid="pod-affinity-weight-index1"]').exists()).toBeFalsy();
});

it('should display the weight input when the value is cleared', async() => {
const podAffinity = {
preferredDuringSchedulingIgnoredDuringExecution: [{
podAffinityTerm: { topologyKey: 'test topology key 1' },
weight: 1
}],
};

const wrapper = mount(PodAffinity, {
propsData: {
mode: _CREATE, field: 'overrideAffinity', value: { overrideAffinity: { podAffinity } }
}
});

const weightInput = wrapper.find('[data-testid="pod-affinity-weight-index0"]');

weightInput.setValue('');

await wrapper.vm.$nextTick();

expect(wrapper.find('[data-testid="pod-affinity-weight-index0"]').exists()).toBeTruthy();
});
});