Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[velero] Refactoring labels and annotations #281

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/velero/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
appVersion: 1.7.1
description: A Helm chart for velero
name: velero
version: 2.27.1
version: 2.28.0
home: https://github.com/vmware-tanzu/velero
icon: https://cdn-images-1.medium.com/max/1600/1*-9mb3AKnKdcL_QD3CMnthQ.png
sources:
Expand Down
25 changes: 25 additions & 0 deletions charts/velero/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@ Create the name of the service account to use for creating or deleting the veler
{{- end -}}
{{- end -}}

{{/*
Generate basic labels
*/}}
{{- define "velero.labels" }}
helm.sh/chart: {{ include "velero.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/component: server
app.kubernetes.io/part-of: {{ template "velero.name" . }}
nlamirault marked this conversation as resolved.
Show resolved Hide resolved
{{- include "velero.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
nlamirault marked this conversation as resolved.
Show resolved Hide resolved
{{- if .Values.customLabels }}
{{ toYaml .Values.customLabels }}
{{- end }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "velero.selectorLabels" }}
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
nlamirault marked this conversation as resolved.
Show resolved Hide resolved

{{/*
Create the name for the credentials secret.
*/}}
Expand Down
8 changes: 4 additions & 4 deletions charts/velero/templates/backupstoragelocation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ metadata:
annotations:
"helm.sh/hook": post-install,post-upgrade,post-rollback
"helm.sh/hook-delete-policy": before-hook-creation
{{- with .Values.customAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
{{- include "velero.labels" . | indent 4 }}
spec:
provider: {{ include "velero.backupStorageLocation.provider" . }}
{{- with .Values.configuration.backupStorageLocation.default }}
Expand Down
20 changes: 13 additions & 7 deletions charts/velero/templates/cleanup-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,29 @@ metadata:
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-delete-policy": hook-succeeded
{{- with .Values.customAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
{{- include "velero.labels" . | indent 4 }}
spec:
backoffLimit: 3
template:
metadata:
name: velero-cleanup-crds
{{- with .Values.kubectl.labels }}
labels:
{{- include "velero.labels" . | indent 8 }}
{{- with .Values.kubectl.labels }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.kubectl.annotations }}
{{- end }}
{{- if or .Values.kubectl.annotations .Values.customAnnotations }}
annotations:
{{- with .Values.kubectl.annotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.customAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
spec:
{{- if .Values.image.imagePullSecrets }}
Expand Down
10 changes: 5 additions & 5 deletions charts/velero/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "velero.fullname" . }}-server
{{- if .Values.customAnnotations }}
annotations:
{{- toYaml .Values.customAnnotations | nindent 4 }}
{{- end }}
labels:
app.kubernetes.io/component: server
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
{{- include "velero.labels" . | indent 4 }}
subjects:
- kind: ServiceAccount
namespace: {{ .Release.Namespace }}
Expand Down
9 changes: 5 additions & 4 deletions charts/velero/templates/configmaps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "velero.fullname" $ }}-{{ $configMapName }}
{{- if .Values.customAnnotations }}
annotations:
{{- toYaml .Values.customAnnotations | nindent 4 }}
{{- end }}
labels:
app.kubernetes.io/name: {{ include "velero.name" $ }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
helm.sh/chart: {{ include "velero.chart" $ }}
{{- include "velero.labels" . | indent 4 }}
{{- with $configMap.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
Expand Down
27 changes: 13 additions & 14 deletions charts/velero/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,37 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "velero.fullname" . }}
{{- with .Values.annotations }}
{{- if or .Values.annotations .Values.customAnnotations }}
annotations:
{{- with .Values.customAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- if .Values.annotations }}
{{- toYaml .Values.annotations | nindent 4 }}
{{- end }}
{{- end }}
labels:
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
component: velero
{{- include "velero.labels" . | indent 4 }}
{{- with .Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
Comment on lines 20 to 22
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With removing these lines, will this make the labels duplicated?

spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/name: {{ include "velero.name" . }}
{{- include "velero.selectorLabels" . | indent 6 }}
template:
metadata:
labels:
name: velero
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
{{- include "velero.labels" . | indent 8 }}
{{- if .Values.podLabels }}
{{- toYaml .Values.podLabels | nindent 8 }}
{{- end }}
{{- if or .Values.podAnnotations .Values.metrics.enabled }}
{{- if or .Values.podAnnotations .Values.metrics.enabled .Values.customAnnotations }}
annotations:
{{- with .Values.customAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down
26 changes: 15 additions & 11 deletions charts/velero/templates/restic-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ apiVersion: apps/v1
kind: DaemonSet
metadata:
name: restic
{{- with .Values.restic.annotations }}
{{- if or .Values.restic.annotations .Values.customAnnotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- with .Values.restic.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.customAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
labels:
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
{{- include "velero.labels" . | indent 4 }}
{{- with .Values.restic.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
Expand All @@ -26,16 +28,18 @@ spec:
metadata:
labels:
name: restic
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
{{- include "velero.labels" . | indent 8 }}
{{- if .Values.podLabels }}
{{- toYaml .Values.podLabels | nindent 8 }}
{{- end }}
{{- with .Values.podAnnotations }}
{{- if or .Values.podAnnotations .Values.customAnnotations }}
annotations:
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.customAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
spec:
{{- if .Values.image.imagePullSecrets }}
Expand Down
10 changes: 5 additions & 5 deletions charts/velero/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ include "velero.fullname" . }}-server
{{- if .Values.customAnnotations }}
annotations:
{{- toYaml .Values.customAnnotations | nindent 4 }}
{{- end }}
labels:
app.kubernetes.io/component: server
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
{{- include "velero.labels" . | indent 4 }}
rules:
- apiGroups:
- "*"
Expand Down
10 changes: 5 additions & 5 deletions charts/velero/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "velero.fullname" . }}-server
{{- if .Values.customAnnotations }}
annotations:
{{- toYaml .Values.customAnnotations | nindent 4 }}
{{- end }}
labels:
app.kubernetes.io/component: server
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
{{- include "velero.labels" . | indent 4 }}
subjects:
- kind: ServiceAccount
namespace: {{ .Release.Namespace }}
Expand Down
8 changes: 4 additions & 4 deletions charts/velero/templates/schedule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ metadata:
{{- if $schedule.annotations }}
{{- toYaml $schedule.annotations | nindent 4 }}
{{- end }}
{{- with $.Values.customAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
"helm.sh/hook": post-install,post-upgrade,post-rollback
"helm.sh/hook-delete-policy": before-hook-creation
labels:
app.kubernetes.io/name: {{ include "velero.name" $ }}
app.kubernetes.io/instance: {{ $.Release.Name }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
helm.sh/chart: {{ include "velero.chart" $ }}
{{- include "velero.labels" $ | indent 4 }}
{{- if $schedule.labels }}
{{- toYaml $schedule.labels | nindent 4 }}
{{- end }}
Expand Down
9 changes: 5 additions & 4 deletions charts/velero/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ include "velero.secretName" . }}
{{- if .Values.customAnnotations }}
annotations:
{{- toYaml .Values.customAnnotations | nindent 4 }}
{{- end }}
labels:
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
{{- include "velero.labels" . | indent 4 }}
type: Opaque
data:
{{- range $key, $value := .Values.credentials.secretContents }}
Expand Down
16 changes: 8 additions & 8 deletions charts/velero/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ apiVersion: v1
kind: Service
metadata:
name: {{ include "velero.fullname" . }}
{{- with .Values.metrics.service.annotations }}
{{- if or .Values.customAnnotations .Values.metrics.service.annotations }}
annotations:
{{- if .Values.metrics.service.annotations }}
{{- toYaml .Values.metrics.service.annotations | nindent 4 }}
{{- end }}
{{- with .Values.customAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
labels:
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
{{- include "velero.labels" . | indent 4 }}
{{- with .Values.metrics.service.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
Expand All @@ -22,7 +24,5 @@ spec:
port: 8085
targetPort: http-monitoring
selector:
name: velero
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- include "velero.selectorLabels" . | indent 4 }}
{{- end }}
16 changes: 9 additions & 7 deletions charts/velero/templates/serviceaccount-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "velero.serverServiceAccount" . }}
{{- if .Values.serviceAccount.server.annotations }}
{{- if or .Values.serviceAccount.server.annotations .Values.customAnnotations }}
annotations:
{{ toYaml .Values.serviceAccount.server.annotations | nindent 4 }}
{{- end }}
{{- with .Values.serviceAccount.server.Annotations }}
{{ toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.customAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
labels:
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
{{- include "velero.labels" . | indent 4 }}
{{- with .Values.serviceAccount.server.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
Expand Down
12 changes: 6 additions & 6 deletions charts/velero/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ metadata:
{{- if .Values.metrics.serviceMonitor.namespace }}
namespace: {{ .Values.metrics.serviceMonitor.namespace }}
{{- end }}
{{- if .Values.customAnnotations }}
annotations:
{{- toYaml .Values.customAnnotations | nindent 4 }}
{{- end }}
labels:
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "velero.chart" . }}
{{- include "velero.labels" . | indent 4 }}
{{- with .Values.metrics.serviceMonitor.additionalLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
Expand All @@ -20,8 +21,7 @@ spec:
- {{ .Release.Namespace }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "velero.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- include "velero.selectorLabels" . | indent 6 }}
endpoints:
- port: http-monitoring
interval: {{ .Values.metrics.scrapeInterval }}
Expand Down
Loading