Skip to content

Commit

Permalink
Add affinity for all resources that create pod (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
VyacheslavSemin authored May 8, 2024
1 parent 24a6dd1 commit ce279c5
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 15 deletions.
18 changes: 18 additions & 0 deletions README.md

Large diffs are not rendered by default.

21 changes: 18 additions & 3 deletions templates/jobs/dashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,30 @@ spec:
{{- end }}
spec:
serviceAccountName: dashboard-sa
{{- if .Values.podSecurityContext.enabled }}
securityContext: {{- toYaml .Values.podSecurityContext.jobs | nindent 8 }}
{{- end }}
{{- if or .Values.grafanaDashboard.job.customPodAntiAffinity .Values.grafanaDashboard.job.podAffinity .Values.grafanaDashboard.job.nodeAffinity }}
affinity:
{{- with .Values.grafanaDashboard.job.customPodAntiAffinity }}
podAntiAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.grafanaDashboard.job.podAffinity }}
podAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.grafanaDashboard.job.nodeAffinity }}
nodeAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- end }}
{{- if or .Values.nodeSelector .Values.grafanaDashboard.job.nodeSelector }}
nodeSelector: {{ toYaml (default .Values.nodeSelector .Values.grafanaDashboard.job.nodeSelector) | nindent 8 }}
{{- end }}
{{- if or .Values.tolerations .Values.grafanaDashboard.job.tolerations }}
tolerations: {{ toYaml (default .Values.tolerations .Values.grafanaDashboard.job.tolerations) | nindent 8 }}
{{- end }}
{{- if .Values.podSecurityContext.enabled }}
securityContext: {{- toYaml .Values.podSecurityContext.jobs | nindent 8 }}
{{- end }}
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
- name: {{ .Values.imagePullSecrets }}
Expand Down
21 changes: 18 additions & 3 deletions templates/jobs/pre-delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,30 @@ spec:
{{- end }}
spec:
serviceAccountName: {{ include "ds.serviceAccountName" . }}
{{- if .Values.podSecurityContext.enabled }}
securityContext: {{- toYaml .Values.podSecurityContext.jobs | nindent 8 }}
{{- end }}
{{- if or .Values.delete.job.customPodAntiAffinity .Values.delete.job.podAffinity .Values.delete.job.nodeAffinity }}
affinity:
{{- with .Values.delete.job.customPodAntiAffinity }}
podAntiAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.delete.job.podAffinity }}
podAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.delete.job.nodeAffinity }}
nodeAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- end }}
{{- if or .Values.nodeSelector .Values.delete.job.nodeSelector }}
nodeSelector: {{ toYaml (default .Values.nodeSelector .Values.delete.job.nodeSelector) | nindent 8 }}
{{- end }}
{{- if or .Values.tolerations .Values.delete.job.tolerations }}
tolerations: {{ toYaml (default .Values.tolerations .Values.delete.job.tolerations) | nindent 8 }}
{{- end }}
{{- if .Values.podSecurityContext.enabled }}
securityContext: {{- toYaml .Values.podSecurityContext.jobs | nindent 8 }}
{{- end }}
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
- name: {{ .Values.imagePullSecrets }}
Expand Down
21 changes: 18 additions & 3 deletions templates/jobs/pre-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,30 @@ spec:
{{- end }}
spec:
serviceAccountName: {{ include "ds.serviceAccountName" . }}
{{- if .Values.podSecurityContext.enabled }}
securityContext: {{- toYaml .Values.podSecurityContext.jobs | nindent 8 }}
{{- end }}
{{- if or .Values.install.job.customPodAntiAffinity .Values.install.job.podAffinity .Values.install.job.nodeAffinity }}
affinity:
{{- with .Values.install.job.customPodAntiAffinity }}
podAntiAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.install.job.podAffinity }}
podAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.install.job.nodeAffinity }}
nodeAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- end }}
{{- if or .Values.nodeSelector .Values.install.job.nodeSelector }}
nodeSelector: {{ toYaml (default .Values.nodeSelector .Values.install.job.nodeSelector) | nindent 8 }}
{{- end }}
{{- if or .Values.tolerations .Values.install.job.tolerations }}
tolerations: {{ toYaml (default .Values.tolerations .Values.install.job.tolerations) | nindent 8 }}
{{- end }}
{{- if .Values.podSecurityContext.enabled }}
securityContext: {{- toYaml .Values.podSecurityContext.jobs | nindent 8 }}
{{- end }}
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
- name: {{ .Values.imagePullSecrets }}
Expand Down
21 changes: 18 additions & 3 deletions templates/jobs/pre-rollback.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,30 @@ spec:
{{- end }}
spec:
serviceAccountName: {{ include "ds.serviceAccountName" . }}
{{- if .Values.podSecurityContext.enabled }}
securityContext: {{- toYaml .Values.podSecurityContext.jobs | nindent 8 }}
{{- end }}
{{- if or .Values.rollback.job.customPodAntiAffinity .Values.rollback.job.podAffinity .Values.rollback.job.nodeAffinity }}
affinity:
{{- with .Values.rollback.job.customPodAntiAffinity }}
podAntiAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.rollback.job.podAffinity }}
podAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.rollback.job.nodeAffinity }}
nodeAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- end }}
{{- if or .Values.nodeSelector .Values.rollback.job.nodeSelector }}
nodeSelector: {{ toYaml (default .Values.nodeSelector .Values.rollback.job.nodeSelector) | nindent 8 }}
{{- end }}
{{- if or .Values.tolerations .Values.rollback.job.tolerations }}
tolerations: {{ toYaml (default .Values.tolerations .Values.rollback.job.tolerations) | nindent 8 }}
{{- end }}
{{- if .Values.podSecurityContext.enabled }}
securityContext: {{- toYaml .Values.podSecurityContext.jobs | nindent 8 }}
{{- end }}
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
- name: {{ .Values.imagePullSecrets }}
Expand Down
21 changes: 18 additions & 3 deletions templates/jobs/pre-upgrade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,30 @@ spec:
{{- end }}
spec:
serviceAccountName: {{ include "ds.serviceAccountName" . }}
{{- if .Values.podSecurityContext.enabled }}
securityContext: {{- toYaml .Values.podSecurityContext.jobs | nindent 8 }}
{{- end }}
{{- if or .Values.upgrade.job.customPodAntiAffinity .Values.upgrade.job.podAffinity .Values.upgrade.job.nodeAffinity }}
affinity:
{{- with .Values.upgrade.job.customPodAntiAffinity }}
podAntiAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.upgrade.job.podAffinity }}
podAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.upgrade.job.nodeAffinity }}
nodeAffinity:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- end }}
{{- if or .Values.nodeSelector .Values.upgrade.job.nodeSelector }}
nodeSelector: {{ toYaml (default .Values.nodeSelector .Values.upgrade.job.nodeSelector) | nindent 8 }}
{{- end }}
{{- if or .Values.tolerations .Values.upgrade.job.tolerations }}
tolerations: {{ toYaml (default .Values.tolerations .Values.upgrade.job.tolerations) | nindent 8 }}
{{- end }}
{{- if .Values.podSecurityContext.enabled }}
securityContext: {{- toYaml .Values.podSecurityContext.jobs | nindent 8 }}
{{- end }}
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
- name: {{ .Values.imagePullSecrets }}
Expand Down
15 changes: 15 additions & 0 deletions templates/tests/test-ds-pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ spec:
{{- if .Values.podSecurityContext.enabled }}
securityContext: {{- toYaml .Values.podSecurityContext.tests | nindent 4 }}
{{- end }}
{{- if or .Values.tests.customPodAntiAffinity .Values.tests.podAffinity .Values.tests.nodeAffinity }}
affinity:
{{- with .Values.tests.customPodAntiAffinity }}
podAntiAffinity:
{{- toYaml . | nindent 6 }}
{{- end }}
{{- with .Values.tests.podAffinity }}
podAffinity:
{{- toYaml . | nindent 6 }}
{{- end }}
{{- with .Values.tests.nodeAffinity }}
nodeAffinity:
{{- toYaml . | nindent 6 }}
{{- end }}
{{- end }}
{{- if or .Values.nodeSelector .Values.tests.nodeSelector }}
nodeSelector: {{ toYaml (default .Values.nodeSelector .Values.tests.nodeSelector) | nindent 4 }}
{{- end }}
Expand Down
60 changes: 60 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,16 @@ install:
annotations: {}
## install.job.podAnnotations Map of annotations to add to the pre-install Pod
podAnnotations: {}
## install.job.customPodAntiAffinity Prohibiting the scheduling of pre-install Job Pod relative to other Pods containing the specified labels on the same node
customPodAntiAffinity: {}
## Pod affinity rules for pre-install Job Pod scheduling by nodes relative to other Pods
## Pod affinity allow you to constrain which nodes pre-install Job Pod can be scheduled on based on the labels of Pods already running on that node
## ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity
podAffinity: {}
## Node affinity rules for pre-install Job Pod scheduling by nodes
## Node affinity allow you to constrain which nodes pre-install Job Pod can be scheduled on based on node labels
## ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity
nodeAffinity: {}
## install.job.nodeSelector Node labels for pre-install Job Pod assignment
## If set to, it takes priority over the `nodeSelector`
nodeSelector: {}
Expand Down Expand Up @@ -1173,6 +1183,16 @@ upgrade:
annotations: {}
## upgrade.job.podAnnotations Map of annotations to add to the pre-upgrade Pod
podAnnotations: {}
## upgrade.job.customPodAntiAffinity Prohibiting the scheduling of pre-upgrade Job Pod relative to other Pods containing the specified labels on the same node
customPodAntiAffinity: {}
## Pod affinity rules for pre-upgrade Job Pod scheduling by nodes relative to other Pods
## Pod affinity allow you to constrain which nodes pre-upgrade Job Pod can be scheduled on based on the labels of Pods already running on that node
## ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity
podAffinity: {}
## Node affinity rules for pre-upgrade Job Pod scheduling by nodes
## Node affinity allow you to constrain which nodes pre-upgrade Job Pod can be scheduled on based on node labels
## ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity
nodeAffinity: {}
## upgrade.job.nodeSelector Node labels for pre-upgrade Job Pod assignment
## If set to, it takes priority over the `nodeSelector`
nodeSelector: {}
Expand Down Expand Up @@ -1252,6 +1272,16 @@ rollback:
annotations: {}
## rollback.job.podAnnotations Map of annotations to add to the pre-rollback Pod
podAnnotations: {}
## rollback.job.customPodAntiAffinity Prohibiting the scheduling of pre-rollback Job Pod relative to other Pods containing the specified labels on the same node
customPodAntiAffinity: {}
## Pod affinity rules for pre-rollback Job Pod scheduling by nodes relative to other Pods
## Pod affinity allow you to constrain which nodes pre-rollback Job Pod can be scheduled on based on the labels of Pods already running on that node
## ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity
podAffinity: {}
## Node affinity rules for pre-rollback Job Pod scheduling by nodes
## Node affinity allow you to constrain which nodes pre-rollback Job Pod can be scheduled on based on node labels
## ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity
nodeAffinity: {}
## rollback.job.nodeSelector Node labels for pre-rollback Job Pod assignment
## If set to, it takes priority over the `nodeSelector`
nodeSelector: {}
Expand Down Expand Up @@ -1331,6 +1361,16 @@ delete:
annotations: {}
## delete.job.podAnnotations Map of annotations to add to the pre-delete Pod
podAnnotations: {}
## delete.job.customPodAntiAffinity Prohibiting the scheduling of pre-delete Job Pod relative to other Pods containing the specified labels on the same node
customPodAntiAffinity: {}
## Pod affinity rules for pre-delete Job Pod scheduling by nodes relative to other Pods
## Pod affinity allow you to constrain which nodes pre-delete Job Pod can be scheduled on based on the labels of Pods already running on that node
## ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity
podAffinity: {}
## Node affinity rules for Rollback Job Pod scheduling by nodes
## Node affinity allow you to constrain which nodes pre-delete Job Pod can be scheduled on based on node labels
## ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity
nodeAffinity: {}
## delete.job.nodeSelector Node labels for pre-delete Job Pod assignment
## If set to, it takes priority over the `nodeSelector`
nodeSelector: {}
Expand Down Expand Up @@ -1401,6 +1441,16 @@ grafanaDashboard:
annotations: {}
## grafanaDashboard.job.podAnnotations Map of annotations to add to the Grafana Dashboard Pod
podAnnotations: {}
## grafanaDashboard.job.customPodAntiAffinity Prohibiting the scheduling of Grafana Dashboard Job Pod relative to other Pods containing the specified labels on the same node
customPodAntiAffinity: {}
## Pod affinity rules for Grafana Dashboard Job Pod scheduling by nodes relative to other Pods
## Pod affinity allow you to constrain which nodes Grafana Dashboard Job Pod can be scheduled on based on the labels of Pods already running on that node
## ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity
podAffinity: {}
## Node affinity rules for Grafana Dashboard Job Pod scheduling by nodes
## Node affinity allow you to constrain which nodes Grafana Dashboard Job Pod can be scheduled on based on node labels
## ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity
nodeAffinity: {}
## grafanaDashboard.job.nodeSelector Node labels for Grafana Dashboard Job Pod assignment
## If set to, it takes priority over the `nodeSelector`
nodeSelector: {}
Expand Down Expand Up @@ -1456,6 +1506,16 @@ tests:
## If set to, it takes priority over the `commonAnnotations`
## You can also use `tpl` as the value for the key
annotations: {}
## tests.customPodAntiAffinity Prohibiting the scheduling of Test Pod relative to other Pods containing the specified labels on the same node
customPodAntiAffinity: {}
## Pod affinity rules for Test Pod scheduling by nodes relative to other Pods
## Pod affinity allow you to constrain which nodes Test Pod can be scheduled on based on the labels of Pods already running on that node
## ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity
podAffinity: {}
## Node affinity rules for Test Pod scheduling by nodes
## Node affinity allow you to constrain which nodes Test Pod can be scheduled on based on node labels
## ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity
nodeAffinity: {}
## tests.nodeSelector Node labels for Test Pod assignment
## If set to, it takes priority over the `nodeSelector`
nodeSelector: {}
Expand Down

0 comments on commit ce279c5

Please sign in to comment.