From 0b528b4c557d7854317284cd5dbab8ee53da5477 Mon Sep 17 00:00:00 2001 From: Wojciech Suszko Date: Mon, 27 May 2024 22:35:53 +0200 Subject: [PATCH 1/7] introduce persistentVolumeClaimRetentionPolicy field in Prometheus operator Signed-off-by: Wojciech Suszko --- charts/kube-prometheus-stack/Chart.yaml | 2 +- charts/kube-prometheus-stack/templates/_helpers.tpl | 4 ++++ .../templates/prometheus/prometheus.yaml | 5 +++++ charts/kube-prometheus-stack/values.yaml | 9 +++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/charts/kube-prometheus-stack/Chart.yaml b/charts/kube-prometheus-stack/Chart.yaml index 9aaefc90b7a2..8feb7d1bd4d5 100644 --- a/charts/kube-prometheus-stack/Chart.yaml +++ b/charts/kube-prometheus-stack/Chart.yaml @@ -23,7 +23,7 @@ name: kube-prometheus-stack sources: - https://github.com/prometheus-community/helm-charts - https://github.com/prometheus-operator/kube-prometheus -version: 58.7.2 +version: 58.7.3 appVersion: v0.73.2 kubeVersion: ">=1.19.0-0" home: https://github.com/prometheus-operator/kube-prometheus diff --git a/charts/kube-prometheus-stack/templates/_helpers.tpl b/charts/kube-prometheus-stack/templates/_helpers.tpl index 3bd3bc87690b..8015a6b410a0 100644 --- a/charts/kube-prometheus-stack/templates/_helpers.tpl +++ b/charts/kube-prometheus-stack/templates/_helpers.tpl @@ -318,3 +318,7 @@ global: {{ $fullname }}-webhook.{{ $namespace }}.svc {{- end }} {{- end }} + +{{- define "kube-prometheus-stack.operator.kubeVersion" -}} + {{- default .Capabilities.KubeVersion.Version (regexFind "v[0-9]+\\.[0-9]+\\.[0-9]+" .Capabilities.KubeVersion.Version) -}} +{{- end -}} \ No newline at end of file diff --git a/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml b/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml index 39b9a327bd71..9558a1782aa4 100644 --- a/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml +++ b/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml @@ -261,6 +261,11 @@ spec: storage: {{ tpl (toYaml .Values.prometheus.prometheusSpec.storageSpec | indent 4) . }} {{- end }} +{{- if semverCompare ">= 1.27.0" (include "kube-prometheus-stack.operator.kubeVersion" .) }} + persistentVolumeClaimRetentionPolicy: + whenDeleted: {{ ternary "Delete" "Retain" .Values.prometheusOperator.statefulSet.pvcDeleteOnStsDelete }} + whenScaled: {{ ternary "Delete" "Retain" .Values.prometheusOperator.statefulSet.pvcDeleteOnStsScale }} +{{- end }} {{- if .Values.prometheus.prometheusSpec.podMetadata }} podMetadata: {{ tpl (toYaml .Values.prometheus.prometheusSpec.podMetadata | indent 4) . }} diff --git a/charts/kube-prometheus-stack/values.yaml b/charts/kube-prometheus-stack/values.yaml index fa00232ae0ce..de4455df1e10 100644 --- a/charts/kube-prometheus-stack/values.yaml +++ b/charts/kube-prometheus-stack/values.yaml @@ -2884,6 +2884,15 @@ prometheusOperator: ## automountServiceAccountToken: true + ## Statefulset's persistent volume claim retention policy + ## pvcDeleteOnStsDelete and pvcDeleteOnStsScale determine whether + ## statefulset's PVCs are deleted (true) or retained (false) on scaling down + ## and deleting statefulset, respectively. Requires 1.27.0+. + ## Ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#persistentvolumeclaim-retention + statefulSet: + pvcDeleteOnStsDelete: false + pvcDeleteOnStsScale: false + ## Additional volumes ## extraVolumes: [] From 953e1c5136e9c8b89e0edb89dcb2003f555377dc Mon Sep 17 00:00:00 2001 From: Wojciech Suszko Date: Mon, 27 May 2024 23:03:30 +0200 Subject: [PATCH 2/7] add newline at the end of helpers, as per convention Signed-off-by: Wojciech Suszko --- charts/kube-prometheus-stack/templates/_helpers.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/kube-prometheus-stack/templates/_helpers.tpl b/charts/kube-prometheus-stack/templates/_helpers.tpl index 8015a6b410a0..edd792e10237 100644 --- a/charts/kube-prometheus-stack/templates/_helpers.tpl +++ b/charts/kube-prometheus-stack/templates/_helpers.tpl @@ -321,4 +321,4 @@ global: {{- define "kube-prometheus-stack.operator.kubeVersion" -}} {{- default .Capabilities.KubeVersion.Version (regexFind "v[0-9]+\\.[0-9]+\\.[0-9]+" .Capabilities.KubeVersion.Version) -}} -{{- end -}} \ No newline at end of file +{{- end -}} From 7d9471187102a19bd7fd9592311090ee4625c7e4 Mon Sep 17 00:00:00 2001 From: Wojciech Suszko Date: Mon, 27 May 2024 23:20:35 +0200 Subject: [PATCH 3/7] fix semver Signed-off-by: Wojciech Suszko --- charts/kube-prometheus-stack/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/kube-prometheus-stack/Chart.yaml b/charts/kube-prometheus-stack/Chart.yaml index 8feb7d1bd4d5..df29792b1cfc 100644 --- a/charts/kube-prometheus-stack/Chart.yaml +++ b/charts/kube-prometheus-stack/Chart.yaml @@ -23,7 +23,7 @@ name: kube-prometheus-stack sources: - https://github.com/prometheus-community/helm-charts - https://github.com/prometheus-operator/kube-prometheus -version: 58.7.3 +version: 58.8.2 appVersion: v0.73.2 kubeVersion: ">=1.19.0-0" home: https://github.com/prometheus-operator/kube-prometheus From ec2044149491fe87e8f4f14c2856d289b3c9c5aa Mon Sep 17 00:00:00 2001 From: Wojciech Suszko Date: Tue, 28 May 2024 23:12:17 +0200 Subject: [PATCH 4/7] improve code as per PR suggestions Signed-off-by: Wojciech Suszko --- charts/kube-prometheus-stack/Chart.yaml | 2 +- .../templates/_helpers.tpl | 4 ---- .../templates/prometheus/prometheus.yaml | 5 ++--- charts/kube-prometheus-stack/values.yaml | 18 +++++++++--------- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/charts/kube-prometheus-stack/Chart.yaml b/charts/kube-prometheus-stack/Chart.yaml index df29792b1cfc..8d548d961874 100644 --- a/charts/kube-prometheus-stack/Chart.yaml +++ b/charts/kube-prometheus-stack/Chart.yaml @@ -23,7 +23,7 @@ name: kube-prometheus-stack sources: - https://github.com/prometheus-community/helm-charts - https://github.com/prometheus-operator/kube-prometheus -version: 58.8.2 +version: 59.1.0 appVersion: v0.73.2 kubeVersion: ">=1.19.0-0" home: https://github.com/prometheus-operator/kube-prometheus diff --git a/charts/kube-prometheus-stack/templates/_helpers.tpl b/charts/kube-prometheus-stack/templates/_helpers.tpl index edd792e10237..3bd3bc87690b 100644 --- a/charts/kube-prometheus-stack/templates/_helpers.tpl +++ b/charts/kube-prometheus-stack/templates/_helpers.tpl @@ -318,7 +318,3 @@ global: {{ $fullname }}-webhook.{{ $namespace }}.svc {{- end }} {{- end }} - -{{- define "kube-prometheus-stack.operator.kubeVersion" -}} - {{- default .Capabilities.KubeVersion.Version (regexFind "v[0-9]+\\.[0-9]+\\.[0-9]+" .Capabilities.KubeVersion.Version) -}} -{{- end -}} diff --git a/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml b/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml index 9558a1782aa4..ae95fd02a42c 100644 --- a/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml +++ b/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml @@ -261,10 +261,9 @@ spec: storage: {{ tpl (toYaml .Values.prometheus.prometheusSpec.storageSpec | indent 4) . }} {{- end }} -{{- if semverCompare ">= 1.27.0" (include "kube-prometheus-stack.operator.kubeVersion" .) }} +{{- with .Values.prometheus.prometheusSpec.persistentVolumeClaimRetentionPolicy }} persistentVolumeClaimRetentionPolicy: - whenDeleted: {{ ternary "Delete" "Retain" .Values.prometheusOperator.statefulSet.pvcDeleteOnStsDelete }} - whenScaled: {{ ternary "Delete" "Retain" .Values.prometheusOperator.statefulSet.pvcDeleteOnStsScale }} + {{- toYaml . | nindent 4 }} {{- end }} {{- if .Values.prometheus.prometheusSpec.podMetadata }} podMetadata: diff --git a/charts/kube-prometheus-stack/values.yaml b/charts/kube-prometheus-stack/values.yaml index de4455df1e10..c12824f329b3 100644 --- a/charts/kube-prometheus-stack/values.yaml +++ b/charts/kube-prometheus-stack/values.yaml @@ -2884,15 +2884,6 @@ prometheusOperator: ## automountServiceAccountToken: true - ## Statefulset's persistent volume claim retention policy - ## pvcDeleteOnStsDelete and pvcDeleteOnStsScale determine whether - ## statefulset's PVCs are deleted (true) or retained (false) on scaling down - ## and deleting statefulset, respectively. Requires 1.27.0+. - ## Ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#persistentvolumeclaim-retention - statefulSet: - pvcDeleteOnStsDelete: false - pvcDeleteOnStsScale: false - ## Additional volumes ## extraVolumes: [] @@ -3374,6 +3365,15 @@ prometheus: ## ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#prometheusspec ## prometheusSpec: + ## Statefulset's persistent volume claim retention policy + ## pvcDeleteOnStsDelete and pvcDeleteOnStsScale determine whether + ## statefulset's PVCs are deleted (true) or retained (false) on scaling down + ## and deleting statefulset, respectively. Requires 1.27.0+. + ## Ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#persistentvolumeclaim-retention + persistentVolumeClaimRetentionPolicy: + # whenDeleted: Retain + # whenScaled: Retain + ## If true, pass --storage.tsdb.max-block-duration=2h to prometheus. This is already done if using Thanos ## disableCompaction: false From 9da6d5b0748a41c7384e1f1e26902ff4f608ac88 Mon Sep 17 00:00:00 2001 From: Wojciech Suszko Date: Tue, 28 May 2024 23:25:56 +0200 Subject: [PATCH 5/7] add empty value as default to values.yaml Signed-off-by: Wojciech Suszko --- charts/kube-prometheus-stack/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/kube-prometheus-stack/values.yaml b/charts/kube-prometheus-stack/values.yaml index c12824f329b3..54d0acf561e1 100644 --- a/charts/kube-prometheus-stack/values.yaml +++ b/charts/kube-prometheus-stack/values.yaml @@ -3370,7 +3370,7 @@ prometheus: ## statefulset's PVCs are deleted (true) or retained (false) on scaling down ## and deleting statefulset, respectively. Requires 1.27.0+. ## Ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#persistentvolumeclaim-retention - persistentVolumeClaimRetentionPolicy: + persistentVolumeClaimRetentionPolicy: {} # whenDeleted: Retain # whenScaled: Retain From cf33303567c1e2ef4988e625ab759257edf1ce2b Mon Sep 17 00:00:00 2001 From: Wojciech Suszko Date: Wed, 29 May 2024 17:02:19 +0200 Subject: [PATCH 6/7] remove trailing spaces Signed-off-by: Wojciech Suszko --- charts/kube-prometheus-stack/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/kube-prometheus-stack/values.yaml b/charts/kube-prometheus-stack/values.yaml index 54d0acf561e1..384d5cac87cc 100644 --- a/charts/kube-prometheus-stack/values.yaml +++ b/charts/kube-prometheus-stack/values.yaml @@ -3373,7 +3373,7 @@ prometheus: persistentVolumeClaimRetentionPolicy: {} # whenDeleted: Retain # whenScaled: Retain - + ## If true, pass --storage.tsdb.max-block-duration=2h to prometheus. This is already done if using Thanos ## disableCompaction: false From ac71f7f5749d5860cbce6cfa7f00c9fd6c49eba6 Mon Sep 17 00:00:00 2001 From: Wojciech Suszko Date: Fri, 31 May 2024 16:06:59 +0200 Subject: [PATCH 7/7] remove trailing spaces Signed-off-by: Wojciech Suszko --- charts/kube-prometheus-stack/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/kube-prometheus-stack/values.yaml b/charts/kube-prometheus-stack/values.yaml index 384d5cac87cc..5dd92fbd3803 100644 --- a/charts/kube-prometheus-stack/values.yaml +++ b/charts/kube-prometheus-stack/values.yaml @@ -3373,7 +3373,7 @@ prometheus: persistentVolumeClaimRetentionPolicy: {} # whenDeleted: Retain # whenScaled: Retain - + ## If true, pass --storage.tsdb.max-block-duration=2h to prometheus. This is already done if using Thanos ## disableCompaction: false