From 25f7ae3c2b5056e3a456d1e00b5a839bc1a3ea13 Mon Sep 17 00:00:00 2001 From: smerle33 Date: Wed, 4 Oct 2023 17:04:04 +0200 Subject: [PATCH 1/2] feat(mirrorbits): add PodDisruptionBudget and unittest --- charts/mirrorbits/Chart.yaml | 2 +- charts/mirrorbits/templates/_helpers.tpl | 16 ++++++ .../mirrorbits/tests/custom_values_test.yaml | 57 +++++++++++++++++++ charts/mirrorbits/tests/defaults_test.yaml | 18 ++++++ charts/mirrorbits/values.yaml | 8 +++ 5 files changed, 100 insertions(+), 1 deletion(-) diff --git a/charts/mirrorbits/Chart.yaml b/charts/mirrorbits/Chart.yaml index fd593aa87..26e736537 100644 --- a/charts/mirrorbits/Chart.yaml +++ b/charts/mirrorbits/Chart.yaml @@ -5,4 +5,4 @@ maintainers: - email: jenkins-infra-team@googlegroups.com name: jenkins-infra-team name: mirrorbits -version: 1.0.1 +version: 1.1.0 diff --git a/charts/mirrorbits/templates/_helpers.tpl b/charts/mirrorbits/templates/_helpers.tpl index d31d17c03..ef74f6b29 100644 --- a/charts/mirrorbits/templates/_helpers.tpl +++ b/charts/mirrorbits/templates/_helpers.tpl @@ -50,3 +50,19 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} app.kubernetes.io/managed-by: {{ .Release.Service }} {{- end -}} + +{{/* +Selector labels +*/}} +{{- define "mirrorbits.files.selectorLabels" -}} +app.kubernetes.io/name: {{ include "mirrorbits.name" . }}-files +app.kubernetes.io/instance: {{ .Release.Name }}-files +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "mirrorbits.rsyncd.selectorLabels" -}} +app.kubernetes.io/name: {{ include "mirrorbits.name" . }}-rsyncd +app.kubernetes.io/instance: {{ .Release.Name }}-rsyncd +{{- end }} diff --git a/charts/mirrorbits/tests/custom_values_test.yaml b/charts/mirrorbits/tests/custom_values_test.yaml index 28d8909c5..2e1426886 100644 --- a/charts/mirrorbits/tests/custom_values_test.yaml +++ b/charts/mirrorbits/tests/custom_values_test.yaml @@ -70,6 +70,9 @@ templates: - secret.yaml # Direct dependency of deployment(.*).yaml - service.files.yaml - service.rsyncd.yaml + - pdb.yaml + - pdb.files.yaml + - pdb.rsyncd.yaml tests: - it: Should set the correct service selector labels when a fullNameOverride is specified template: service.files.yaml @@ -167,3 +170,57 @@ tests: count: 1 - isKind: of: Service + - it: should ensure the pdb has correct spec + template: pdb.yaml + set: + replicaCount.mirrorbits: 2 + poddisruptionbudget.mirrorbits.minAvailable: 2 + poddisruptionbudget.mirrorbits.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: "mirrorbits" + - it: should ensure the pdb.files has correct spec + template: pdb.files.yaml + set: + replicaCount.files: 2 + poddisruptionbudget.files.minAvailable: 2 + poddisruptionbudget.files.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: "mirrorbits-files" + - it: should ensure the pdb.rsyncd has correct spec + template: pdb.rsyncd.yaml + set: + replicaCount.rsyncd: 2 + poddisruptionbudget.rsyncd.minAvailable: 2 + poddisruptionbudget.rsyncd.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: "mirrorbits-rsyncd" diff --git a/charts/mirrorbits/tests/defaults_test.yaml b/charts/mirrorbits/tests/defaults_test.yaml index 67cd2f50b..f8c252e3d 100644 --- a/charts/mirrorbits/tests/defaults_test.yaml +++ b/charts/mirrorbits/tests/defaults_test.yaml @@ -10,6 +10,9 @@ templates: - configmap.rsyncd.rsyncd-conf.yaml - configmap.rsyncd.jenkins-motd.yaml - service.rsyncd.yaml + - pdb.yaml + - pdb.files.yaml + - pdb.rsyncd.yaml tests: - it: should not create any ingress by default template: ingress.yaml @@ -90,3 +93,18 @@ tests: value: /var/log/mirrorbits - notExists: path: spec.template.spec.affinity + - it: should not generate any pdb with default values + template: pdb.yaml + asserts: + - hasDocuments: + count: 0 + - it: should not generate any pdb with default values + template: pdb.files.yaml + asserts: + - hasDocuments: + count: 0 + - it: should not generate any pdb with default values + template: pdb.rsyncd.yaml + asserts: + - hasDocuments: + count: 0 diff --git a/charts/mirrorbits/values.yaml b/charts/mirrorbits/values.yaml index 0a1f53db5..c6ffebba0 100644 --- a/charts/mirrorbits/values.yaml +++ b/charts/mirrorbits/values.yaml @@ -158,3 +158,11 @@ rsyncd: # **Read Only** # # Feel free to reach out on https://www.jenkins.io/chat/#jenkins-infra/ with any question you may have + +poddisruptionbudget: + mirrorbits: + minAvailable: 1 + files: + minAvailable: 1 + rsyncd: + minAvailable: 1 From b91c629cae3607a62b048a446783af4030cda5fa Mon Sep 17 00:00:00 2001 From: smerle33 Date: Wed, 4 Oct 2023 17:16:58 +0200 Subject: [PATCH 2/2] with pdb it's always better --- charts/mirrorbits/templates/pdb.files.yaml | 18 ++++++++++++++++++ charts/mirrorbits/templates/pdb.rsyncd.yaml | 18 ++++++++++++++++++ charts/mirrorbits/templates/pdb.yaml | 18 ++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 charts/mirrorbits/templates/pdb.files.yaml create mode 100644 charts/mirrorbits/templates/pdb.rsyncd.yaml create mode 100644 charts/mirrorbits/templates/pdb.yaml diff --git a/charts/mirrorbits/templates/pdb.files.yaml b/charts/mirrorbits/templates/pdb.files.yaml new file mode 100644 index 000000000..4e7d302be --- /dev/null +++ b/charts/mirrorbits/templates/pdb.files.yaml @@ -0,0 +1,18 @@ +{{- if (gt (int .Values.replicaCount.files) 1) }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "mirrorbits.fullname" . }}-files + labels: + {{- include "mirrorbits.labels" . | nindent 4 }} +spec: + {{- with .Values.poddisruptionbudget.files.minAvailable }} + minAvailable: {{ . }} + {{- end }} + {{- with .Values.poddisruptionbudget.files.maxUnavailable }} + maxUnavailable: {{ . }} + {{- end }} + selector: + matchLabels: + {{- include "mirrorbits.files.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/charts/mirrorbits/templates/pdb.rsyncd.yaml b/charts/mirrorbits/templates/pdb.rsyncd.yaml new file mode 100644 index 000000000..4a672c92b --- /dev/null +++ b/charts/mirrorbits/templates/pdb.rsyncd.yaml @@ -0,0 +1,18 @@ +{{- if (gt (int .Values.replicaCount.rsyncd) 1) }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "mirrorbits.fullname" . }}-rsyncd + labels: + {{- include "mirrorbits.labels" . | nindent 4 }} +spec: + {{- with .Values.poddisruptionbudget.rsyncd.minAvailable }} + minAvailable: {{ . }} + {{- end }} + {{- with .Values.poddisruptionbudget.rsyncd.maxUnavailable }} + maxUnavailable: {{ . }} + {{- end }} + selector: + matchLabels: + {{- include "mirrorbits.rsyncd.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/charts/mirrorbits/templates/pdb.yaml b/charts/mirrorbits/templates/pdb.yaml new file mode 100644 index 000000000..9228eefe1 --- /dev/null +++ b/charts/mirrorbits/templates/pdb.yaml @@ -0,0 +1,18 @@ +{{- if (gt (int .Values.replicaCount.mirrorbits) 1) }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "mirrorbits.fullname" . }} + labels: + {{- include "mirrorbits.labels" . | nindent 4 }} +spec: + {{- with .Values.poddisruptionbudget.mirrorbits.minAvailable }} + minAvailable: {{ . }} + {{- end }} + {{- with .Values.poddisruptionbudget.mirrorbits.maxUnavailable }} + maxUnavailable: {{ . }} + {{- end }} + selector: + matchLabels: + {{- include "mirrorbits.selectorLabels" . | nindent 6 }} +{{- end }}