Skip to content

Commit

Permalink
Monochart support tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
goruha committed May 11, 2024
1 parent 3ac1df1 commit 3b828a5
Show file tree
Hide file tree
Showing 4 changed files with 368 additions and 26 deletions.
4 changes: 2 additions & 2 deletions incubator/monochart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v1
description: A declarative helm chart for deploying common types of services on Kubernetes
name: monochart
version: 0.27.0
appVersion: 0.27.0
version: 0.28.0
appVersion: 0.28.0
home: https://github.com/cloudposse/charts/tree/master/incubator/monochart
icon: https://raw.githubusercontent.com/cloudposse/charts/master/incubator/monochart/logo.png
maintainers:
Expand Down
68 changes: 68 additions & 0 deletions incubator/monochart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,71 @@ The pod anti-affinity rule to prefer not to be scheduled onto a node if that nod
topologyKey: "kubernetes.io/hostname"
{{- end -}}

{{/*
The affinity
*/}}
{{- define "monochart.affinity" -}}
{{- if .Values.affinity }}
affinity:
{{- if or .Values.affinity.podAntiAffinity (eq .Values.affinity.affinityRule "ShouldBeOnDifferentNode") }}
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
{{- if .Values.affinity.podAntiAffinity }}
{{- if .Values.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution }}
{{- with .Values.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution }}
{{ toYaml . | indent 6 }}
{{- end }}
{{- end }}
{{- end }}
{{- if eq .Values.affinity.affinityRule "ShouldBeOnDifferentNode" }}
{{- include "monochart.affinityRule.ShouldBeOnDifferentNode" . | nindent 6 }}
{{- end }}
{{- end }}
{{- if .Values.affinity.podAffinity }}
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
{{- with .Values.affinity.podAffinity.requiredDuringSchedulingIgnoredDuringExecution }}
{{ toYaml . | indent 6 }}
{{- end }}
{{- end }}
{{- end }}

{{- end -}}

{{/*
The nodeSelector
*/}}
{{- define "monochart.nodeSelector" -}}
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- {{ include "common.name" . }}
- key: release
operator: In
values:
- {{ .Release.Name | quote }}
topologyKey: "kubernetes.io/hostname"
{{- end -}}

{{/*
The tolerations
*/}}
{{- define "monochart.tolerations" -}}
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- {{ include "common.name" . }}
- key: release
operator: In
values:
- {{ .Release.Name | quote }}
topologyKey: "kubernetes.io/hostname"
{{- end -}}
27 changes: 3 additions & 24 deletions incubator/monochart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,9 @@ spec:
{{- if index .Values "serviceAccountName" }}
serviceAccountName: {{ .Values.serviceAccountName }}
{{- end }}
{{- if .Values.deployment.affinity }}
affinity:
{{- if or .Values.deployment.affinity.podAntiAffinity (eq .Values.deployment.affinity.affinityRule "ShouldBeOnDifferentNode") }}
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
{{- if .Values.deployment.affinity.podAntiAffinity }}
{{- if .Values.deployment.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution }}
{{- with .Values.deployment.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution }}
{{ toYaml . | indent 10 }}
{{- end }}
{{- end }}
{{- end }}
{{- if eq .Values.deployment.affinity.affinityRule "ShouldBeOnDifferentNode" }}
{{- include "monochart.affinityRule.ShouldBeOnDifferentNode" . | nindent 10 }}
{{- end }}
{{- end }}
{{- if .Values.deployment.affinity.podAffinity }}
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
{{- with .Values.deployment.affinity.podAffinity.requiredDuringSchedulingIgnoredDuringExecution }}
{{ toYaml . | indent 10 }}
{{- end }}
{{- end }}
{{- end }}
{{- include "monochart.affinity" . | nindent 6 }}
{{- include "monochart.nodeSelector" . | nindent 6 }}
{{- include "monochart.tolerations" . | nindent 6 }}
containers:
- name: {{ .Release.Name }}
image: {{ required "image.repository is required!" .Values.image.repository }}:{{ required "image.tag is required!" .Values.image.tag }}
Expand Down
Loading

0 comments on commit 3b828a5

Please sign in to comment.