Skip to content

Commit

Permalink
Merge pull request #840 from smerle33/PDB/plugin-site/frontend
Browse files Browse the repository at this point in the history
feat(plugin-site-frontend): add PDB and unittest
  • Loading branch information
dduportal authored Oct 6, 2023
2 parents 4fc7056 + 12c9b94 commit 0a275de
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/plugin-site/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ maintainers:
- name: timja
- name: halkeye
name: plugin-site
version: 0.2.0
version: 0.3.0
19 changes: 17 additions & 2 deletions charts/plugin-site/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 4 additions & 0 deletions charts/plugin-site/templates/deployment-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions charts/plugin-site/templates/pdb-frontend.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
58 changes: 58 additions & 0 deletions charts/plugin-site/tests/custom_values_test.yaml
Original file line number Diff line number Diff line change
@@ -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"
50 changes: 50 additions & 0 deletions charts/plugin-site/tests/defaults_values_test.yaml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions charts/plugin-site/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ frontend:
requests:
cpu: 100m
memory: 32Mi
poddisruptionbudget:
minAvailable: 1
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
Expand Down

0 comments on commit 0a275de

Please sign in to comment.