Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions k8s-cluster/ha-cluster/helm_charts/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ spec:
- name: secret
secret:
secretName: {{ .Values.clusterName }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
terminationGracePeriodSeconds: 0
volumeClaimTemplates:
- metadata:
Expand Down
41 changes: 41 additions & 0 deletions tests/test_helm_scheduling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Render regression tests. Requires Helm 3 and PyYAML (pip install pyyaml)."""
import json
import os
from pathlib import Path
import subprocess
import unittest

CHART = Path(__file__).resolve().parents[1] / 'k8s-cluster/ha-cluster/helm_charts'

def render(overrides=None):
command = [os.environ.get('HELM', 'helm'), 'template', 'test', str(CHART)]
if overrides:
command += ['--values', '-']
result = subprocess.run(command, input=json.dumps(overrides or {}),
text=True, encoding='utf-8', capture_output=True, check=True)
import yaml
return list(yaml.safe_load_all(result.stdout))

def statefulset(documents):
return next(doc for doc in documents if doc and doc['kind'] == 'StatefulSet')

class SchedulingTest(unittest.TestCase):
def test_defaults_omit_constraints(self):
pod = statefulset(render())['spec']['template']['spec']
for key in ('nodeSelector', 'affinity', 'tolerations'):
self.assertNotIn(key, pod)

def test_scheduling_constraints(self):
settings = {
'nodeSelector': {'disktype': 'ssd'},
'tolerations': [{'key': 'database', 'operator': 'Equal', 'value': 'ivorysql', 'effect': 'NoSchedule'}],
'affinity': {'podAntiAffinity': {'requiredDuringSchedulingIgnoredDuringExecution': [
{'labelSelector': {'matchLabels': {'application': 'ivyhac'}},
'topologyKey': 'kubernetes.io/hostname'}]}},
}
pod = statefulset(render(settings))['spec']['template']['spec']
for key, value in settings.items():
self.assertEqual(pod.get(key), value, key)

if __name__ == '__main__':
unittest.main()