diff --git a/charts/plugin-site/Chart.yaml b/charts/plugin-site/Chart.yaml index 0185b7b0d..22dce8c2a 100644 --- a/charts/plugin-site/Chart.yaml +++ b/charts/plugin-site/Chart.yaml @@ -5,4 +5,4 @@ maintainers: - name: timja - name: halkeye name: plugin-site -version: 0.2.0 +version: 0.3.0 diff --git a/charts/plugin-site/templates/_helpers.tpl b/charts/plugin-site/templates/_helpers.tpl index dc96d0b1b..1876748c4 100644 --- a/charts/plugin-site/templates/_helpers.tpl +++ b/charts/plugin-site/templates/_helpers.tpl @@ -31,13 +31,28 @@ Create chart name and version as used by the chart label. {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} {{- end -}} +{{/* +Selector labels frontend +*/}} +{{- define "plugin-site-frontend.selectorLabels" -}} +app.kubernetes.io/name: {{ include "plugin-site.name" . }}-frontend +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "plugin-site.selectorLabels" -}} +app.kubernetes.io/name: {{ include "plugin-site.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + {{/* Common labels */}} {{- define "plugin-site.labels" -}} -app.kubernetes.io/name: {{ include "plugin-site.name" . }} +{{ include "plugin-site.selectorLabels" . }} helm.sh/chart: {{ include "plugin-site.chart" . }} -app.kubernetes.io/instance: {{ .Release.Name }} {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} diff --git a/charts/plugin-site/templates/deployment-frontend.yaml b/charts/plugin-site/templates/deployment-frontend.yaml index 30bf57482..5912b654b 100644 --- a/charts/plugin-site/templates/deployment-frontend.yaml +++ b/charts/plugin-site/templates/deployment-frontend.yaml @@ -67,7 +67,11 @@ spec: {{- end }} volumes: - name: html + {{- if .Values.htmlVolume }} {{ toYaml .Values.htmlVolume | indent 10 }} + {{- else }} + emptyDir: {} + {{- end }} - name: config configMap: name: {{ include "plugin-site.fullname" . }}-nginx diff --git a/charts/plugin-site/templates/pdb-frontend.yaml b/charts/plugin-site/templates/pdb-frontend.yaml new file mode 100644 index 000000000..07ffe520b --- /dev/null +++ b/charts/plugin-site/templates/pdb-frontend.yaml @@ -0,0 +1,18 @@ +{{- if (gt (int .Values.frontend.replicaCount) 1) }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "plugin-site.fullname" . }}-frontend + labels: + {{- include "plugin-site.labels" . | nindent 4 }} +spec: + {{- with .Values.frontend.poddisruptionbudget.minAvailable }} + minAvailable: {{ . }} + {{- end }} + {{- with .Values.frontend.poddisruptionbudget.maxUnavailable }} + maxUnavailable: {{ . }} + {{- end }} + selector: + matchLabels: + {{- include "plugin-site-frontend.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/charts/plugin-site/tests/custom_values_test.yaml b/charts/plugin-site/tests/custom_values_test.yaml new file mode 100644 index 000000000..b670fdfc8 --- /dev/null +++ b/charts/plugin-site/tests/custom_values_test.yaml @@ -0,0 +1,58 @@ +suite: Test with custom values +templates: + - deployment-frontend.yaml + - ingress.yaml + - pdb-frontend.yaml + - nginx-configmap.yaml # Direct dependency of deployment.yaml +tests: + - it: should create an ingress when ingress.enabled is true + set: + ingress: + enabled: true + template: ingress.yaml + asserts: + - hasDocuments: + count: 1 + - it: should mount the html volume when htmlVolume is set + template: deployment-frontend.yaml + set: + htmlVolume: + hostPath: /host + frontend: + resources: + limits: + cpu: 300ms + asserts: + - hasDocuments: + count: 1 + - isKind: + of: Deployment + - equal: + path: spec.template.spec.volumes[0].name + value: html + - equal: + path: spec.template.spec.volumes[0].hostPath + value: /host + - equal: + path: spec.template.spec.containers[0].resources.limits.cpu + value: 300ms + - it: should create a customized PDB with the provided spec + template: pdb-frontend.yaml + set: + frontend: + replicaCount: 3 + poddisruptionbudget: + minAvailable: 2 + maxUnavailable: 3 + asserts: + - isKind: + of: PodDisruptionBudget + - equal: + path: spec.minAvailable + value: 2 + - equal: + path: spec.maxUnavailable + value: 3 + - equal: + path: spec.selector.matchLabels['app.kubernetes.io/name'] + value: "plugin-site-frontend" diff --git a/charts/plugin-site/tests/defaults_values_test.yaml b/charts/plugin-site/tests/defaults_values_test.yaml new file mode 100644 index 000000000..1ffa41652 --- /dev/null +++ b/charts/plugin-site/tests/defaults_values_test.yaml @@ -0,0 +1,50 @@ +suite: Test with default values +templates: + - deployment-frontend.yaml + - ingress.yaml + - pdb-frontend.yaml + - nginx-configmap.yaml +tests: + - it: should not create an ingress by default + template: ingress.yaml + asserts: + - hasDocuments: + count: 0 + - it: should define the default deployment with default imagePullPolicy + template: deployment-frontend.yaml + asserts: + - hasDocuments: + count: 1 + - isKind: + of: Deployment + - equal: + path: spec.template.spec.containers[0].imagePullPolicy + value: IfNotPresent + - equal: + path: metadata.labels["app.kubernetes.io/name"] + value: plugin-site + - equal: + path: metadata.labels["app.kubernetes.io/managed-by"] + value: Helm + - equal: + path: spec.template.spec.volumes[0].name + value: html + - equal: + path: spec.template.spec.volumes[0].emptyDir + value: {} + - equal: + path: spec.template.spec.containers[0].resources.limits.cpu + value: 100m + - it: should create a pdb with default values as the frontend service is replicated to 2 by default + template: pdb-frontend.yaml + asserts: + - hasDocuments: + count: 1 + - isKind: + of: PodDisruptionBudget + - equal: + path: spec.minAvailable + value: 1 + - equal: + path: spec.selector.matchLabels['app.kubernetes.io/name'] + value: "plugin-site-frontend" diff --git a/charts/plugin-site/values.yaml b/charts/plugin-site/values.yaml index e4bb4ad62..da41eb288 100644 --- a/charts/plugin-site/values.yaml +++ b/charts/plugin-site/values.yaml @@ -30,6 +30,8 @@ frontend: requests: cpu: 100m memory: 32Mi + poddisruptionbudget: + minAvailable: 1 imagePullSecrets: [] nameOverride: "" fullnameOverride: ""