Skip to content

Commit

Permalink
move clean up cr job to operator chart (#593)
Browse files Browse the repository at this point in the history
* move clean up cr hook to operator

* bump operator chart version

* keep previous behaviour for `cleanupCRD` in operator chart

* add changelog

---------

Co-authored-by: Nikolay <[email protected]>
  • Loading branch information
Haleygo and f41gh7 authored Aug 23, 2023
1 parent 448bc1b commit ab04561
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 28 deletions.
1 change: 1 addition & 0 deletions charts/victoria-metrics-k8s-stack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
![AppVersion: **APP_VERSION**](https://img.shields.io/static/v1?label=AppVersion&message=**APP_VERSION**&color=success&logo=)
![Helm: v3](https://img.shields.io/static/v1?label=Helm&message=v3&color=informational&logo=helm)

* Move `cleanupCRD` option to victoria-metrics-operator chart (#593)
* Disable `honorTimestamps` for cadvisor scrape job by default (#617)

## 0.17.5
Expand Down
8 changes: 0 additions & 8 deletions charts/victoria-metrics-k8s-stack/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ Create the name of the service account to use
{{- end }}
{{- end }}

{{/*
Create the name of service account and clusterRole for cleanup-hook
*/}}
{{- define "victoria-metrics-k8s-stack.cleanupHookName" -}}
{{- printf "%s-%s" (include "victoria-metrics-k8s-stack.fullname" .) "cleanup-hook" | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}


{{/*
Create the name for VMSingle
*/}}
Expand Down
2 changes: 1 addition & 1 deletion charts/victoria-metrics-k8s-stack/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ argocdReleaseOverride: ""
# -- also checkout here possible ENV variables to configure operator behaviour https://docs.victoriametrics.com/operator/vars.html
victoria-metrics-operator:
enabled: true
# -- Tells helm to remove CRD after chart remove
# -- Tells helm to clean up vm cr resources when uninstalling
cleanupCRD: true
cleanupImage:
repository: gcr.io/google_containers/hyperkube
Expand Down
3 changes: 2 additions & 1 deletion charts/victoria-metrics-operator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
![Helm: v3](https://img.shields.io/static/v1?label=Helm&message=v3&color=informational&logo=helm)

* Added `topologySpreadConstraints` for the operator + a small refactoring (#611)
* fix vm operator appVersion (#589)
* Fix vm operator appVersion (#589)
* Fixes operator doc description
* Add `cleanupCRD` option to clean up vm cr resources when uninstalling (#593)

## 0.24.1

Expand Down
7 changes: 7 additions & 0 deletions charts/victoria-metrics-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ Create unified labels for vm-operator components
helm.sh/chart: {{ include "vm-operator.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Create the name of service account and clusterRole for cleanup-hook
*/}}
{{- define "vm-operator.cleanupHookName" -}}
{{- printf "%s-%s" (include "vm-operator.fullname" .) "cleanup-hook" | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": hook-succeeded
{{- end }}
{{- if (index .Values "victoria-metrics-operator" "enabled") }}
{{- if (index .Values "victoria-metrics-operator" "cleanupCRD") }}
{{- if .Values.cleanupCRD }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "victoria-metrics-k8s-stack.cleanupHookName" . }}
name: {{ include "vm-operator.cleanupHookName" . }}
namespace: {{ .Release.Namespace }}
labels: {{ include "victoria-metrics-k8s-stack.labels" . | nindent 4 }}
labels: {{ include "vm-operator.labels" . | nindent 4 }}
annotations: {{ include "cleanupHookName.annotations" . | nindent 4 }}
spec:
template:
metadata:
name: "{{ .Release.Name }}"
labels: {{ include "victoria-metrics-k8s-stack.labels" . | nindent 8 }}
labels: {{ include "vm-operator.labels" . | nindent 8 }}
spec:
serviceAccountName: {{ include "victoria-metrics-k8s-stack.cleanupHookName" . }}
serviceAccountName: {{ include "vm-operator.cleanupHookName" . }}
containers:
- name: kubectl
image: "{{ (index .Values "victoria-metrics-operator" "cleanupImage" "repository") }}:{{ (index .Values "victoria-metrics-operator" "cleanupImage" "tag") }}"
imagePullPolicy: "{{ (index .Values "victoria-metrics-operator" "cleanupImage" "pullPolicy") }}"
image: "{{ (index .Values "cleanupImage" "repository") }}:{{ (index .Values "cleanupImage" "tag") }}"
imagePullPolicy: "{{ (index .Values "cleanupImage" "pullPolicy") }}"
resources:
limits:
cpu: "500m"
Expand Down Expand Up @@ -56,33 +55,33 @@ spec:
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "victoria-metrics-k8s-stack.cleanupHookName" . }}
name: {{ include "vm-operator.cleanupHookName" . }}
namespace: {{ .Release.Namespace }}
labels: {{- include "victoria-metrics-k8s-stack.labels" . | nindent 4 }}
labels: {{- include "vm-operator.labels" . | nindent 4 }}
annotations: {{ include "cleanupHookName.annotations" . | nindent 4 }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "victoria-metrics-k8s-stack.cleanupHookName" . }}
name: {{ include "vm-operator.cleanupHookName" . }}
namespace: {{ .Release.Namespace }}
labels: {{- include "victoria-metrics-k8s-stack.labels" . | nindent 4 }}
labels: {{- include "vm-operator.labels" . | nindent 4 }}
annotations: {{ include "cleanupHookName.annotations" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "victoria-metrics-k8s-stack.cleanupHookName" . }}
name: {{ include "vm-operator.cleanupHookName" . }}
subjects:
- kind: ServiceAccount
name: {{ include "victoria-metrics-k8s-stack.cleanupHookName" . }}
name: {{ include "vm-operator.cleanupHookName" . }}
namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "victoria-metrics-k8s-stack.cleanupHookName" . }}
name: {{ include "vm-operator.cleanupHookName" . }}
namespace: {{ .Release.Namespace }}
labels: {{- include "victoria-metrics-k8s-stack.labels" . | nindent 4 }}
labels: {{- include "vm-operator.labels" . | nindent 4 }}
annotations: {{ include "cleanupHookName.annotations" . | nindent 4 }}
rules:
- apiGroups: ["operator.victoriametrics.com"]
Expand All @@ -95,4 +94,4 @@ rules:
verbs: ["get", "list", "watch","delete"]
---
{{- end }}
{{- end }}

9 changes: 8 additions & 1 deletion charts/victoria-metrics-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ image:
# -- with this option, if you remove this chart, all crd resources will be deleted with it.
createCRD: true

# -- Tells helm to clean up vm cr resources when uninstalling
cleanupCRD: false
cleanupImage:
repository: gcr.io/google_containers/hyperkube
tag: v1.18.0
pullPolicy: IfNotPresent

replicaCount: 1

# -- Secret to pull images
Expand Down Expand Up @@ -59,7 +66,7 @@ operator:
useCustomConfigReloader: false

# By default, the operator will watch all the namespaces
# If you want to override this behavior, specify the namespace.
# If you want to override this behavior, specify the namespace.
# Operator supports only single namespace for watching.
watchNamespace: ""

Expand Down

0 comments on commit ab04561

Please sign in to comment.