Skip to content

Commit

Permalink
Merge pull request #114 from gimlet-io/merge
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
laszlocph authored Dec 20, 2023
2 parents d27b401 + 35231e6 commit 78d23b1
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 139 deletions.
2 changes: 1 addition & 1 deletion charts/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ type: library
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.4.1
version: 0.5.0
54 changes: 54 additions & 0 deletions charts/common/templates/_container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{- define "common.container.tpl" -}}
name: {{ template "robustName" .Release.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 2 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.command }}
command:
- {{ .Values.shell }}
- -c
- {{ .Values.command | quote }}
{{- end }}
ports:
{{- if not .Values.ports }}
- name: http
containerPort: {{ .Values.containerPort }}
protocol: TCP
{{- else }}
{{- range .Values.ports }}
- name: {{ .name }}
containerPort: {{ .containerPort }}
protocol: TCP
{{- end }}
{{- end }}
{{- if .Values.probe.enabled }}
readinessProbe:
httpGet:
path: {{ .Values.probe.path }}
port: {{ .Values.containerPort }}
scheme: HTTP
{{- with .Values.probe.settings }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- end }}
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: {{ .Values.livenessProbe.path }}
port: {{ .Values.containerPort }}
scheme: HTTP
{{- with .Values.livenessProbe.settings }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- end }}
{{- if not .Values.resources.ignore }}
resources:
{{- if .Values.resources.ignoreLimits }}
requests:
{{- toYaml .Values.resources.requests | nindent 4 }}
{{- else }}
{{- toYaml .Values.resources | nindent 2 }}
{{- end }}
{{- end }}
{{- end }}
80 changes: 80 additions & 0 deletions charts/common/templates/_podSpec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{{- define "common.podSpec.tpl" -}}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 2 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 2 }}
{{- if .Values.serviceAccount }}
serviceAccountName: {{ .Values.serviceAccount }}
{{- end }}
initContainers:
{{- range .Values.initContainers }}
- name: {{ .name }}
image: "{{ .image }}:{{ .tag }}"
imagePullPolicy: {{ .imagePullPolicy | default "IfNotPresent" }}
{{- if .command }}
command:
- {{ $.Values.shell }}
- -c
- {{ .command | quote}}
{{- end }}
volumeMounts:
{{- range $.Values.volumes }}
{{- if (or (hasPrefix "shared-" .name) (hasPrefix "init-" .name))}}
- mountPath: {{ .path }}
name: {{ .name }}
{{- end }}
{{- end }}
{{- if .securityContext }}
securityContext:
{{- toYaml .securityContext | nindent 6 }}
{{- end}}
{{- end }}
containers:
{{- $containerTpl := include "common.container.tpl" . | fromYaml }}
{{- $container := mergeOverwrite $containerTpl .Values.container }}
- {{ toYaml $container | nindent 4 }}
{{- include "common.envFromRef.tpl" . | nindent 4 }}
{{- include "common.volumeMountsRef.tpl" . | nindent 4 }}
{{- if .Values.sidecar }}
- name: {{ template "robustName" .Release.Name }}-sidecar
securityContext:
{{- toYaml .Values.securityContext | nindent 6 }}
image: {{ .Values.sidecar.repository }}:{{ .Values.sidecar.tag }}
{{- if .Values.sidecar.command }}
command:
- {{ .Values.sidecar.shell }}
- -c
- {{ .Values.sidecar.command | quote }}
{{- end }}
{{- include "common.envFromRef.tpl" . | nindent 4 }}
{{- include "common.volumeMountsRef.tpl" . | nindent 4 }}
{{- end }}
{{- include "common.volumesRef.tpl" . }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- if or .Values.spreadAcrossNodes .Values.affinity }}
affinity:
{{- if .Values.spreadAcrossNodes }}
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app.kubernetes.io/instance"
operator: In
values:
- {{ template "robustName" .Release.Name }}
topologyKey: "kubernetes.io/hostname"
{{- end }}
{{- if .Values.affinity }}
{{- toYaml .Values.affinity | nindent 2 }}
{{- end }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- end }}
6 changes: 3 additions & 3 deletions charts/common/templates/_volumesRef.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- define "common.volumesRef.tpl" -}}
{{- if or (or (or (.Values.volumes) (.Values.sealedFileSecrets)) .Values.fileSecrets) .Values.existingFileSecrets -}}
{{- define "common.volumesRef.tpl" }}
{{- if or (or (or (.Values.volumes) (.Values.sealedFileSecrets)) .Values.fileSecrets) .Values.existingFileSecrets }}
volumes:
{{- range .Values.volumes }}
- name: {{ .name }}
Expand Down Expand Up @@ -42,4 +42,4 @@ volumes:
secretName: {{ .name }}
{{- end }}
{{- end }}
{{- end -}}
{{- end }}
6 changes: 3 additions & 3 deletions charts/cron-job/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies:
- name: common
repository: file://../common
version: 0.4.0
digest: sha256:d4eccd332ada7362f429e04b82022f5605a02e2d3aa7b9fdf8adaf4f6c9e03eb
generated: "2023-10-20T10:53:13.982995773+02:00"
version: 0.5.0
digest: sha256:30d2b6050fd6d3ce739c4a1b549f16713ad778669467e767ddf1fc67bc1114d4
generated: "2023-12-18T16:50:56.069352+01:00"
2 changes: 1 addition & 1 deletion charts/cron-job/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ version: 0.63.0

dependencies:
- name: common
version: 0.4.1
version: 0.5.0
repository: file://../common
Binary file removed charts/cron-job/charts/common-0.4.0.tgz
Binary file not shown.
Binary file added charts/cron-job/charts/common-0.5.0.tgz
Binary file not shown.
6 changes: 3 additions & 3 deletions charts/onechart/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies:
- name: common
repository: file://../common
version: 0.4.0
digest: sha256:d4eccd332ada7362f429e04b82022f5605a02e2d3aa7b9fdf8adaf4f6c9e03eb
generated: "2023-10-20T10:52:47.237955041+02:00"
version: 0.5.0
digest: sha256:30d2b6050fd6d3ce739c4a1b549f16713ad778669467e767ddf1fc67bc1114d4
generated: "2023-12-18T13:46:34.090227+01:00"
2 changes: 1 addition & 1 deletion charts/onechart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ version: 0.63.0

dependencies:
- name: common
version: 0.4.1
version: 0.5.0
repository: file://../common
Binary file removed charts/onechart/charts/common-0.4.0.tgz
Binary file not shown.
Binary file added charts/onechart/charts/common-0.5.0.tgz
Binary file not shown.
130 changes: 3 additions & 127 deletions charts/onechart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,130 +44,6 @@ spec:
{{- end }}
{{- include "helm-chart.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- if .Values.serviceAccount }}
serviceAccountName: {{ .Values.serviceAccount }}
{{- end }}
initContainers:
{{- range .Values.initContainers }}
- name: {{ .name }}
image: "{{ .image }}:{{ .tag }}"
imagePullPolicy: {{ .imagePullPolicy | default "IfNotPresent" }}
{{- if .command }}
command:
- {{ $.Values.shell }}
- -c
- {{ .command | quote}}
{{- end }}
volumeMounts:
{{- range $.Values.volumes }}
{{- if (or (hasPrefix "shared-" .name) (hasPrefix "init-" .name))}}
- mountPath: {{ .path }}
name: {{ .name }}
{{- end }}
{{- end }}
{{- if .securityContext }}
securityContext:
{{- toYaml .securityContext | nindent 12 }}
{{- end}}
{{- end }}
containers:
- name: {{ template "robustName" .Release.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.command }}
command:
- {{ .Values.shell }}
- -c
- {{ .Values.command | quote }}
{{- end }}
{{- include "common.envFromRef.tpl" . | nindent 10 }}
ports:
{{- if not .Values.ports }}
- name: http
containerPort: {{ .Values.containerPort }}
protocol: TCP
{{- else }}
{{- range .Values.ports }}
- name: {{ .name }}
containerPort: {{ .containerPort }}
protocol: TCP
{{- end }}
{{- end }}
{{- if .Values.probe.enabled }}
readinessProbe:
httpGet:
path: {{ .Values.probe.path }}
port: {{ .Values.containerPort }}
scheme: HTTP
{{- with .Values.probe.settings }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: {{ .Values.livenessProbe.path }}
port: {{ .Values.containerPort }}
scheme: HTTP
{{- with .Values.livenessProbe.settings }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- include "common.volumeMountsRef.tpl" . | nindent 10 }}
{{- if not .Values.resources.ignore }}
resources:
{{- if .Values.resources.ignoreLimits }}
requests:
{{- toYaml .Values.resources.requests | nindent 14 }}
{{- else }}
{{- toYaml .Values.resources | nindent 12 }}
{{- end }}
{{- end }}
{{- if .Values.sidecar }}
- name: {{ template "robustName" .Release.Name }}-sidecar
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: {{ .Values.sidecar.repository }}:{{ .Values.sidecar.tag }}
{{- if .Values.sidecar.command }}
command:
- {{ .Values.sidecar.shell }}
- -c
- {{ .Values.sidecar.command | quote }}
{{- end }}
{{- include "common.envFromRef.tpl" . | nindent 10 }}
{{- include "common.volumeMountsRef.tpl" . | nindent 10 }}
{{- end }}
{{- include "common.volumesRef.tpl" . | nindent 6 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if or .Values.spreadAcrossNodes .Values.affinity }}
affinity:
{{- if .Values.spreadAcrossNodes }}
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app.kubernetes.io/instance"
operator: In
values:
- {{ template "robustName" .Release.Name }}
topologyKey: "kubernetes.io/hostname"
{{- end }}
{{- if .Values.affinity }}
{{- toYaml .Values.affinity | nindent 8 }}
{{- end }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- $podSpecTpl := include "common.podSpec.tpl" . | fromYaml }}
{{- $podSpec := mergeOverwrite $podSpecTpl .Values.podSpec }}
{{- toYaml $podSpec | nindent 6 }}
14 changes: 14 additions & 0 deletions charts/onechart/tests/deployment_merge_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
suite: test deployment
templates:
- deployment.yaml
- configmap.yaml
tests:
- it: Should add hostNetwork
set:
podSpec:
hostNetwork: true
asserts:
- template: deployment.yaml
equal:
path: spec.template.spec.hostNetwork
value: true
3 changes: 3 additions & 0 deletions charts/onechart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@ nodePortEnabled: false
# Set true to enable service monitor.
monitor:
enabled: false

container: {}
podSpec: {}
8 changes: 8 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ volumes:
vars:
var1: value1
var2: value2

probe:
enabled: true
settings:
periodSeconds: 30

podSpec:
hostNetwork: true

0 comments on commit 78d23b1

Please sign in to comment.