From 77f9f1aec1c6abfd6f41c5dd6bd8e1d9c59dd158 Mon Sep 17 00:00:00 2001 From: ashman1984 Date: Thu, 28 Nov 2024 17:27:52 +1030 Subject: [PATCH 1/2] feat conditional volumes on migration pods --- charts/kong/templates/_helpers.tpl | 34 +++++++++++++++++-- .../templates/migrations-post-upgrade.yaml | 4 +-- .../templates/migrations-pre-upgrade.yaml | 4 +-- charts/kong/templates/migrations.yaml | 4 +-- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/charts/kong/templates/_helpers.tpl b/charts/kong/templates/_helpers.tpl index d720e4d7a..b65df7792 100644 --- a/charts/kong/templates/_helpers.tpl +++ b/charts/kong/templates/_helpers.tpl @@ -584,9 +584,33 @@ The name of the Service which will be used by the controller to update the Ingre {{- end -}} +{{- define "kong.migrationPodFilter" -}} +{{ $newList := list }} +{{- range . }} +{{- if or (eq .excludeMigrationPod false) (not (hasKey . "excludeMigrationPod")) }} +{{ $newList = append $newList (omit . "excludeMigrationPod") }} +{{- end }} +{{- end }} +{{ toJson $newList }} +{{- end }} + +{{- define "kong.userDefinedMigrationVolumes" -}} +{{- if .Values.deployment.userDefinedVolumes }} +{{- include "kong.migrationPodFilter" .Values.deployment.userDefinedVolumes | fromJsonArray | toYaml }} +{{- end }} +{{- end -}} + +{{- define "kong.migrationPropertyFilter" -}} +{{ $newList := list }} +{{- range . }} +{{ $newList = append $newList (omit . "excludeMigrationPod") }} +{{- end }} +{{ toJson $newList }} +{{- end }} + {{- define "kong.userDefinedVolumes" -}} {{- if .Values.deployment.userDefinedVolumes }} -{{- toYaml .Values.deployment.userDefinedVolumes }} +{{- include "kong.migrationPropertyFilter" .Values.deployment.userDefinedVolumes | fromJsonArray | toYaml }} {{- end }} {{- end -}} @@ -746,9 +770,15 @@ The name of the Service which will be used by the controller to update the Ingre {{- end -}} {{- end -}} +{{- define "kong.userDefinedMigrationVolumeMounts" -}} +{{- if .userDefinedVolumeMounts }} +{{- include "kong.migrationPodFilter" .userDefinedVolumeMounts | fromJsonArray | toYaml }} +{{- end }} +{{- end -}} + {{- define "kong.userDefinedVolumeMounts" -}} {{- if .userDefinedVolumeMounts }} -{{- toYaml .userDefinedVolumeMounts }} +{{- include "kong.migrationPropertyFilter" .userDefinedVolumeMounts | fromJsonArray | toYaml }} {{- end }} {{- end -}} diff --git a/charts/kong/templates/migrations-post-upgrade.yaml b/charts/kong/templates/migrations-post-upgrade.yaml index 73225392c..39230745b 100644 --- a/charts/kong/templates/migrations-post-upgrade.yaml +++ b/charts/kong/templates/migrations-post-upgrade.yaml @@ -72,7 +72,7 @@ spec: args: [ "kong", "migrations", "finish" ] volumeMounts: {{- include "kong.volumeMounts" . | nindent 8 }} - {{- include "kong.userDefinedVolumeMounts" .Values.deployment | nindent 8 }} + {{- include "kong.userDefinedMigrationVolumeMounts" .Values.deployment | nindent 8 }} resources: {{- toYaml .Values.migrations.resources | nindent 10 }} securityContext: @@ -92,6 +92,6 @@ spec: restartPolicy: OnFailure volumes: {{- include "kong.volumes" . | nindent 6 -}} - {{- include "kong.userDefinedVolumes" . | nindent 6 -}} + {{- include "kong.userDefinedMigrationVolumes" . | nindent 6 -}} {{- end }} {{- end }} diff --git a/charts/kong/templates/migrations-pre-upgrade.yaml b/charts/kong/templates/migrations-pre-upgrade.yaml index 9efb8baea..7fb8fa387 100644 --- a/charts/kong/templates/migrations-pre-upgrade.yaml +++ b/charts/kong/templates/migrations-pre-upgrade.yaml @@ -74,7 +74,7 @@ spec: args: [ "kong", "migrations", "up" ] volumeMounts: {{- include "kong.volumeMounts" . | nindent 8 }} - {{- include "kong.userDefinedVolumeMounts" .Values.deployment | nindent 8 }} + {{- include "kong.userDefinedMigrationVolumeMounts" .Values.deployment | nindent 8 }} resources: {{- toYaml .Values.migrations.resources| nindent 10 }} securityContext: @@ -94,6 +94,6 @@ spec: restartPolicy: OnFailure volumes: {{- include "kong.volumes" . | nindent 6 -}} - {{- include "kong.userDefinedVolumes" . | nindent 6 -}} + {{- include "kong.userDefinedMigrationVolumes" . | nindent 6 -}} {{- end }} {{- end }} diff --git a/charts/kong/templates/migrations.yaml b/charts/kong/templates/migrations.yaml index e1a85fb90..1bab74385 100644 --- a/charts/kong/templates/migrations.yaml +++ b/charts/kong/templates/migrations.yaml @@ -82,7 +82,7 @@ spec: args: [ "kong", "migrations", "bootstrap" ] volumeMounts: {{- include "kong.volumeMounts" . | nindent 8 }} - {{- include "kong.userDefinedVolumeMounts" .Values.deployment | nindent 8 }} + {{- include "kong.userDefinedMigrationVolumeMounts" .Values.deployment | nindent 8 }} resources: {{- toYaml .Values.migrations.resources | nindent 10 }} securityContext: @@ -102,7 +102,7 @@ spec: restartPolicy: OnFailure volumes: {{- include "kong.volumes" . | nindent 6 -}} - {{- include "kong.userDefinedVolumes" . | nindent 6 -}} + {{- include "kong.userDefinedMigrationVolumes" . | nindent 6 -}} {{- end }} {{- end }} {{- end }} From 960e51b3e5d2dc0832bf05122dc957e803beb482 Mon Sep 17 00:00:00 2001 From: ashman1984 Date: Fri, 29 Nov 2024 14:15:14 +1030 Subject: [PATCH 2/2] update changelog + values --- charts/kong/CHANGELOG.md | 1 + charts/kong/values.yaml | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/charts/kong/CHANGELOG.md b/charts/kong/CHANGELOG.md index d99c8f63f..81a9d490b 100644 --- a/charts/kong/CHANGELOG.md +++ b/charts/kong/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased * Added serviceMonitor.trustCRDsExist for render based deployments +* Add support for `excludeMigrationPod` to userDefinedVolumes and userDefinedVolumeMounts ### Changes diff --git a/charts/kong/values.yaml b/charts/kong/values.yaml index 30b538374..ece8d75cb 100644 --- a/charts/kong/values.yaml +++ b/charts/kong/values.yaml @@ -57,6 +57,28 @@ deployment: # userDefinedVolumeMounts: # - name: "volumeName" # mountPath: "/opt/user/dir/mount" + + ## userDefinedVolumes & userDefinedVolumeMounts can be specified with excludeMigrationPod which disables adding the volumes and mounts to migration pods + # userDefinedVolumes: + # - name: "volumeNameAlways" + # emptyDir: { } + # - name: "volumeNameNever" + # excludeMigrationPod: true + # emptyDir: {} + # - name: "volumeNameYes" + # excludeMigrationPod: false + # persistentVolumeClaim: + # claimName: "my_claim" + # userDefinedVolumeMounts: + # - name: "volumeNameAlways" + # mountPath: "/opt/user/dir/mountAlways" + # - name: "volumeNameNever" + # excludeMigrationPod: true + # mountPath: "/opt/user/dir/volumeNameNever" + # - name: "volumeNameYes" + # excludeMigrationPod: false + # mountPath: "/opt/user/dir/volumeNameYes" + test: # Enable creation of test resources for use with "helm test" enabled: false