From f1ce89c69318c6701dca577d382a6a94fb355c69 Mon Sep 17 00:00:00 2001 From: Dominik Rosiek Date: Wed, 3 Apr 2024 09:16:12 +0200 Subject: [PATCH 1/3] feat: add pvcCleaner for events Signed-off-by: Dominik Rosiek --- deploy/helm/sumologic/README.md | 1 + .../sumologic/templates/_helpers/_events.tpl | 10 ++- .../templates/pvc-cleaner/configmap.yaml | 2 +- .../pvc-cleaner/cron-job-events.yaml | 71 ++++++++++++++++ .../templates/pvc-cleaner/serviceaccount.yaml | 2 +- deploy/helm/sumologic/values.yaml | 2 + .../pvc-cleaner/full_config_events.input.yaml | 79 ++++++++++++++++++ .../full_config_events.output.yaml | 81 +++++++++++++++++++ 8 files changed, 245 insertions(+), 3 deletions(-) create mode 100644 deploy/helm/sumologic/templates/pvc-cleaner/cron-job-events.yaml create mode 100644 tests/helm/testdata/goldenfile/pvc-cleaner/full_config_events.input.yaml create mode 100644 tests/helm/testdata/goldenfile/pvc-cleaner/full_config_events.output.yaml diff --git a/deploy/helm/sumologic/README.md b/deploy/helm/sumologic/README.md index 0f19554f7a..9be3112290 100644 --- a/deploy/helm/sumologic/README.md +++ b/deploy/helm/sumologic/README.md @@ -482,6 +482,7 @@ The following table lists the configurable parameters of the Sumo Logic chart an | `tailing-sidecar-operator.scc.create` | Create OpenShift's Security Context Constraint | `false` | | `pvcCleaner.metrics.enabled` | Flag to enable cleaning unused PVCs for otelcol metrics statefulsets. | `false` | | `pvcCleaner.logs.enabled` | Flag to enable cleaning unused PVCs for otelcol logs statefulsets. | `false` | +| `pvcCleaner.events.enabled` | Flag to enable cleaning unused PVCs for otelcol events statefulsets. | `false` | | `pvcCleaner.job.image.repository` | Image repository for pvcCleaner docker containers. | `public.ecr.aws/sumologic/kubernetes-tools-kubectl` | | `pvcCleaner.job.image.tag` | Image tag for pvcCleaner docker containers. | `2.22.0` | | `pvcCleaner.job.image.pullPolicy` | Image pullPolicy for pvcCleaner docker containers. | `IfNotPresent` | diff --git a/deploy/helm/sumologic/templates/_helpers/_events.tpl b/deploy/helm/sumologic/templates/_helpers/_events.tpl index 8fb68ab56e..92c90204d8 100644 --- a/deploy/helm/sumologic/templates/_helpers/_events.tpl +++ b/deploy/helm/sumologic/templates/_helpers/_events.tpl @@ -138,4 +138,12 @@ otlp {{- else -}} {{- template "kubernetes.defaultAffinity" . -}} {{- end -}} -{{- end -}} \ No newline at end of file +{{- end -}} + +{{- define "sumologic.metadata.name.pvcCleaner.events" -}} +{{- template "sumologic.metadata.name.pvcCleaner" . }}-events +{{- end -}} + +{{- define "sumologic.labels.app.pvcCleaner.events" -}} +{{- template "sumologic.labels.app.pvcCleaner" . }}-events +{{- end -}} diff --git a/deploy/helm/sumologic/templates/pvc-cleaner/configmap.yaml b/deploy/helm/sumologic/templates/pvc-cleaner/configmap.yaml index c0249c4766..a9e6bb34c5 100644 --- a/deploy/helm/sumologic/templates/pvc-cleaner/configmap.yaml +++ b/deploy/helm/sumologic/templates/pvc-cleaner/configmap.yaml @@ -1,4 +1,4 @@ -{{- if or (eq .Values.pvcCleaner.logs.enabled true) (eq .Values.pvcCleaner.metrics.enabled true) }} +{{- if or (eq .Values.pvcCleaner.logs.enabled true) (eq .Values.pvcCleaner.metrics.enabled true) (eq .Values.pvcCleaner.events.enabled true) }} apiVersion: v1 kind: ConfigMap metadata: diff --git a/deploy/helm/sumologic/templates/pvc-cleaner/cron-job-events.yaml b/deploy/helm/sumologic/templates/pvc-cleaner/cron-job-events.yaml new file mode 100644 index 0000000000..6e929967cd --- /dev/null +++ b/deploy/helm/sumologic/templates/pvc-cleaner/cron-job-events.yaml @@ -0,0 +1,71 @@ +{{- if eq .Values.pvcCleaner.events.enabled true }} +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ template "sumologic.metadata.name.pvcCleaner.events" . }} + namespace: {{ template "sumologic.namespace" . }} + labels: + app: {{ template "sumologic.labels.app.pvcCleaner.events" . }} + {{- include "sumologic.labels.common" . | nindent 4 }} +spec: + schedule: {{ .Values.pvcCleaner.job.schedule | quote }} + jobTemplate: + spec: + template: + metadata: + name: {{ template "sumologic.metadata.name.pvcCleaner.events" . }} + labels: + app: {{ template "sumologic.labels.app.pvcCleaner.events" . }} +{{- include "sumologic.labels.common" . | nindent 12 }} +{{- with .Values.sumologic.podLabels }} +{{ toYaml . | indent 12 }} +{{- end }} +{{- with .Values.pvcCleaner.job.podLabels }} +{{ toYaml . | indent 12 }} +{{- end }} + annotations: +{{- with .Values.sumologic.podAnnotations }} +{{ toYaml . | indent 12 }} +{{- end }} +{{- with .Values.pvcCleaner.job.podAnnotations }} +{{ toYaml . | indent 12 }} +{{- end }} + spec: + nodeSelector: +{{- if not (empty (include "pvcCleaner.job.nodeSelector" .)) }} +{{ include "pvcCleaner.job.nodeSelector" . | indent 12 }} +{{- end }} +{{- if not (empty (include "pvcCleaner.job.tolerations" .)) }} + tolerations: +{{ include "pvcCleaner.job.tolerations" . | indent 12 }} +{{- end }} +{{- if not (empty (include "pvcCleaner.job.affinity" .)) }} + affinity: +{{ include "pvcCleaner.job.affinity" . | indent 12 }} +{{- end }} +{{- with .Values.pvcCleaner.job.securityContext }} + securityContext: +{{ toYaml . | indent 12 }} +{{- end }} + containers: + - name: pvc-cleaner + image: {{ .Values.pvcCleaner.job.image.repository }}:{{ .Values.pvcCleaner.job.image.tag }} + command: + - "bash" + - "/pvc-cleaner/pvc-cleaner.sh" + - "{{ template "sumologic.namespace" . }}" + - "app={{ template "sumologic.labels.app.events.statefulset" . }}" + imagePullPolicy: {{ .Values.pvcCleaner.job.image.pullPolicy }} + resources: + {{- toYaml .Values.pvcCleaner.job.resources | nindent 14 }} + volumeMounts: + - name: pvc-cleaner + mountPath: /pvc-cleaner + volumes: + - configMap: + defaultMode: 420 + name: {{ template "sumologic.metadata.name.pvcCleaner.configmap" . }} + name: pvc-cleaner + restartPolicy: Never + serviceAccountName: {{ template "sumologic.metadata.name.pvcCleaner.roles.serviceaccount" . }} +{{- end }} diff --git a/deploy/helm/sumologic/templates/pvc-cleaner/serviceaccount.yaml b/deploy/helm/sumologic/templates/pvc-cleaner/serviceaccount.yaml index ce9c17b1b8..dcb62e3972 100644 --- a/deploy/helm/sumologic/templates/pvc-cleaner/serviceaccount.yaml +++ b/deploy/helm/sumologic/templates/pvc-cleaner/serviceaccount.yaml @@ -1,4 +1,4 @@ -{{- if or (eq .Values.pvcCleaner.logs.enabled true) (eq .Values.pvcCleaner.metrics.enabled true) }} +{{- if or (eq .Values.pvcCleaner.logs.enabled true) (eq .Values.pvcCleaner.metrics.enabled true) (eq .Values.pvcCleaner.events.enabled true) }} apiVersion: v1 kind: ServiceAccount metadata: diff --git a/deploy/helm/sumologic/values.yaml b/deploy/helm/sumologic/values.yaml index 9f007a57d2..e4cc0c0e08 100644 --- a/deploy/helm/sumologic/values.yaml +++ b/deploy/helm/sumologic/values.yaml @@ -2363,6 +2363,8 @@ pvcCleaner: enabled: false logs: enabled: false + events: + enabled: false job: image: diff --git a/tests/helm/testdata/goldenfile/pvc-cleaner/full_config_events.input.yaml b/tests/helm/testdata/goldenfile/pvc-cleaner/full_config_events.input.yaml new file mode 100644 index 0000000000..cc6c0c5d5d --- /dev/null +++ b/tests/helm/testdata/goldenfile/pvc-cleaner/full_config_events.input.yaml @@ -0,0 +1,79 @@ +sumologic: + podLabels: + someSumo: label + podAnnotations: + someSumo: annotation + nodeSelector: + notMy: node + tolerations: + - key: null + operator: NotExists + effect: "TestFail" + affinity: + nodeAffinity: + requiredSomethingDuringSomethingElse: + nodeSelectorTerms: + - matchExpressions: + - key: definitely_not + operator: In + values: + - a-correct-affinity + +pvcCleaner: + events: + enabled: true + job: + image: + repository: private.ecr.aws/sumologic/kubernetes-tools + tag: x.y.z + pullPolicy: Always + pullSecrets: + - name: myRegistryKeySecretName + resources: + limits: + memory: 1025Mi + cpu: 31m + requests: + memory: 63Mi + cpu: 12m + nodeSelector: + my: node + # clean up kubernetes.io/os selector + kubernetes.io/os: null + ## Add custom labels only to setup job pod + + ## Node tolerations for server scheduling to nodes with taints + ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ + ## + tolerations: + - key: null + operator: Exists + effect: "NoSchedule" + + ## Affinity and anti-affinity + ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity + ## + affinity: + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app + operator: In + values: + - RELEASE-NAME-sumologic-otelcol-logs + - RELEASE-NAME-sumologic-otelcol-metrics + - RELEASE-NAME-sumologic-otelcol-events + - key: app + operator: In + values: + - prometheus-operator-prometheus + topologyKey: "kubernetes.io/hostname" + + podLabels: + some: label + ## Add custom annotations only to setup job pod + podAnnotations: + some: annotation + + schedule: "*/2 * * * *" diff --git a/tests/helm/testdata/goldenfile/pvc-cleaner/full_config_events.output.yaml b/tests/helm/testdata/goldenfile/pvc-cleaner/full_config_events.output.yaml new file mode 100644 index 0000000000..16a35a9d5f --- /dev/null +++ b/tests/helm/testdata/goldenfile/pvc-cleaner/full_config_events.output.yaml @@ -0,0 +1,81 @@ +--- +# Source: sumologic/templates/pvc-cleaner/cron-job-events.yaml +apiVersion: batch/v1 +kind: CronJob +metadata: + name: RELEASE-NAME-sumologic-pvc-cleaner-events + namespace: sumologic + labels: + app: pvc-cleaner-events + chart: "sumologic-%CURRENT_CHART_VERSION%" + release: "RELEASE-NAME" + heritage: "Helm" +spec: + schedule: "*/2 * * * *" + jobTemplate: + spec: + template: + metadata: + name: RELEASE-NAME-sumologic-pvc-cleaner-events + labels: + app: pvc-cleaner-events + chart: "sumologic-%CURRENT_CHART_VERSION%" + release: "RELEASE-NAME" + heritage: "Helm" + someSumo: label + some: label + annotations: + someSumo: annotation + some: annotation + spec: + nodeSelector: + kubernetes.io/os: null + my: node + tolerations: + - effect: NoSchedule + key: null + operator: Exists + affinity: + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app + operator: In + values: + - RELEASE-NAME-sumologic-otelcol-logs + - RELEASE-NAME-sumologic-otelcol-metrics + - RELEASE-NAME-sumologic-otelcol-events + - key: app + operator: In + values: + - prometheus-operator-prometheus + topologyKey: kubernetes.io/hostname + securityContext: + runAsUser: 1000 + containers: + - name: pvc-cleaner + image: private.ecr.aws/sumologic/kubernetes-tools:x.y.z + command: + - "bash" + - "/pvc-cleaner/pvc-cleaner.sh" + - "sumologic" + - "app=RELEASE-NAME-sumologic-otelcol-events" + imagePullPolicy: Always + resources: + limits: + cpu: 31m + memory: 1025Mi + requests: + cpu: 12m + memory: 63Mi + volumeMounts: + - name: pvc-cleaner + mountPath: /pvc-cleaner + volumes: + - configMap: + defaultMode: 420 + name: RELEASE-NAME-sumologic-pvc-cleaner + name: pvc-cleaner + restartPolicy: Never + serviceAccountName: RELEASE-NAME-sumologic-pvc-cleaner From 3f77503a5c026f5a02c78fd9a13f8cc6c2dcc66a Mon Sep 17 00:00:00 2001 From: Dominik Rosiek Date: Wed, 3 Apr 2024 09:25:01 +0200 Subject: [PATCH 2/3] chore: changelog Signed-off-by: Dominik Rosiek --- .changelog/3634.added.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 .changelog/3634.added.txt diff --git a/.changelog/3634.added.txt b/.changelog/3634.added.txt new file mode 100644 index 0000000000..fb0f5bb08d --- /dev/null +++ b/.changelog/3634.added.txt @@ -0,0 +1 @@ +feat: add pvcCleaner for events \ No newline at end of file From 5431d98a43ce72affb6cc3ff05680cbe1526ba9b Mon Sep 17 00:00:00 2001 From: Dominik Rosiek Date: Wed, 3 Apr 2024 09:30:19 +0200 Subject: [PATCH 3/3] chore: make format Signed-off-by: Dominik Rosiek --- deploy/helm/sumologic/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/helm/sumologic/README.md b/deploy/helm/sumologic/README.md index 9be3112290..c5178b6dd0 100644 --- a/deploy/helm/sumologic/README.md +++ b/deploy/helm/sumologic/README.md @@ -482,7 +482,7 @@ The following table lists the configurable parameters of the Sumo Logic chart an | `tailing-sidecar-operator.scc.create` | Create OpenShift's Security Context Constraint | `false` | | `pvcCleaner.metrics.enabled` | Flag to enable cleaning unused PVCs for otelcol metrics statefulsets. | `false` | | `pvcCleaner.logs.enabled` | Flag to enable cleaning unused PVCs for otelcol logs statefulsets. | `false` | -| `pvcCleaner.events.enabled` | Flag to enable cleaning unused PVCs for otelcol events statefulsets. | `false` | +| `pvcCleaner.events.enabled` | Flag to enable cleaning unused PVCs for otelcol events statefulsets. | `false` | | `pvcCleaner.job.image.repository` | Image repository for pvcCleaner docker containers. | `public.ecr.aws/sumologic/kubernetes-tools-kubectl` | | `pvcCleaner.job.image.tag` | Image tag for pvcCleaner docker containers. | `2.22.0` | | `pvcCleaner.job.image.pullPolicy` | Image pullPolicy for pvcCleaner docker containers. | `IfNotPresent` |