From 2ed5c41ddd46d2adca9fea407eb48ac0bbdd6020 Mon Sep 17 00:00:00 2001 From: smerle33 Date: Mon, 25 Nov 2024 17:37:44 +0100 Subject: [PATCH] feat(geoipupdater): provide a cronjob for update geoip --- charts/geoipupdates/Chart.yaml | 2 +- charts/geoipupdates/templates/cronjob.yaml | 62 ++++++++++++++++ charts/geoipupdates/templates/deployment.yaml | 74 ------------------- charts/geoipupdates/tests/defaults_test.yaml | 35 ++++----- charts/geoipupdates/values.yaml | 1 + 5 files changed, 80 insertions(+), 94 deletions(-) create mode 100644 charts/geoipupdates/templates/cronjob.yaml delete mode 100644 charts/geoipupdates/templates/deployment.yaml diff --git a/charts/geoipupdates/Chart.yaml b/charts/geoipupdates/Chart.yaml index cfda2d6bf..289f9051b 100644 --- a/charts/geoipupdates/Chart.yaml +++ b/charts/geoipupdates/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v1 description: MaxMind GeoIP database updater name: geoipupdates -version: 0.1.0 +version: 1.0.0 appVersion: "v7.1.0" maintainers: - email: jenkins-infra-team@googlegroups.com diff --git a/charts/geoipupdates/templates/cronjob.yaml b/charts/geoipupdates/templates/cronjob.yaml new file mode 100644 index 000000000..aaf76c1d6 --- /dev/null +++ b/charts/geoipupdates/templates/cronjob.yaml @@ -0,0 +1,62 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ include "geoipupdate.fullname" . }} + labels: +{{ include "geoipupdate.labels" . | indent 4 }} +spec: + concurrencyPolicy: Forbid + schedule: {{ .Values.geoipupdate.cron }} + jobTemplate: + spec: + template: + spec: + serviceAccountName: {{ include "geoipupdate.fullname" . }} + restartPolicy: Never + containers: + - name: geoipupdate + image: "{{ .Values.image }}:{{ .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.imagePullPolicy }} + {{- with .Values.containerSecurityContext }} + securityContext: + {{- toYaml . | nindent 16 }} + {{- end }} + volumeMounts: + - name: geoipdata + mountPath: /usr/share/GeoIP + readOnly: false + - name: tmpdir + mountPath: /tmp + readOnly: false + resources: + {{- toYaml .Values.resources | nindent 16 }} + env: + - name: GEOIPUPDATE_EDITION_IDS + value: {{ .Values.geoipupdate.editions }} + - name: GEOIPUPDATE_FREQUENCY + value: {{ .Values.geoipupdate.update_frequency | quote }} + envFrom: + - secretRef: + name: {{ include "geoipupdate.fullname" . }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 12 }} + {{- end }} + volumes: + - name: geoipdata + {{- if .Values.dataVolume }} + {{- toYaml .Values.dataVolume | nindent 14 }} + {{- else }} + emptyDir: {} + {{- end }} + - name: tmpdir + emptyDir: + medium: "Memory" diff --git a/charts/geoipupdates/templates/deployment.yaml b/charts/geoipupdates/templates/deployment.yaml deleted file mode 100644 index 9e482a44f..000000000 --- a/charts/geoipupdates/templates/deployment.yaml +++ /dev/null @@ -1,74 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "geoipupdate.fullname" . }} - labels: -{{ include "geoipupdate.labels" . | indent 4 }} -spec: - replicas: 1 # Do not scale up or you will run in trouble - selector: - matchLabels: -{{ include "geoipupdate.selectorLabels" . | indent 6 }} - template: - metadata: - labels: -{{ include "geoipupdate.selectorLabels" . | indent 8 }} - spec: - automountServiceAccountToken: false - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.podSecurityContext }} - securityContext: - {{- toYaml . | nindent 8 }} - {{- end }} - containers: - - name: geoipupdate - image: "{{ .Values.image }}:{{ .Chart.AppVersion }}" - imagePullPolicy: {{ .Values.imagePullPolicy }} - {{- with .Values.containerSecurityContext }} - securityContext: - {{- toYaml . | nindent 12 }} - {{- end }} - volumeMounts: - - name: geoipdata - mountPath: /usr/share/GeoIP - readOnly: false - - name: tmpdir - mountPath: /tmp - readOnly: false - resources: - {{- toYaml .Values.resources | nindent 12 }} - env: - - name: GEOIPUPDATE_EDITION_IDS - value: {{ .Values.geoipupdate.editions }} - - name: GEOIPUPDATE_FREQUENCY - value: {{ .Values.geoipupdate.update_frequency | quote }} - envFrom: - - secretRef: - name: {{ include "geoipupdate.fullname" . }} - {{- 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: geoipdata - {{- if .Values.dataVolume }} - {{- toYaml .Values.dataVolume | nindent 10 }} - {{- else }} - emptyDir: {} - {{- end }} - - name: tmpdir - emptyDir: - medium: "Memory" -... diff --git a/charts/geoipupdates/tests/defaults_test.yaml b/charts/geoipupdates/tests/defaults_test.yaml index ad56a7bbd..49b405d39 100644 --- a/charts/geoipupdates/tests/defaults_test.yaml +++ b/charts/geoipupdates/tests/defaults_test.yaml @@ -1,52 +1,49 @@ suite: default tests templates: - - deployment.yaml + - cronjob.yaml tests: - - it: should define the default "mirrorbits" deployment with default imagePullPolicy and metadata labels - template: deployment.yaml + - it: should define the default "geoipupdate" cronjob with default imagePullPolicy and metadata labels + template: cronjob.yaml asserts: - hasDocuments: count: 1 - isKind: - of: Deployment + of: CronJob - equal: - path: spec.template.metadata.labels["app.kubernetes.io/name"] + path: metadata.labels["app.kubernetes.io/name"] value: "geoipupdate" - equal: - path: spec.template.metadata.labels["app.kubernetes.io/instance"] + path: metadata.labels["app.kubernetes.io/instance"] value: "RELEASE-NAME" - equal: - path: "spec.template.spec.containers[*].imagePullPolicy" + path: "spec.jobTemplate.spec.template.spec.containers[*].imagePullPolicy" value: IfNotPresent - - equal: - path: spec.replicas - value: 1 # GeoIP is an emptyDir, with default mountpath - equal: - path: spec.template.spec.volumes[0].name + path: spec.jobTemplate.spec.template.spec.volumes[0].name value: geoipdata - equal: - path: spec.template.spec.volumes[0].emptyDir + path: spec.jobTemplate.spec.template.spec.volumes[0].emptyDir value: {} - equal: - path: spec.template.spec.containers[0].volumeMounts[0].name + path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[0].name value: geoipdata - equal: - path: spec.template.spec.containers[0].volumeMounts[0].mountPath + path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[0].mountPath value: /usr/share/GeoIP - equal: - path: spec.template.spec.containers[0].volumeMounts[0].readOnly + path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[0].readOnly value: false # Env. variables - equal: - path: spec.template.spec.containers[0].env[0].name + path: spec.jobTemplate.spec.template.spec.containers[0].env[0].name value: GEOIPUPDATE_EDITION_IDS - equal: - path: spec.template.spec.containers[0].env[0].value + path: spec.jobTemplate.spec.template.spec.containers[0].env[0].value value: GeoLite2-ASN GeoLite2-City GeoLite2-Country - equal: - path: spec.template.spec.containers[0].env[1].name + path: spec.jobTemplate.spec.template.spec.containers[0].env[1].name value: GEOIPUPDATE_FREQUENCY - equal: - path: spec.template.spec.containers[0].env[1].value + path: spec.jobTemplate.spec.template.spec.containers[0].env[1].value value: "24" diff --git a/charts/geoipupdates/values.yaml b/charts/geoipupdates/values.yaml index 538ebb86e..4fc5a1f94 100644 --- a/charts/geoipupdates/values.yaml +++ b/charts/geoipupdates/values.yaml @@ -8,6 +8,7 @@ geoipupdate: license_key: "" editions: GeoLite2-ASN GeoLite2-City GeoLite2-Country update_frequency: 24 + cron: '0 4 * * *' # default to every day at 4AM podSecurityContext: {} # fsGroup: 2000 containerSecurityContext: {}