Skip to content

Commit

Permalink
feat: add nodeSelector, pod tolerations, node affinity configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dmakeroam authored and eshepelyuk committed Nov 26, 2021
1 parent ef5cbbb commit 5733852
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- run: ./test/linter/test.sh
- run: |
helm plugin install https://github.com/quintush/helm-unittest
helm unittest -f test/unit/*.yaml -3 .
helm unittest -f 'test/unit/*.yaml' -3 .
- uses: AbsaOSS/k3d-action@v1.5.0
with:
cluster-name: "k3d"
Expand Down
9 changes: 9 additions & 0 deletions templates/cronjob-reconcile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ spec:
- name: {{ $nm }}-clusters
configMap:
name: {{ $nm }}-clusters
{{- with .Values.nodeSelector }}
nodeSelector: {{ toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.affinity }}
affinity: {{ toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations: {{ toYaml . | nindent 12 }}
{{- end }}
containers:
- name: setup
image: {{ $image | quote }}
Expand Down
9 changes: 9 additions & 0 deletions templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ spec:
secretName: {{ include "cmak.name" . }}-ssl
{{- end -}}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector: {{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity: {{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations: {{ toYaml . | nindent 8 }}
{{- end }}
containers:
- name: zk
image: {{ printf "%s/zookeeper:%s" .Values.imageRegistry .Values.zk.version | quote }}
Expand Down
9 changes: 9 additions & 0 deletions templates/job-setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ spec:
- name: {{ $nm }}-clusters
configMap:
name: {{ $nm }}-clusters
{{- with .Values.nodeSelector }}
nodeSelector: {{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity: {{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations: {{ toYaml . | nindent 8 }}
{{- end }}
containers:
- name: setup
image: {{ $image | quote }}
Expand Down
22 changes: 22 additions & 0 deletions test/linter/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,25 @@ helm lint . --strict
helm lint . --strict -f test/linter/values-lint.yaml
helm lint . --strict -f test/linter/values-ssl.yaml
helm dep up test/linter/subchart && helm lint test/linter/subchart --strict

helm lint . --strict --set 'tolerations.sample=1'
if [ $? -eq 0 ]; then
exit 1
fi

helm lint . --strict --set 'tolerations.sample={"qwe", "asd"}'
if [ $? -eq 0 ]; then
exit 1
fi

helm lint . --strict --set 'nodeSelector={1,2,3}'
if [ $? -eq 0 ]; then
exit 1
fi

helm lint . --strict --set 'affinity={1,2,3}'
if [ $? -eq 0 ]; then
exit 1
fi


49 changes: 49 additions & 0 deletions test/unit/deploy-placement.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
suite: deployment placement
templates:
- deployment.yaml
tests:
- it: should not populate placement by default
asserts:
- isNull:
path: spec.template.spec.nodeSelector
- isNull:
path: spec.template.spec.affinity
- isNull:
path: spec.template.spec.tolerations
- it: should populate nodeSelector
set:
nodeSelector:
myLbl: myVal
asserts:
- isNotNull:
path: spec.template.spec.nodeSelector
- isNotEmpty:
path: spec.template.spec.nodeSelector.myLbl
- equal:
path: spec.template.spec.nodeSelector.myLbl
value: myVal
- it: should populate affinity
set:
affinity:
someProp: someVal
asserts:
- isNotEmpty:
path: spec.template.spec.affinity
- equal:
path: spec.template.spec.affinity.someProp
value: someVal
- it: should populate tolerations
set:
tolerations:
- name: val
someProp: someVal
asserts:
- isNotEmpty:
path: spec.template.spec.tolerations
- contains:
path: spec.template.spec.tolerations
content:
name: val
someProp: someVal
count: 1
any: false
49 changes: 49 additions & 0 deletions test/unit/reconcile-placement.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
suite: reconcile cronjob placement
templates:
- cronjob-reconcile.yaml
tests:
- it: should not populate placement by default
asserts:
- isNull:
path: spec.jobTemplate.spec.template.spec.nodeSelector
- isNull:
path: spec.jobTemplate.spec.template.spec.affinity
- isNull:
path: spec.jobTemplate.spec.template.spec.tolerations
- it: should populate nodeSelector
set:
nodeSelector:
myLbl: myVal
asserts:
- isNotNull:
path: spec.jobTemplate.spec.template.spec.nodeSelector
- isNotEmpty:
path: spec.jobTemplate.spec.template.spec.nodeSelector.myLbl
- equal:
path: spec.jobTemplate.spec.template.spec.nodeSelector.myLbl
value: myVal
- it: should populate affinity
set:
affinity:
someProp: someVal
asserts:
- isNotEmpty:
path: spec.jobTemplate.spec.template.spec.affinity
- equal:
path: spec.jobTemplate.spec.template.spec.affinity.someProp
value: someVal
- it: should populate tolerations
set:
tolerations:
- name: val
someProp: someVal
asserts:
- isNotEmpty:
path: spec.jobTemplate.spec.template.spec.tolerations
- contains:
path: spec.jobTemplate.spec.template.spec.tolerations
content:
name: val
someProp: someVal
count: 1
any: false
49 changes: 49 additions & 0 deletions test/unit/setup-placement.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
suite: setup job placement
templates:
- job-setup.yaml
tests:
- it: should not populate placement by default
asserts:
- isNull:
path: spec.template.spec.nodeSelector
- isNull:
path: spec.template.spec.affinity
- isNull:
path: spec.template.spec.tolerations
- it: should populate nodeSelector
set:
nodeSelector:
myLbl: myVal
asserts:
- isNotNull:
path: spec.template.spec.nodeSelector
- isNotEmpty:
path: spec.template.spec.nodeSelector.myLbl
- equal:
path: spec.template.spec.nodeSelector.myLbl
value: myVal
- it: should populate affinity
set:
affinity:
someProp: someVal
asserts:
- isNotEmpty:
path: spec.template.spec.affinity
- equal:
path: spec.template.spec.affinity.someProp
value: someVal
- it: should populate tolerations
set:
tolerations:
- name: val
someProp: someVal
asserts:
- isNotEmpty:
path: spec.template.spec.tolerations
- contains:
path: spec.template.spec.tolerations
content:
name: val
someProp: someVal
count: 1
any: false
17 changes: 14 additions & 3 deletions values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,22 @@
}
}
},

"type": "object", "required": ["cmak", "reconcile", "ui", "zk"],

"properties": {
"imageRegistry": { "type": "string", "default": "docker.io", "title": "docker registry for all images of the chart" },
"affinity": {
"type": "object", "default": {}, "title": "affinity",
"description": "See https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity"
},
"nodeSelector": {
"type": "object", "default": {}, "title": "node selector",
"description": "See https://kubernetes.io/docs/tasks/configure-pod-container/assign-pods-nodes/"
},
"tolerations": {
"type": "array", "default": [], "title": "tolerations",
"description": "See https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/",
"items": {"type": "object"}
},
"reconcile": {
"type": "object", "additionalProperties": false,
"required": ["schedule"], "title": "reconciliation job config",
Expand Down Expand Up @@ -132,7 +143,7 @@
"clusters": {
"type": "array", "title": "list of configured clusters",
"items": { "$ref": "#/definitions/clusterConfig" }
}
}
}
},
"ui": {
Expand Down
9 changes: 8 additions & 1 deletion values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ reconcile:
successfulJobsHistoryLimit: null
failedJobsHistoryLimit: null
# reconcile resource configuration
# resources:
# resources:
# limits:
# cpu: 100m
# memory: 128Mi
Expand Down Expand Up @@ -124,3 +124,10 @@ ingress: null
#
# # optional ingress labels
# labels: {}

affinity: {}

nodeSelector: {}

tolerations: []

0 comments on commit 5733852

Please sign in to comment.