From 5f8d30ac4c5bea43aa53630728ab3350177886a8 Mon Sep 17 00:00:00 2001 From: Andrey Tatarinov Date: Tue, 25 Jul 2023 02:22:20 +0400 Subject: [PATCH] datapipe 0.2.1 --- charts/datapipe/CHANGELOG.md | 4 + charts/datapipe/Chart.yaml | 2 +- charts/datapipe/templates/loops-cronjob.yaml | 24 ++++-- .../tests/__snapshot__/simple_test.yaml.snap | 78 +++++++++++++++++++ charts/datapipe/tests/simple-values.yaml | 17 ++++ charts/datapipe/tests/simple_test.yaml | 19 +++++ 6 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 charts/datapipe/CHANGELOG.md create mode 100644 charts/datapipe/tests/__snapshot__/simple_test.yaml.snap create mode 100644 charts/datapipe/tests/simple-values.yaml create mode 100644 charts/datapipe/tests/simple_test.yaml diff --git a/charts/datapipe/CHANGELOG.md b/charts/datapipe/CHANGELOG.md new file mode 100644 index 0000000..21ee277 --- /dev/null +++ b/charts/datapipe/CHANGELOG.md @@ -0,0 +1,4 @@ +# 0.2.1 + +* Add support for `.Values.env` to loop-cronjob +* Add unit tests diff --git a/charts/datapipe/Chart.yaml b/charts/datapipe/Chart.yaml index aadc695..8f0197e 100644 --- a/charts/datapipe/Chart.yaml +++ b/charts/datapipe/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.2.0 +version: 0.2.1 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/datapipe/templates/loops-cronjob.yaml b/charts/datapipe/templates/loops-cronjob.yaml index cc4bfe9..5d63bcb 100644 --- a/charts/datapipe/templates/loops-cronjob.yaml +++ b/charts/datapipe/templates/loops-cronjob.yaml @@ -1,8 +1,7 @@ # CronJob template # for each .Values.loops item, create a cronjob -{{ $image := .Values.image }} -{{ $resources := .Values.resources }} -{{ $executor := .Values.executor }} + +{{ $labels := include "datapipe.labels" . }} {{- range .Values.loops }} @@ -10,6 +9,8 @@ apiVersion: batch/v1 kind: CronJob metadata: name: {{ .name }} + labels: + {{- $labels | nindent 4 }} spec: schedule: "{{ .schedule }}" concurrencyPolicy: Forbid @@ -19,7 +20,7 @@ spec: spec: containers: - name: {{ .name }} - image: "{{ $image.repository }}:{{ $image.tag }}" + image: "{{ $.Values.image.repository }}:{{ $.Values.image.tag }}" command: - datapipe - step @@ -28,17 +29,24 @@ spec: {{- end }} {{- if .executor }} - --executor={{ .executor }} - {{- else if $executor }} - - --executor={{ $executor }} + {{- else if $.Values.executor }} + - --executor={{ $.Values.executor }} {{- end }} {{- if .labels }} - --labels={{ .labels }} {{- end }} - run + env: + {{- if $.Values.env }} + {{- $.Values.env | toYaml | nindent 12 }} + {{ end }} + {{- if .env }} + {{- .env | toYaml | nindent 12 }} + {{ end }} {{- if .resources }} resources: {{ .resources | toYaml | nindent 14 }} - {{- else if $resources }} - resources: {{ $resources | toYaml | nindent 14 }} + {{- else if $.Values.resources }} + resources: {{ $.Values.resources | toYaml | nindent 14 }} {{- end }} ports: - name: ray-dash-http diff --git a/charts/datapipe/tests/__snapshot__/simple_test.yaml.snap b/charts/datapipe/tests/__snapshot__/simple_test.yaml.snap new file mode 100644 index 0000000..66752c7 --- /dev/null +++ b/charts/datapipe/tests/__snapshot__/simple_test.yaml.snap @@ -0,0 +1,78 @@ +All manifests should match snapshot: + 1: | + apiVersion: batch/v1 + kind: CronJob + metadata: + labels: + app.kubernetes.io/instance: datapipe + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: datapipe + app.kubernetes.io/version: 1.16.0 + helm.sh/chart: datapipe-0.1.0 + name: loop-hourly + spec: + concurrencyPolicy: Forbid + jobTemplate: + spec: + template: + spec: + containers: + - command: + - datapipe + - step + - --labels=stage=loop-hourly + - run + env: + - name: TEST_ENV + value: test + image: test-datapipe:1.1.1 + name: loop-hourly + ports: + - containerPort: 8265 + name: ray-dash-http + restartPolicy: OnFailure + schedule: 0 * * * * + 2: | + apiVersion: batch/v1 + kind: CronJob + metadata: + labels: + app.kubernetes.io/instance: datapipe + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: datapipe + app.kubernetes.io/version: 1.16.0 + helm.sh/chart: datapipe-0.1.0 + name: loop-daily + spec: + concurrencyPolicy: Forbid + jobTemplate: + spec: + template: + spec: + containers: + - command: + - datapipe + - step + - --labels=stage=loop-daily + - run + env: + - name: TEST_ENV + value: test + image: test-datapipe:1.1.1 + name: loop-daily + ports: + - containerPort: 8265 + name: ray-dash-http + restartPolicy: OnFailure + schedule: 0 0 * * * + 3: | + apiVersion: v1 + kind: ServiceAccount + metadata: + labels: + app.kubernetes.io/instance: datapipe + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: datapipe + app.kubernetes.io/version: 1.16.0 + helm.sh/chart: datapipe-0.1.0 + name: datapipe diff --git a/charts/datapipe/tests/simple-values.yaml b/charts/datapipe/tests/simple-values.yaml new file mode 100644 index 0000000..d565c91 --- /dev/null +++ b/charts/datapipe/tests/simple-values.yaml @@ -0,0 +1,17 @@ +# yaml-language-server: $schema=../values.schema.json + +image: + repository: test-datapipe + tag: 1.1.1 + +env: + - name: TEST_ENV + value: "test" + +loops: + - name: loop-hourly + schedule: "0 * * * *" + labels: "stage=loop-hourly" + - name: loop-daily + schedule: "0 0 * * *" + labels: "stage=loop-daily" diff --git a/charts/datapipe/tests/simple_test.yaml b/charts/datapipe/tests/simple_test.yaml new file mode 100644 index 0000000..a6e98a7 --- /dev/null +++ b/charts/datapipe/tests/simple_test.yaml @@ -0,0 +1,19 @@ +suite: datapipe simple case + +values: + - simple-values.yaml + +chart: + version: 0.1.0 + +release: + name: datapipe + namespace: default + +tests: + - it: All manifests should match snapshot + templates: + - loops-cronjob.yaml + - serviceaccount.yaml + asserts: + - matchSnapshot: {}