From 34df5b8fb599cac7c705efe91e3262f5a035e289 Mon Sep 17 00:00:00 2001 From: bjws Date: Thu, 19 Nov 2020 16:05:29 +0100 Subject: [PATCH] Initial daemonset support --- charts/common/templates/_all.tpl | 8 ++- charts/common/templates/_daemonset.tpl | 69 +++++++++++++++++++ .../templates/lib/chart/_capabilities.tpl | 11 +++ charts/common/values.yaml | 6 +- 4 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 charts/common/templates/_daemonset.tpl diff --git a/charts/common/templates/_all.tpl b/charts/common/templates/_all.tpl index efc24e5131..093a65bcaf 100644 --- a/charts/common/templates/_all.tpl +++ b/charts/common/templates/_all.tpl @@ -10,10 +10,12 @@ {{- /* Build the templates */ -}} {{- include "common.pvc" . }} {{- print "---" | nindent 0 -}} - {{- if eq .Values.controllerType "statefulset" }} - {{- include "common.statefulset" . | nindent 0 }} - {{ else }} + {{- if eq .Values.controllerType "deployment" }} {{- include "common.deployment" . | nindent 0 }} + {{ else if eq .Values.controllerType "daemonset" }} + {{- include "common.daemonset" . | nindent 0 }} + {{ else if eq .Values.controllerType "statefulset" }} + {{- include "common.statefulset" . | nindent 0 }} {{- end -}} {{- print "---" | nindent 0 -}} {{ include "common.service" . | nindent 0 }} diff --git a/charts/common/templates/_daemonset.tpl b/charts/common/templates/_daemonset.tpl new file mode 100644 index 0000000000..e606b6bdd2 --- /dev/null +++ b/charts/common/templates/_daemonset.tpl @@ -0,0 +1,69 @@ +{{- define "common.daemonset" -}} +apiVersion: {{ include "common.capabilities.daemonset.apiVersion" . }} +kind: DaemonSet +metadata: + name: {{ include "common.names.fullname" . }} + labels: + {{- include "common.labels" . | nindent 4 }} + {{- with .Values.controllerLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.controllerAnnotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + selector: + matchLabels: + {{- include "common.labels.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "common.labels.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.podSecurityContext }} + securityContext: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.hostNetwork }} + hostNetwork: {{ . }} + {{- end }} + {{- with .Values.dnsPolicy }} + dnsPolicy: {{ . }} + {{- end }} + {{- with .Values.initContainers }} + initContainers: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + {{- include "common.controller.mainContainer" . | nindent 6 }} + {{- with .Values.additionalContainers }} + {{- toYaml . | nindent 6 }} + {{- end }} + volumes: + {{- include "common.controller.volumes" . | trim | nindent 6 }} + {{- with .Values.hostAliases }} + hostAliases: + {{- toYaml . | nindent 8 }} + {{- 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 }} +{{- end }} diff --git a/charts/common/templates/lib/chart/_capabilities.tpl b/charts/common/templates/lib/chart/_capabilities.tpl index 1aaf504436..c2359c32e8 100644 --- a/charts/common/templates/lib/chart/_capabilities.tpl +++ b/charts/common/templates/lib/chart/_capabilities.tpl @@ -1,3 +1,14 @@ +{{/* +Return the appropriate apiVersion for daemonset. +*/}} +{{- define "common.capabilities.daemonset.apiVersion" -}} +{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}} +{{- print "extensions/v1beta1" -}} +{{- else -}} +{{- print "apps/v1" -}} +{{- end -}} +{{- end -}} + {{/* Return the appropriate apiVersion for deployment. */}} diff --git a/charts/common/values.yaml b/charts/common/values.yaml index 14f3f5cefc..742fbb1e70 100644 --- a/charts/common/values.yaml +++ b/charts/common/values.yaml @@ -1,8 +1,8 @@ -# type: options are statefulset or deployment +# type: options are deployment, daemonset or statefulset controllerType: deployment -# Set annotations on the deployment/statefulset +# Set annotations on the deployment/statefulset/daemonset controllerAnnotations: {} -# Set labels on the deployment/statefulset +# Set labels on the deployment/statefulset/daemonset controllerLabels: {} replicas: 1