Skip to content

Commit fc54897

Browse files
author
Daman Arora
committed
add affinity group support Kubernetes cluster creation
1 parent d62b9f3 commit fc54897

File tree

3 files changed

+97
-3
lines changed

3 files changed

+97
-3
lines changed

ui/public/locales/en.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@
555555
"label.cks.cluster.size": "Cluster size (Worker nodes)",
556556
"label.cks.cluster.worker.nodes.offeringid": "Service Offering for Worker Nodes",
557557
"label.cks.cluster.worker.nodes.templateid": "Template for Worker Nodes",
558+
"label.cks.cluster.control.nodes.affinitygroupid": "Affinity Groups for Control Nodes",
559+
"label.cks.cluster.worker.nodes.affinitygroupid": "Affinity Groups for Worker Nodes",
560+
"label.cks.cluster.etcd.nodes.affinitygroupid": "Affinity Groups for ETCD Nodes",
558561
"label.cleanup": "Clean up",
559562
"label.clear": "Clear",
560563
"label.clear.all": "Clear all",
@@ -2883,6 +2886,9 @@
28832886
"label.edgecluster": "Edge Cluster",
28842887
"label.encryption": "Encryption",
28852888
"label.etcdnodes": "Number of etcd nodes",
2889+
"label.controlaffinitygroupnames": "Control Affinity Groups",
2890+
"label.workeraffinitygroupnames": "Worker Affinity Groups",
2891+
"label.etcdaffinitygroupnames": "ETCD Affinity Groups",
28862892
"label.versioning": "Versioning",
28872893
"label.objectlocking": "Object Lock",
28882894
"label.bucket.policy": "Bucket Policy",

ui/src/config/section/compute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ export default {
574574
const filters = ['cloud.managed', 'external.managed']
575575
return filters
576576
},
577-
details: ['name', 'description', 'zonename', 'kubernetesversionname', 'autoscalingenabled', 'csienabled', 'minsize', 'maxsize', 'size', 'controlnodes', 'etcdnodes', 'cpunumber', 'memory', 'keypair', 'cniconfigname', 'associatednetworkname', 'account', 'domain', 'zonename', 'clustertype', 'created'],
577+
details: ['name', 'description', 'zonename', 'kubernetesversionname', 'autoscalingenabled', 'csienabled', 'minsize', 'maxsize', 'size', 'controlnodes', 'controlaffinitygroupnames', 'etcdnodes', 'etcdaffinitygroupnames', 'workeraffinitygroupnames', 'cpunumber', 'memory', 'keypair', 'cniconfigname', 'associatednetworkname', 'account', 'domain', 'zonename', 'clustertype', 'created'],
578578
tabs: [
579579
{
580580
name: 'k8s',

ui/src/views/compute/CreateKubernetesCluster.vue

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@
316316
</a-select-option>
317317
</a-select>
318318
</a-form-item>
319-
<a-form-item v-if="form.advancedmode && form?.etcdnodes > 0" name="etcdtemplateid" ref="etcdtemplateid">
319+
<a-form-item v-if="form.advancedmode && form.etcdnodes && form.etcdnodes > 0" name="etcdtemplateid" ref="etcdtemplateid">
320320
<template #label>
321321
<tooltip-label :title="$t('label.cks.cluster.etcd.nodes.templateid')" :tooltip="$t('label.cks.cluster.etcd.nodes.templateid')"/>
322322
</template>
@@ -335,6 +335,57 @@
335335
</a-select-option>
336336
</a-select>
337337
</a-form-item>
338+
<a-form-item v-if="form.advancedmode" name="controlaffinitygroupids" ref="controlaffinitygroupids">
339+
<template #label>
340+
<tooltip-label :title="$t('label.cks.cluster.control.nodes.affinitygroupid')" :tooltip="$t('label.cks.cluster.control.nodes.affinitygroupid')"/>
341+
</template>
342+
<a-select
343+
v-model:value="controlAffinityGroups"
344+
mode="multiple"
345+
showSearch
346+
optionFilterProp="label"
347+
:filterOption="(input, option) => option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0"
348+
:loading="affinityGroupLoading"
349+
:placeholder="$t('label.cks.cluster.control.nodes.affinitygroupid')">
350+
<a-select-option v-for="opt in affinityGroups" :key="opt.id" :label="opt.name">
351+
{{ opt.name }}
352+
</a-select-option>
353+
</a-select>
354+
</a-form-item>
355+
<a-form-item v-if="form.advancedmode" name="workeraffinitygroupids" ref="workeraffinitygroupids">
356+
<template #label>
357+
<tooltip-label :title="$t('label.cks.cluster.worker.nodes.affinitygroupid')" :tooltip="$t('label.cks.cluster.worker.nodes.affinitygroupid')"/>
358+
</template>
359+
<a-select
360+
v-model:value="workerAffinityGroups"
361+
mode="multiple"
362+
showSearch
363+
optionFilterProp="label"
364+
:filterOption="(input, option) => option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0"
365+
:loading="affinityGroupLoading"
366+
:placeholder="$t('label.cks.cluster.worker.nodes.affinitygroupid')">
367+
<a-select-option v-for="opt in affinityGroups" :key="opt.id" :label="opt.name">
368+
{{ opt.name }}
369+
</a-select-option>
370+
</a-select>
371+
</a-form-item>
372+
<a-form-item v-if="form.advancedmode && form.etcdnodes && form.etcdnodes > 0" name="etcdaffinitygroupids" ref="etcdaffinitygroupids">
373+
<template #label>
374+
<tooltip-label :title="$t('label.cks.cluster.etcd.nodes.affinitygroupid')" :tooltip="$t('label.cks.cluster.etcd.nodes.affinitygroupid')"/>
375+
</template>
376+
<a-select
377+
v-model:value="etcdAffinityGroups"
378+
mode="multiple"
379+
showSearch
380+
optionFilterProp="label"
381+
:filterOption="(input, option) => option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0"
382+
:loading="affinityGroupLoading"
383+
:placeholder="$t('label.cks.cluster.etcd.nodes.affinitygroupid')">
384+
<a-select-option v-for="opt in affinityGroups" :key="opt.id" :label="opt.name">
385+
{{ opt.name }}
386+
</a-select-option>
387+
</a-select>
388+
</a-form-item>
338389
<a-form-item v-if="form.advancedmode && isASNumberRequired() && !form.networkid" name="asnumber" ref="asnumber">
339390
<template #label>
340391
<tooltip-label :title="$t('label.asnumber')" :tooltip="apiParams.asnumber.description"/>
@@ -490,7 +541,12 @@ export default {
490541
cksNetworkOffering: null,
491542
asNumbersZone: [],
492543
asNumberLoading: false,
493-
selectedAsNumber: 0
544+
selectedAsNumber: 0,
545+
affinityGroups: [],
546+
affinityGroupLoading: false,
547+
controlAffinityGroups: [],
548+
workerAffinityGroups: [],
549+
etcdAffinityGroups: []
494550
}
495551
},
496552
beforeCreate () {
@@ -560,6 +616,22 @@ export default {
560616
this.fetchCKSNetworkOfferingName()
561617
this.fetchCniConfigurations()
562618
},
619+
fetchAffinityGroups () {
620+
this.affinityGroups = []
621+
const params = {}
622+
if (!this.isObjectEmpty(this.selectedZone)) {
623+
params.zoneid = this.selectedZone.id
624+
}
625+
this.affinityGroupLoading = true
626+
getAPI('listAffinityGroups', params).then(json => {
627+
const groups = json.listaffinitygroupsresponse.affinitygroup
628+
if (this.arrayHasItems(groups)) {
629+
this.affinityGroups = groups
630+
}
631+
}).finally(() => {
632+
this.affinityGroupLoading = false
633+
})
634+
},
563635
isValidValueForKey (obj, key) {
564636
return key in obj && obj[key] != null
565637
},
@@ -600,6 +672,7 @@ export default {
600672
this.fetchNetworkData()
601673
this.fetchZoneHypervisors()
602674
this.fetchZoneASNumbers()
675+
this.fetchAffinityGroups()
603676
},
604677
handleASNumberChange (selectedIndex) {
605678
this.selectedAsNumber = this.asNumbersZone[selectedIndex].asnumber
@@ -881,6 +954,21 @@ export default {
881954
advancedTemplates++
882955
}
883956
}
957+
if (values.advancedmode) {
958+
let affinityIndex = 0
959+
const addAffinityGroups = (nodeType, groups) => {
960+
if (groups && groups.length > 0) {
961+
params[`nodeaffinitygroups[${affinityIndex}].node`] = nodeType
962+
params[`nodeaffinitygroups[${affinityIndex}].affinitygroup`] = groups.join(',')
963+
affinityIndex++
964+
}
965+
}
966+
addAffinityGroups('control', this.controlAffinityGroups)
967+
addAffinityGroups('worker', this.workerAffinityGroups)
968+
if (values.etcdnodes > 0) {
969+
addAffinityGroups('etcd', this.etcdAffinityGroups)
970+
}
971+
}
884972
if (this.isValidValueForKey(values, 'noderootdisksize') && values.noderootdisksize > 0) {
885973
params.noderootdisksize = values.noderootdisksize
886974
}

0 commit comments

Comments
 (0)