Skip to content

Commit a6fcfbc

Browse files
authored
feat(charts/kube-ovn-v2): enable custom node affinity on deployments (#6025)
* feat(charts/kube-ovn-v2): enable custom node affinity on deployments Signed-off-by: ctallquist <caleb.tallquist@pelo.tech> * remove unused tmpl functions Signed-off-by: ctallquist <caleb.tallquist@pelo.tech> * improve spacing and documentation on node affinity Signed-off-by: ctallquist <caleb.tallquist@pelo.tech> * document the match expressions in the values yaml Signed-off-by: ctallquist <caleb.tallquist@pelo.tech> * fix usage example in values file Signed-off-by: ctallquist <caleb.tallquist@pelo.tech> * clarify the entries in the match expression lists Signed-off-by: ctallquist <caleb.tallquist@pelo.tech> * remove conditional statements from monitor-deployment Signed-off-by: ctallquist <caleb.tallquist@pelo.tech> * add examples of what a match expression should look like Signed-off-by: ctallquist <caleb.tallquist@pelo.tech> --------- Signed-off-by: ctallquist <caleb.tallquist@pelo.tech>
1 parent 5262026 commit a6fcfbc

File tree

6 files changed

+135
-9
lines changed

6 files changed

+135
-9
lines changed

charts/kube-ovn-v2/templates/_helpers.tpl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,36 @@ Get IPs of master nodes from values
151151
65534
152152
{{- end -}}
153153
{{- end -}}
154+
155+
{{/*
156+
Merge hardcoded node affinity expressions with user-provided values.
157+
Usage: include "kube-ovn.affinities.nodeAffinity" (dict "hardcodedPreferred" $hardcodedPreferred "hardcodedRequired" $hardcodedRequired "userPreferred" .Values.component.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution "userRequired" .Values.component.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution)
158+
*/}}
159+
{{- define "kube-ovn.affinities.nodeAffinity" -}}
160+
{{- $hardcodedPreferred := .hardcodedPreferred | default list -}}
161+
{{- $hardcodedRequired := .hardcodedRequired | default list -}}
162+
{{- $userPreferred := .userPreferred | default list -}}
163+
{{- $userRequired := .userRequired | default list -}}
164+
{{- $mergedPreferred := concat $hardcodedPreferred $userPreferred -}}
165+
{{- $mergedRequired := concat $hardcodedRequired $userRequired -}}
166+
{{- if or $mergedPreferred $mergedRequired -}}
167+
nodeAffinity:
168+
{{- if $mergedPreferred }}
169+
preferredDuringSchedulingIgnoredDuringExecution:
170+
{{- range $mergedPreferred }}
171+
- preference:
172+
matchExpressions:
173+
{{- toYaml .matchExpressions | nindent 10 }}
174+
weight: {{ .weight | default 100 }}
175+
{{- end }}
176+
{{- end }}
177+
{{- if $mergedRequired }}
178+
requiredDuringSchedulingIgnoredDuringExecution:
179+
nodeSelectorTerms:
180+
{{- range $mergedRequired }}
181+
- matchExpressions:
182+
{{- toYaml .matchExpressions | nindent 8 }}
183+
{{- end }}
184+
{{- end }}
185+
{{- end -}}
186+
{{- end -}}

charts/kube-ovn-v2/templates/central/central-deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ spec:
4747
- key: CriticalAddonsOnly
4848
operator: Exists
4949
affinity:
50+
{{- include "kube-ovn.affinities.nodeAffinity" (dict "userPreferred" .Values.central.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution "userRequired" .Values.central.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution) | nindent 8 }}
5051
podAntiAffinity:
5152
requiredDuringSchedulingIgnoredDuringExecution:
5253
- labelSelector:

charts/kube-ovn-v2/templates/controller/controller-deployment.yaml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,8 @@ spec:
4545
- key: CriticalAddonsOnly
4646
operator: Exists
4747
affinity:
48-
nodeAffinity:
49-
preferredDuringSchedulingIgnoredDuringExecution:
50-
- preference:
51-
matchExpressions:
52-
- key: "ovn.kubernetes.io/ic-gw"
53-
operator: NotIn
54-
values:
55-
- "true"
56-
weight: 100
48+
{{- $hardcodedPreferred := list (dict "matchExpressions" (list (dict "key" "ovn.kubernetes.io/ic-gw" "operator" "NotIn" "values" (list "true"))) "weight" 100) -}}
49+
{{- include "kube-ovn.affinities.nodeAffinity" (dict "hardcodedPreferred" $hardcodedPreferred "userPreferred" .Values.controller.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution "userRequired" .Values.controller.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution) | nindent 8 }}
5750
podAntiAffinity:
5851
requiredDuringSchedulingIgnoredDuringExecution:
5952
- labelSelector:

charts/kube-ovn-v2/templates/ic/ic-controller-deploy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ spec:
3232
- key: CriticalAddonsOnly
3333
operator: Exists
3434
affinity:
35+
{{- include "kube-ovn.affinities.nodeAffinity" (dict "userPreferred" .Values.ic.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution "userRequired" .Values.ic.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution) | nindent 8 }}
3536
podAntiAffinity:
3637
requiredDuringSchedulingIgnoredDuringExecution:
3738
- labelSelector:

charts/kube-ovn-v2/templates/monitor/monitor-deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ spec:
4545
- key: CriticalAddonsOnly
4646
operator: Exists
4747
affinity:
48+
{{- include "kube-ovn.affinities.nodeAffinity" (dict "userPreferred" .Values.monitor.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution "userRequired" .Values.monitor.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution) -}}
4849
podAntiAffinity:
4950
requiredDuringSchedulingIgnoredDuringExecution:
5051
- labelSelector:

charts/kube-ovn-v2/values.yaml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,29 @@ monitor:
574574
cpu: "200m"
575575
memory: "200Mi"
576576

577+
# -- Node affinity configuration for kube-ovn-monitor.
578+
# -- More information on formatting nodeAffinity can be found at https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity
579+
# @section -- OVN monitoring daemon configuration
580+
nodeAffinity:
581+
# -- User-preferred node affinity matchExpressions. Each entry should be a series of match expressions to be AND'd together, and all entries will be OR'd together
582+
# -- Each entry should look like the following:
583+
# -- matchExpressions:
584+
# -- - key: topology.kubernetes.io/zone
585+
# -- operator: In
586+
# -- values:
587+
# -- - antarctica-east1
588+
# -- - antarctica-west1
589+
preferredDuringSchedulingIgnoredDuringExecution: []
590+
# -- User-required node affinity matchExpressions. Each entry should be a series of match expressions to be AND'd together, and all entries will be OR'd together
591+
# -- Each entry should look like the following:
592+
# -- matchExpressions:
593+
# -- - key: topology.kubernetes.io/zone
594+
# -- operator: In
595+
# -- values:
596+
# -- - antarctica-east1
597+
# -- - antarctica-west1
598+
requiredDuringSchedulingIgnoredDuringExecution: []
599+
577600
# -- kube-ovn-monitor metrics configuration.
578601
# @section -- OVN monitoring daemon configuration
579602
# @default -- "{}"
@@ -610,6 +633,29 @@ controller:
610633
cpu: "1000m"
611634
memory: "1Gi"
612635

636+
# -- Node affinity configuration for kube-ovn-controller.
637+
# -- More information on formatting nodeAffinity can be found at https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity
638+
# @section -- Kube-OVN controller configuration
639+
nodeAffinity:
640+
# -- User-preferred node affinity matchExpressions. Each entry should be a series of match expressions to be AND'd together, and all entries will be OR'd together
641+
# -- Each entry should look like the following:
642+
# -- matchExpressions:
643+
# -- - key: topology.kubernetes.io/zone
644+
# -- operator: In
645+
# -- values:
646+
# -- - antarctica-east1
647+
# -- - antarctica-west1
648+
preferredDuringSchedulingIgnoredDuringExecution: []
649+
# -- User-required node affinity matchExpressions. Each entry should be a series of match expressions to be AND'd together, and all entries will be OR'd together
650+
# -- Each entry should look like the following:
651+
# -- matchExpressions:
652+
# -- - key: topology.kubernetes.io/zone
653+
# -- operator: In
654+
# -- values:
655+
# -- - antarctica-east1
656+
# -- - antarctica-west1
657+
requiredDuringSchedulingIgnoredDuringExecution: []
658+
613659
# -- Controller metrics configuration.
614660
# @section -- Kube-OVN controller configuration
615661
# @default -- "{}"
@@ -646,6 +692,29 @@ central:
646692
cpu: "3"
647693
memory: "4Gi"
648694

695+
# -- Node affinity configuration for ovn-central.
696+
# -- More information on formatting nodeAffinity can be found at https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity
697+
# @section -- OVN-central daemon configuration
698+
nodeAffinity:
699+
# -- User-preferred node affinity matchExpressions. Each entry should be a series of match expressions to be AND'd together, and all entries will be OR'd together
700+
# -- Each entry should look like the following:
701+
# -- matchExpressions:
702+
# -- - key: topology.kubernetes.io/zone
703+
# -- operator: In
704+
# -- values:
705+
# -- - antarctica-east1
706+
# -- - antarctica-west1
707+
preferredDuringSchedulingIgnoredDuringExecution: []
708+
# -- User-required node affinity matchExpressions. Each entry should be a series of match expressions to be AND'd together, and all entries will be OR'd together
709+
# -- Each entry should look like the following:
710+
# -- matchExpressions:
711+
# -- - key: topology.kubernetes.io/zone
712+
# -- operator: In
713+
# -- values:
714+
# -- - antarctica-east1
715+
# -- - antarctica-west1
716+
requiredDuringSchedulingIgnoredDuringExecution: []
717+
649718
# -- ""
650719
# @section -- OVN-central daemon configuration.
651720
ovnNorthdProbeInterval: 5000
@@ -656,6 +725,34 @@ central:
656725
# @section -- OVN-central daemon configuration.
657726
ovnLeaderProbeInterval: 5
658727

728+
729+
# -- Configuration for the OVN interconnection (IC) controller.
730+
# @section -- OVN IC controller configuration
731+
# @default -- "{}"
732+
ic:
733+
# -- Node affinity configuration for the OVN IC controller.
734+
# -- More information on formatting nodeAffinity can be found at https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity
735+
# @section -- OVN IC controller configuration
736+
nodeAffinity:
737+
# -- User-preferred node affinity matchExpressions. Each entry should be a series of match expressions to be AND'd together, and all entries will be OR'd together
738+
# -- Each entry should look like the following:
739+
# -- matchExpressions:
740+
# -- - key: topology.kubernetes.io/zone
741+
# -- operator: In
742+
# -- values:
743+
# -- - antarctica-east1
744+
# -- - antarctica-west1
745+
preferredDuringSchedulingIgnoredDuringExecution: []
746+
# -- User-required node affinity matchExpressions. Each entry should be a series of match expressions to be AND'd together, and all entries will be OR'd together
747+
# -- Each entry should look like the following:
748+
# -- matchExpressions:
749+
# -- - key: topology.kubernetes.io/zone
750+
# -- operator: In
751+
# -- values:
752+
# -- - antarctica-east1
753+
# -- - antarctica-west1
754+
requiredDuringSchedulingIgnoredDuringExecution: []
755+
659756
# -- Configuration for kube-ovn-cni, the agent responsible for handling CNI requests from the CRI.
660757
# @section -- CNI agent configuration
661758
# @default -- "{}"

0 commit comments

Comments
 (0)