Chart: Make pod affinity templatable. (#11453)
* [helm] template pod affinity * update README * Apply suggestions from code review Co-authored-by: Marco Ebert <marco_ebert@icloud.com> * revert Chart.yaml version bump * add unittests * add docs defaultBackend.affinity * add README section to values * fix README syntax * Apply suggestions from code review Co-authored-by: Marco Ebert <marco_ebert@icloud.com> * Update charts/ingress-nginx/values.yaml Co-authored-by: Marco Ebert <marco_ebert@icloud.com> * update formatting of unittests + add README examples * fix affinity labels on default-backend * Apply suggestions from code review Co-authored-by: Marco Ebert <marco_ebert@icloud.com> * remove double quotes on string --------- Co-authored-by: Marco Ebert <marco_ebert@icloud.com>
This commit is contained in:
parent
8ca27e7ee9
commit
af9e5246ad
8 changed files with 179 additions and 9 deletions
|
@ -485,7 +485,7 @@ As of version `1.26.0` of this chart, by simply not providing any clusterIP valu
|
||||||
| controller.udp.configMapNamespace | string | `""` | Allows customization of the udp-services-configmap; defaults to $(POD_NAMESPACE) |
|
| controller.udp.configMapNamespace | string | `""` | Allows customization of the udp-services-configmap; defaults to $(POD_NAMESPACE) |
|
||||||
| controller.updateStrategy | object | `{}` | The update strategy to apply to the Deployment or DaemonSet # |
|
| controller.updateStrategy | object | `{}` | The update strategy to apply to the Deployment or DaemonSet # |
|
||||||
| controller.watchIngressWithoutClass | bool | `false` | Process Ingress objects without ingressClass annotation/ingressClassName field Overrides value for --watch-ingress-without-class flag of the controller binary Defaults to false |
|
| controller.watchIngressWithoutClass | bool | `false` | Process Ingress objects without ingressClass annotation/ingressClassName field Overrides value for --watch-ingress-without-class flag of the controller binary Defaults to false |
|
||||||
| defaultBackend.affinity | object | `{}` | |
|
| defaultBackend.affinity | object | `{}` | Affinity and anti-affinity rules for server scheduling to nodes # Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity |
|
||||||
| defaultBackend.autoscaling.annotations | object | `{}` | |
|
| defaultBackend.autoscaling.annotations | object | `{}` | |
|
||||||
| defaultBackend.autoscaling.enabled | bool | `false` | |
|
| defaultBackend.autoscaling.enabled | bool | `false` | |
|
||||||
| defaultBackend.autoscaling.maxReplicas | int | `2` | |
|
| defaultBackend.autoscaling.maxReplicas | int | `2` | |
|
||||||
|
|
|
@ -203,7 +203,7 @@ spec:
|
||||||
tolerations: {{ toYaml .Values.controller.tolerations | nindent 8 }}
|
tolerations: {{ toYaml .Values.controller.tolerations | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .Values.controller.affinity }}
|
{{- if .Values.controller.affinity }}
|
||||||
affinity: {{ toYaml .Values.controller.affinity | nindent 8 }}
|
affinity: {{ tpl (toYaml .Values.controller.affinity) $ | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .Values.controller.topologySpreadConstraints }}
|
{{- if .Values.controller.topologySpreadConstraints }}
|
||||||
topologySpreadConstraints: {{ tpl (toYaml .Values.controller.topologySpreadConstraints) $ | nindent 8 }}
|
topologySpreadConstraints: {{ tpl (toYaml .Values.controller.topologySpreadConstraints) $ | nindent 8 }}
|
||||||
|
|
|
@ -206,7 +206,7 @@ spec:
|
||||||
tolerations: {{ toYaml .Values.controller.tolerations | nindent 8 }}
|
tolerations: {{ toYaml .Values.controller.tolerations | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .Values.controller.affinity }}
|
{{- if .Values.controller.affinity }}
|
||||||
affinity: {{ toYaml .Values.controller.affinity | nindent 8 }}
|
affinity: {{ tpl (toYaml .Values.controller.affinity) $ | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .Values.controller.topologySpreadConstraints }}
|
{{- if .Values.controller.topologySpreadConstraints }}
|
||||||
topologySpreadConstraints: {{ tpl (toYaml .Values.controller.topologySpreadConstraints) $ | nindent 8 }}
|
topologySpreadConstraints: {{ tpl (toYaml .Values.controller.topologySpreadConstraints) $ | nindent 8 }}
|
||||||
|
|
|
@ -107,7 +107,7 @@ spec:
|
||||||
tolerations: {{ toYaml .Values.defaultBackend.tolerations | nindent 8 }}
|
tolerations: {{ toYaml .Values.defaultBackend.tolerations | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .Values.defaultBackend.affinity }}
|
{{- if .Values.defaultBackend.affinity }}
|
||||||
affinity: {{ toYaml .Values.defaultBackend.affinity | nindent 8 }}
|
affinity: {{ tpl (toYaml .Values.defaultBackend.affinity) $ | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .Values.defaultBackend.topologySpreadConstraints }}
|
{{- if .Values.defaultBackend.topologySpreadConstraints }}
|
||||||
topologySpreadConstraints: {{ tpl (toYaml .Values.defaultBackend.topologySpreadConstraints) $ | nindent 8 }}
|
topologySpreadConstraints: {{ tpl (toYaml .Values.defaultBackend.topologySpreadConstraints) $ | nindent 8 }}
|
||||||
|
|
|
@ -95,3 +95,46 @@ tests:
|
||||||
topologyKey: kubernetes.io/hostname
|
topologyKey: kubernetes.io/hostname
|
||||||
maxSkew: 1
|
maxSkew: 1
|
||||||
whenUnsatisfiable: ScheduleAnyway
|
whenUnsatisfiable: ScheduleAnyway
|
||||||
|
|
||||||
|
- it: should create a DaemonSet with affinity if `controller.affinity` is set
|
||||||
|
set:
|
||||||
|
controller.kind: DaemonSet
|
||||||
|
controller.affinity:
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app.kubernetes.io/name
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- '{{ include "ingress-nginx.name" . }}'
|
||||||
|
- key: app.kubernetes.io/instance
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- '{{ .Release.Name }}'
|
||||||
|
- key: app.kubernetes.io/component
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- controller
|
||||||
|
topologyKey: kubernetes.io/hostname
|
||||||
|
asserts:
|
||||||
|
- equal:
|
||||||
|
path: spec.template.spec.affinity
|
||||||
|
value:
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app.kubernetes.io/name
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- ingress-nginx
|
||||||
|
- key: app.kubernetes.io/instance
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- RELEASE-NAME
|
||||||
|
- key: app.kubernetes.io/component
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- controller
|
||||||
|
topologyKey: kubernetes.io/hostname
|
||||||
|
|
|
@ -118,3 +118,45 @@ tests:
|
||||||
topologyKey: kubernetes.io/hostname
|
topologyKey: kubernetes.io/hostname
|
||||||
maxSkew: 1
|
maxSkew: 1
|
||||||
whenUnsatisfiable: ScheduleAnyway
|
whenUnsatisfiable: ScheduleAnyway
|
||||||
|
|
||||||
|
- it: should create a Deployment with affinity if `controller.affinity` is set
|
||||||
|
set:
|
||||||
|
controller.affinity:
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app.kubernetes.io/name
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- '{{ include "ingress-nginx.name" . }}'
|
||||||
|
- key: app.kubernetes.io/instance
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- '{{ .Release.Name }}'
|
||||||
|
- key: app.kubernetes.io/component
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- controller
|
||||||
|
topologyKey: kubernetes.io/hostname
|
||||||
|
asserts:
|
||||||
|
- equal:
|
||||||
|
path: spec.template.spec.affinity
|
||||||
|
value:
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app.kubernetes.io/name
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- ingress-nginx
|
||||||
|
- key: app.kubernetes.io/instance
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- RELEASE-NAME
|
||||||
|
- key: app.kubernetes.io/component
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- controller
|
||||||
|
topologyKey: kubernetes.io/hostname
|
||||||
|
|
|
@ -92,3 +92,46 @@ tests:
|
||||||
topologyKey: kubernetes.io/hostname
|
topologyKey: kubernetes.io/hostname
|
||||||
maxSkew: 1
|
maxSkew: 1
|
||||||
whenUnsatisfiable: ScheduleAnyway
|
whenUnsatisfiable: ScheduleAnyway
|
||||||
|
|
||||||
|
- it: should create a Deployment with affinity if `defaultBackend.affinity` is set
|
||||||
|
set:
|
||||||
|
defaultBackend.enabled: true
|
||||||
|
defaultBackend.affinity:
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app.kubernetes.io/name
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- '{{ include "ingress-nginx.name" . }}'
|
||||||
|
- key: app.kubernetes.io/instance
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- '{{ .Release.Name }}'
|
||||||
|
- key: app.kubernetes.io/component
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- default-backend
|
||||||
|
topologyKey: kubernetes.io/hostname
|
||||||
|
asserts:
|
||||||
|
- equal:
|
||||||
|
path: spec.template.spec.affinity
|
||||||
|
value:
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: app.kubernetes.io/name
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- ingress-nginx
|
||||||
|
- key: app.kubernetes.io/instance
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- RELEASE-NAME
|
||||||
|
- key: app.kubernetes.io/component
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- default-backend
|
||||||
|
topologyKey: kubernetes.io/hostname
|
||||||
|
|
|
@ -260,11 +260,11 @@ controller:
|
||||||
# - key: app.kubernetes.io/name
|
# - key: app.kubernetes.io/name
|
||||||
# operator: In
|
# operator: In
|
||||||
# values:
|
# values:
|
||||||
# - ingress-nginx
|
# - '{{ include "ingress-nginx.name" . }}'
|
||||||
# - key: app.kubernetes.io/instance
|
# - key: app.kubernetes.io/instance
|
||||||
# operator: In
|
# operator: In
|
||||||
# values:
|
# values:
|
||||||
# - ingress-nginx
|
# - '{{ .Release.Name }}'
|
||||||
# - key: app.kubernetes.io/component
|
# - key: app.kubernetes.io/component
|
||||||
# operator: In
|
# operator: In
|
||||||
# values:
|
# values:
|
||||||
|
@ -279,16 +279,16 @@ controller:
|
||||||
# - key: app.kubernetes.io/name
|
# - key: app.kubernetes.io/name
|
||||||
# operator: In
|
# operator: In
|
||||||
# values:
|
# values:
|
||||||
# - ingress-nginx
|
# - '{{ include "ingress-nginx.name" . }}'
|
||||||
# - key: app.kubernetes.io/instance
|
# - key: app.kubernetes.io/instance
|
||||||
# operator: In
|
# operator: In
|
||||||
# values:
|
# values:
|
||||||
# - ingress-nginx
|
# - '{{ .Release.Name }}'
|
||||||
# - key: app.kubernetes.io/component
|
# - key: app.kubernetes.io/component
|
||||||
# operator: In
|
# operator: In
|
||||||
# values:
|
# values:
|
||||||
# - controller
|
# - controller
|
||||||
# topologyKey: "kubernetes.io/hostname"
|
# topologyKey: kubernetes.io/hostname
|
||||||
|
|
||||||
# -- Topology spread constraints rely on node labels to identify the topology domain(s) that each Node is in.
|
# -- Topology spread constraints rely on node labels to identify the topology domain(s) that each Node is in.
|
||||||
## Ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/
|
## Ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/
|
||||||
|
@ -1011,7 +1011,49 @@ defaultBackend:
|
||||||
# value: "value"
|
# value: "value"
|
||||||
# effect: "NoSchedule|PreferNoSchedule|NoExecute(1.6 only)"
|
# effect: "NoSchedule|PreferNoSchedule|NoExecute(1.6 only)"
|
||||||
|
|
||||||
|
# -- Affinity and anti-affinity rules for server scheduling to nodes
|
||||||
|
## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
|
||||||
affinity: {}
|
affinity: {}
|
||||||
|
# # An example of preferred pod anti-affinity, weight is in the range 1-100
|
||||||
|
# podAntiAffinity:
|
||||||
|
# preferredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
# - weight: 100
|
||||||
|
# podAffinityTerm:
|
||||||
|
# labelSelector:
|
||||||
|
# matchExpressions:
|
||||||
|
# - key: app.kubernetes.io/name
|
||||||
|
# operator: In
|
||||||
|
# values:
|
||||||
|
# - '{{ include "ingress-nginx.name" . }}'
|
||||||
|
# - key: app.kubernetes.io/instance
|
||||||
|
# operator: In
|
||||||
|
# values:
|
||||||
|
# - '{{ .Release.Name }}'
|
||||||
|
# - key: app.kubernetes.io/component
|
||||||
|
# operator: In
|
||||||
|
# values:
|
||||||
|
# - default-backend
|
||||||
|
# topologyKey: kubernetes.io/hostname
|
||||||
|
|
||||||
|
# # An example of required pod anti-affinity
|
||||||
|
# podAntiAffinity:
|
||||||
|
# requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
# - labelSelector:
|
||||||
|
# matchExpressions:
|
||||||
|
# - key: app.kubernetes.io/name
|
||||||
|
# operator: In
|
||||||
|
# values:
|
||||||
|
# - '{{ include "ingress-nginx.name" . }}'
|
||||||
|
# - key: app.kubernetes.io/instance
|
||||||
|
# operator: In
|
||||||
|
# values:
|
||||||
|
# - '{{ .Release.Name }}'
|
||||||
|
# - key: app.kubernetes.io/component
|
||||||
|
# operator: In
|
||||||
|
# values:
|
||||||
|
# - default-backend
|
||||||
|
# topologyKey: kubernetes.io/hostname
|
||||||
|
|
||||||
# -- Topology spread constraints rely on node labels to identify the topology domain(s) that each Node is in.
|
# -- Topology spread constraints rely on node labels to identify the topology domain(s) that each Node is in.
|
||||||
# Ref.: https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/
|
# Ref.: https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/
|
||||||
topologySpreadConstraints: []
|
topologySpreadConstraints: []
|
||||||
|
|
Loading…
Reference in a new issue