Skip to content

Commit

Permalink
Merge pull request #821 from smerle33/PDB/uplink
Browse files Browse the repository at this point in the history
feat(uplink): add PodDisruptionBudget and unittests
  • Loading branch information
dduportal authored Oct 3, 2023
2 parents 121b052 + bf27480 commit 92fc2ad
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 4 deletions.
4 changes: 3 additions & 1 deletion charts/uplink/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ apiVersion: v1
appVersion: "1.0"
description: A Helm chart for uplink.jenkins.io
name: uplink
version: 0.2.0
version: 0.3.0
maintainers:
- name: olblak
- name: dduportal
- name: hlemeur
- name: smerle
poddisruptionbudget:
minAvailable: 1
12 changes: 10 additions & 2 deletions charts/uplink/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ 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
*/}}
{{- define "uplink.selectorLabels" -}}
app.kubernetes.io/name: {{ include "uplink.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}


{{/*
Common labels
*/}}
{{- define "uplink.labels" -}}
app.kubernetes.io/name: {{ include "uplink.name" . }}
{{ include "uplink.selectorLabels" . }}
helm.sh/chart: {{ include "uplink.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand Down
4 changes: 3 additions & 1 deletion charts/uplink/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ spec:
httpGet:
path: /
port: 3030
{{- with .Values.resources }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
18 changes: 18 additions & 0 deletions charts/uplink/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if (gt (int .Values.replicaCount) 1) }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "uplink.fullname" . }}
labels:
{{- include "uplink.labels" . | nindent 4 }}
spec:
{{- with .Values.poddisruptionbudget.minAvailable }}
minAvailable: {{ . }}
{{- end }}
{{- with .Values.poddisruptionbudget.maxUnavailable }}
maxUnavailable: {{ . }}
{{- end }}
selector:
matchLabels:
{{- include "uplink.selectorLabels" . | nindent 6 }}
{{- end }}
36 changes: 36 additions & 0 deletions charts/uplink/tests/custom_values_test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
suite: test secret.yaml
templates:
- secret.yaml
- pdb.yaml
set:
postgresql:
url: "example-url"
Expand All @@ -10,6 +11,7 @@ set:
sentry.dsn: "example-dsn"
tests:
- it: should ensure the secret is created with custom credentials
template: secret.yaml
asserts:
- isKind:
of: Secret
Expand All @@ -28,3 +30,37 @@ tests:
- equal:
path: data['sentry.dsn']
value: "ZXhhbXBsZS1kc24=" # Base64 encoded value of "example-dsn"
- it: should create a PDB with defaults when multiple replicas are set
template: pdb.yaml
set:
replicaCount: 2
asserts:
- isKind:
of: PodDisruptionBudget
- equal:
path: spec.minAvailable
value: 1
- equal:
path: spec.selector.matchLabels['app.kubernetes.io/name']
value: "uplink"
- it: should ensure the pdb has correct spec
template: pdb.yaml
set:
replicaCount: 2
poddisruptionbudget.minAvailable: 2
poddisruptionbudget.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: "uplink"
- equal:
path: metadata.labels["app.kubernetes.io/name"]
value: uplink
29 changes: 29 additions & 0 deletions charts/uplink/tests/defaults_test.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
suite: test default behavior of secret.yaml with default values
templates:
- secret.yaml
- pdb.yaml
- deployment.yaml
tests:
- it: should render with default values without error
template: secret.yaml
asserts:
- isKind:
of: Secret
Expand All @@ -17,3 +20,29 @@ tests:
path: data.client.secret
- notExists:
path: data.sentry.dsn
- it: should not generate any pdb with default values
template: pdb.yaml
asserts:
- hasDocuments:
count: 0
- it: Should generate a deployment with the default values
template: deployment.yaml
asserts:
- hasDocuments:
count: 1
- isKind:
of: Deployment
- notExists:
path: spec.affinity
- equal:
path: metadata.labels["app.kubernetes.io/name"]
value: uplink
- equal:
path: metadata.labels["app.kubernetes.io/managed-by"]
value: Helm
- equal:
path: spec.template.spec.containers[0].name
value: uplink
- equal:
path: spec.template.spec.containers[0].resources.limits.cpu
value: 200m
2 changes: 2 additions & 0 deletions charts/uplink/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ client:
secret: ""
sentry:
dsn: ""
poddisruptionbudget:
minAvailable: 1

0 comments on commit 92fc2ad

Please sign in to comment.