From b4834540e57d383de381336557ec7bb29189707a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= Date: Tue, 22 Aug 2023 18:04:12 +0200 Subject: [PATCH] use a distinct deployment template for rsyncd to be able to set its replica count independently from mirrorbits deployment --- .../templates/deployment.rsyncd.yaml | 64 +++++++++++++++++++ charts/mirrorbits/templates/deployment.yaml | 23 ------- .../mirrorbits/templates/service.rsyncd.yaml | 2 +- .../mirrorbits/tests/custom_values_test.yaml | 41 +++++++++--- charts/mirrorbits/tests/defaults_test.yaml | 24 +++---- charts/mirrorbits/values.yaml | 1 + 6 files changed, 105 insertions(+), 50 deletions(-) create mode 100644 charts/mirrorbits/templates/deployment.rsyncd.yaml diff --git a/charts/mirrorbits/templates/deployment.rsyncd.yaml b/charts/mirrorbits/templates/deployment.rsyncd.yaml new file mode 100644 index 000000000..58b4bea52 --- /dev/null +++ b/charts/mirrorbits/templates/deployment.rsyncd.yaml @@ -0,0 +1,64 @@ +{{ if and .Values.rsyncd.service.enabled .Values.repository.persistentVolumeClaim.enabled -}} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "mirrorbits.fullname" . }} + labels: +{{ include "mirrorbits.labels" . | indent 4 }} +spec: + replicas: {{ .Values.replicaCount.rsyncd }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "mirrorbits.name" . }}-rsyncd + app.kubernetes.io/instance: {{ .Release.Name }}-rsyncd + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "mirrorbits.name" . }}-rsyncd + app.kubernetes.io/instance: {{ .Release.Name }}-rsyncd + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ template "mirrorbits.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: rsyncd + image: "{{ .Values.image.rsyncd.repository }}:{{ .Values.image.rsyncd.tag }}" + imagePullPolicy: {{ .Values.image.rsyncd.pullPolicy }} + ports: + - name: rsyncd + containerPort: 873 + protocol: TCP + livenessProbe: + tcpSocket: + port: 873 + readinessProbe: + tcpSocket: + port: 873 + resources: + {{- toYaml .Values.rsyncd.resources | nindent 12 }} + volumeMounts: + - name: binary + mountPath: /srv/repo + readOnly: true + + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + volumes: + - name: binary + persistentVolumeClaim: + claimName: {{ .Values.repository.name | default (printf "%s-binary" (include "mirrorbits.fullname" .)) }} +{{- end }} diff --git a/charts/mirrorbits/templates/deployment.yaml b/charts/mirrorbits/templates/deployment.yaml index a5f804224..13e6052cd 100644 --- a/charts/mirrorbits/templates/deployment.yaml +++ b/charts/mirrorbits/templates/deployment.yaml @@ -71,29 +71,6 @@ spec: envFrom: - secretRef: name: {{ include "mirrorbits.fullname" . }}-geoipupdate - {{ if .Values.rsyncd.service.enabled -}} - - name: rsyncd - image: "{{ .Values.image.rsyncd.repository }}:{{ .Values.image.rsyncd.tag }}" - imagePullPolicy: {{ .Values.image.rsyncd.pullPolicy }} - ports: - - name: rsyncd - containerPort: 873 - protocol: TCP - livenessProbe: - tcpSocket: - port: 873 - readinessProbe: - tcpSocket: - port: 873 - resources: - {{- toYaml .Values.rsyncd.resources | nindent 12 }} - volumeMounts: - {{- if .Values.repository.persistentVolumeClaim.enabled }} - - name: binary - mountPath: /srv/repo - readOnly: true - {{- end }} - {{- end }} initContainers: # we need to ensure the geoip data is in place before mirrorbits starts - name: geoipupdate-init diff --git a/charts/mirrorbits/templates/service.rsyncd.yaml b/charts/mirrorbits/templates/service.rsyncd.yaml index 6d07ac298..bee899a74 100644 --- a/charts/mirrorbits/templates/service.rsyncd.yaml +++ b/charts/mirrorbits/templates/service.rsyncd.yaml @@ -1,4 +1,4 @@ -{{- if .Values.rsyncd.service.enabled -}} +{{- if and .Values.rsyncd.service.enabled .Values.repository.persistentVolumeClaim.enabled -}} apiVersion: v1 kind: Service metadata: diff --git a/charts/mirrorbits/tests/custom_values_test.yaml b/charts/mirrorbits/tests/custom_values_test.yaml index a29bf96be..41955e033 100644 --- a/charts/mirrorbits/tests/custom_values_test.yaml +++ b/charts/mirrorbits/tests/custom_values_test.yaml @@ -4,9 +4,10 @@ values: templates: - deployment.yaml - deployment.files.yaml + - deployment.rsyncd.yaml - ingress.yaml - ingress.rsyncd.yaml - - secret.yaml # Direct dependency of deployment.yaml + - secret.yaml # Direct dependency of deployment(.*).yaml - service.files.yaml - service.rsyncd.yaml tests: @@ -100,30 +101,47 @@ tests: - equal: path: spec.template.spec.containers[*].imagePullPolicy value: Always - - it: should define a rsyncd container if rsyncd service is enabled - template: deployment.yaml + - it: should create rsyncd deployment if rsyncd service is enabled and PVC is enabled + template: deployment.rsyncd.yaml set: rsyncd: service: enabled: true + repository: + persistentVolumeClaim: + enabled: true asserts: - - contains: - path: spec.template.spec.containers - content: - name: rsyncd - any: true # Ignores any other values within the found content - - it: should create rsyncd service only if rsyncd service is enabled + - hasDocuments: + count: 1 + - isKind: + of: Deployment + - it: should create rsyncd deployment if only rsyncd service is enabled + template: deployment.rsyncd.yaml + set: + rsyncd: + service: + enabled: true + repository: + persistentVolumeClaim: + enabled: false + asserts: + - hasDocuments: + count: 0 + - it: should create rsyncd service if rsyncd service and PVC are enabled template: service.rsyncd.yaml set: rsyncd: service: enabled: true + repository: + persistentVolumeClaim: + enabled: true asserts: - hasDocuments: count: 1 - isKind: of: Service - - it: should create rsyncd ingress only if rsyncd ingress and service are enabled + - it: should create rsyncd ingress if rsyncd ingress & service and PVC are enabled template: ingress.rsyncd.yaml set: rsyncd: @@ -136,6 +154,9 @@ tests: paths: - path: / pathType: IfNotPresent + repository: + persistentVolumeClaim: + enabled: true asserts: - hasDocuments: count: 1 diff --git a/charts/mirrorbits/tests/defaults_test.yaml b/charts/mirrorbits/tests/defaults_test.yaml index dc07fb92e..a8a209d4a 100644 --- a/charts/mirrorbits/tests/defaults_test.yaml +++ b/charts/mirrorbits/tests/defaults_test.yaml @@ -3,11 +3,12 @@ values: - ../values.yaml - secrets_default_values.yaml templates: - - deployment.files.yaml - deployment.yaml + - deployment.files.yaml + - deployment.rsyncd.yaml - ingress.yaml - ingress.rsyncd.yaml - - secret.yaml # Direct dependency of deployment.yaml + - secret.yaml # Direct dependency of deployment(.*).yaml - service.files.yaml - service.rsyncd.yaml tests: @@ -26,6 +27,11 @@ tests: asserts: - hasDocuments: count: 0 + - it: should not create any rsyncd deployment by default + template: deployment.rsyncd.yaml + asserts: + - hasDocuments: + count: 0 - it: should create ingress with pathType set to Prefix by default template: ingress.yaml set: @@ -85,17 +91,3 @@ tests: - equal: path: "spec.template.spec.containers[*].imagePullPolicy" value: IfNotPresent - - it: should define the default "mirrorbits" deployment with default imagePullPolicy and without any rsyncd container - template: deployment.yaml - asserts: - - hasDocuments: - count: 1 - - isKind: - of: Deployment - - equal: - path: spec.template.spec.containers[*].imagePullPolicy - value: IfNotPresent - - notContains: - path: spec.template.spec.containers - content: - name: rsyncd diff --git a/charts/mirrorbits/values.yaml b/charts/mirrorbits/values.yaml index 94a2e841a..f94fc9bf4 100644 --- a/charts/mirrorbits/values.yaml +++ b/charts/mirrorbits/values.yaml @@ -4,6 +4,7 @@ replicaCount: mirrorbits: 1 files: 1 + rsyncd: 1 image: mirrorbits: repository: jenkinsciinfra/mirrorbits