Skip to content

Commit 1877e53

Browse files
committed
fix: 解决配置节点亲和性无法保存的问题
1 parent e3c6db1 commit 1877e53

File tree

1 file changed

+50
-52
lines changed

1 file changed

+50
-52
lines changed

web/dashboard/src/components/ko-workloads/ko-spec/ko-pod-scheduling.vue

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
</el-col>
2020
</el-row>
2121
<el-row :gutter="20">
22-
<el-col :span="12">
23-
<el-form-item label="Namespace">
24-
<ko-form-item itemType="select2" v-model="item.namespaces" multiple :selections="namespace_list" />
25-
</el-form-item>
26-
</el-col>
2722
<el-col :span="12" v-if="item.priority === 'Preferred'">
2823
<el-form-item :label="$t('business.workload.weight')">
2924
<ko-form-item itemType="number" v-model="item.weight" />
@@ -151,7 +146,6 @@ export default {
151146
var item = {
152147
type: "Affinity",
153148
priority: "Preferred",
154-
namespaces: "",
155149
weight: 1,
156150
rules: [],
157151
labelRules: [],
@@ -208,7 +202,6 @@ export default {
208202
},
209203
210204
valueTrans(type, priority, s) {
211-
let namespaces = s.namespaces || ""
212205
let rules = []
213206
if (s.labelSelector.matchExpressions) {
214207
for (const express of s.labelSelector.matchExpressions) {
@@ -231,7 +224,6 @@ export default {
231224
type: type,
232225
priority: priority,
233226
weight: s.weight || null,
234-
namespaces: namespaces || "",
235227
rules: rules,
236228
labelRules: labelRules,
237229
topologyKey: topologyKey,
@@ -263,8 +255,7 @@ export default {
263255
if (this.podSchedulings.length !== 0) {
264256
for (const pS of this.podSchedulings) {
265257
let itemAdd = {}
266-
itemAdd.namespaces = (pS.namespaces && pS.namespaces.length !== 0) ? pS.namespaces : undefined
267-
itemAdd.topologyKey = pS.topologyKey || undefined
258+
const itemTopologyKey = pS.topologyKey || undefined
268259
const matchs = this.getMatchExpress(pS.rules)
269260
const labelMatchs = this.getMatchLabels(pS.labelRules)
270261
switch (pS.type + "+" + pS.priority) {
@@ -274,15 +265,16 @@ export default {
274265
}
275266
parentFrom.affinity.podAffinity.requiredDuringSchedulingIgnoredDuringExecution = []
276267
itemAdd.labelSelector = { matchExpressions: matchs, matchLabels: labelMatchs }
268+
itemAdd.topologyKey = itemTopologyKey
277269
parentFrom.affinity.podAffinity.requiredDuringSchedulingIgnoredDuringExecution.push(itemAdd)
278270
break
279271
case "Affinity+Preferred":
280272
if (!parentFrom.affinity.podAffinity) {
281273
parentFrom.affinity.podAffinity = {}
282274
}
283275
parentFrom.affinity.podAffinity.preferredDuringSchedulingIgnoredDuringExecution = []
284-
itemAdd.podAffinityTerm = { labelSelector: { matchExpressions: matchs, matchLabels: labelMatchs } }
285-
itemAdd.weight = pS.weight
276+
itemAdd.podAffinityTerm = { topologyKey: itemTopologyKey, labelSelector: { matchExpressions: matchs, matchLabels: labelMatchs } }
277+
itemAdd.weight = pS.weight || 1
286278
parentFrom.affinity.podAffinity.preferredDuringSchedulingIgnoredDuringExecution.push(itemAdd)
287279
break
288280
case "Anti-Affinity+Required":
@@ -291,41 +283,47 @@ export default {
291283
}
292284
parentFrom.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution = []
293285
itemAdd.labelSelector = { matchExpressions: matchs, matchLabels: labelMatchs }
286+
itemAdd.topologyKey = itemTopologyKey
294287
parentFrom.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution.push(itemAdd)
295288
break
296289
case "Anti-Affinity+Preferred":
297290
if (!parentFrom.affinity.podAntiAffinity) {
298291
parentFrom.affinity.podAntiAffinity = {}
299292
}
300293
parentFrom.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution = []
301-
itemAdd.podAffinityTerm = { labelSelector: { matchExpressions: matchs, matchLabels: labelMatchs } }
302-
itemAdd.weight = pS.weight
294+
itemAdd.podAffinityTerm = { topologyKey: itemTopologyKey, labelSelector: { matchExpressions: matchs, matchLabels: labelMatchs } }
295+
itemAdd.weight = pS.weight || 1
303296
parentFrom.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution.push(itemAdd)
304297
break
305298
}
306299
}
307300
}
308-
parentFrom.nodeAffinity = {}
309301
if (this.nodeSchedulings.length !== 0) {
310302
for (const nS of this.nodeSchedulings) {
311303
const matchs = this.getMatchExpress(nS.rules)
312304
const fields = this.getMatchExpress(nS.fields)
313305
let itemAdd = {}
314306
switch (nS.priority) {
315307
case "Preferred":
316-
parentFrom.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution = []
308+
if (!parentFrom.affinity.nodeAffinity) {
309+
parentFrom.affinity.nodeAffinity = {}
310+
}
311+
parentFrom.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution = []
317312
itemAdd.weight = nS.weight
318313
itemAdd.preference = { matchExpressions: matchs, matchFields: fields }
319-
parentFrom.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution.push(itemAdd)
314+
parentFrom.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution.push(itemAdd)
320315
break
321316
case "Required":
322-
if (!parentFrom.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution) {
323-
parentFrom.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution = {}
317+
if (!parentFrom.affinity.nodeAffinity) {
318+
parentFrom.affinity.nodeAffinity = {}
324319
}
325-
parentFrom.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms = []
320+
if (!parentFrom.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution) {
321+
parentFrom.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution = {}
322+
}
323+
parentFrom.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms = []
326324
itemAdd.matchExpressions = matchs
327325
itemAdd.matchFields = fields
328-
parentFrom.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms.push(itemAdd)
326+
parentFrom.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms.push(itemAdd)
329327
break
330328
}
331329
}
@@ -369,47 +367,47 @@ export default {
369367
}
370368
}
371369
}
372-
}
373370
374-
if (this.podSchedulingParentObj.nodeAffinity) {
375-
if (this.podSchedulingParentObj.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution) {
376-
if (this.podSchedulingParentObj.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms) {
377-
const schedulings = this.podSchedulingParentObj.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms
378-
for (const s of schedulings) {
379-
let rules = []
380-
if (s.matchExpressions) {
381-
for (const express of s.matchExpressions) {
382-
rules.push({ key: express.key, operator: express.operator, value: express.values.join(",") })
371+
if (this.podSchedulingParentObj.affinity.nodeAffinity) {
372+
if (this.podSchedulingParentObj.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution) {
373+
if (this.podSchedulingParentObj.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms) {
374+
const schedulings = this.podSchedulingParentObj.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms
375+
for (const s of schedulings) {
376+
let rules = []
377+
if (s.matchExpressions) {
378+
for (const express of s.matchExpressions) {
379+
rules.push({ key: express.key, operator: express.operator, value: express.values.join(",") })
380+
}
383381
}
384-
}
385-
let fields = []
386-
if (s.matchFields) {
387-
for (const express of s.matchFields) {
388-
fields.push({ key: express.key, operator: express.operator, value: express.values.join(",") })
382+
let fields = []
383+
if (s.matchFields) {
384+
for (const express of s.matchFields) {
385+
fields.push({ key: express.key, operator: express.operator, value: express.values.join(",") })
386+
}
389387
}
388+
this.nodeSchedulings.push({ priority: "Required", rules: rules, fields: fields })
390389
}
391-
this.nodeSchedulings.push({ priority: "Required", rules: rules, fields: fields })
392390
}
393391
}
394-
}
395-
if (this.podSchedulingParentObj.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution) {
396-
const schedulings = this.podSchedulingParentObj.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution
397-
for (const s of schedulings) {
398-
let rules = []
399-
let fields = []
400-
if (s.preference) {
401-
if (s.preference.matchExpressions) {
402-
for (const express of s.preference.matchExpressions) {
403-
rules.push({ key: express.key, operator: express.operator, value: express.values.join(",") })
392+
if (this.podSchedulingParentObj.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution) {
393+
const schedulings = this.podSchedulingParentObj.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution
394+
for (const s of schedulings) {
395+
let rules = []
396+
let fields = []
397+
if (s.preference) {
398+
if (s.preference.matchExpressions) {
399+
for (const express of s.preference.matchExpressions) {
400+
rules.push({ key: express.key, operator: express.operator, value: express.values.join(",") })
401+
}
404402
}
405-
}
406-
if (s.preference.matchFields) {
407-
for (const express of s.preference.matchFields) {
408-
fields.push({ key: express.key, operator: express.operator, value: express.values.join(",") })
403+
if (s.preference.matchFields) {
404+
for (const express of s.preference.matchFields) {
405+
fields.push({ key: express.key, operator: express.operator, value: express.values.join(",") })
406+
}
409407
}
410408
}
409+
this.nodeSchedulings.push({ priority: "Preferred", rules: rules, fields: fields, weight: s.weight || null })
411410
}
412-
this.nodeSchedulings.push({ priority: "Preferred", rules: rules, fields: fields, weight: s.weight || null })
413411
}
414412
}
415413
}

0 commit comments

Comments
 (0)