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

feat: Add additional labels to the kubernetes resources #218

Merged
merged 12 commits into from
Jan 21, 2025
68 changes: 68 additions & 0 deletions charts/greptimedb-cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "greptimedb-cluster.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "greptimedb-cluster.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "greptimedb-cluster.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "greptimedb-cluster.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "greptimedb-cluster.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "greptimedb-cluster.labels" -}}
helm.sh/chart: {{ include "greptimedb-cluster.chart" . }}
{{ include "greptimedb-cluster.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/component: cluster
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/part-of: greptimedb-cluster
{{- with .Values.additionalLabels }}
{{ toYaml . }}
{{- end }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "greptimedb-cluster.selectorLabels" -}}
app.kubernetes.io/name: {{ include "greptimedb-cluster.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
2 changes: 2 additions & 0 deletions charts/greptimedb-cluster/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: GreptimeDBCluster
metadata:
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-cluster.labels" . | nindent 4 }}
spec:
base:
main:
Expand Down
1 change: 1 addition & 0 deletions charts/greptimedb-cluster/templates/debug-depoyment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
name: {{ .Release.Name }}-debug-pod
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-cluster.labels" . | nindent 4 }}
app: {{ .Release.Name }}-debug-pod
spec:
replicas: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ kind: ConfigMap
metadata:
name: {{ $value }}
namespace: {{ $root.Release.Namespace }}
labels:
{{- include "greptimedb-cluster.labels" . | nindent 4 }}
daviderli614 marked this conversation as resolved.
Show resolved Hide resolved
data:
{{ $key }}.json: |-
{{ $root.Files.Get (printf "dashboards/%s.json" $key) | indent 4 }}
Expand Down
2 changes: 2 additions & 0 deletions charts/greptimedb-cluster/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ apiVersion: v1
metadata:
name: {{ default "storage-credentials" .Values.objectStorage.credentials.secretName }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-cluster.labels" . | nindent 4 }}
kind: Secret
type: Opaque
{{- if .Values.objectStorage.credentials.serviceAccountKey }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: ServiceAccount
metadata:
name: {{ .Release.Name }}-datanode
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-cluster.labels" . | nindent 4 }}
{{- with .Values.datanode.podTemplate.serviceAccount.annotations }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: ServiceAccount
metadata:
name: {{ .Release.Name }}-flownode
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-cluster.labels" . | nindent 4 }}
{{- with .Values.flownode.podTemplate.serviceAccount.annotations }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: ServiceAccount
metadata:
name: {{ .Release.Name }}-frontend
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-cluster.labels" . | nindent 4 }}
{{- with .Values.frontend.podTemplate.serviceAccount.annotations }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions charts/greptimedb-cluster/templates/serviceaccount-meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: ServiceAccount
metadata:
name: {{ .Release.Name }}-meta
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-cluster.labels" . | nindent 4 }}
{{- with .Values.meta.podTemplate.serviceAccount.annotations }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions charts/greptimedb-cluster/templates/users-auth-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: Secret
metadata:
name: {{ .Release.Name }}-users-auth
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-cluster.labels" . | nindent 4 }}
type: Opaque
stringData:
{{ .Values.auth.fileName }}: |
Expand Down
3 changes: 3 additions & 0 deletions charts/greptimedb-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ image:
# -- The image pull secrets
pullSecrets: []

# -- additional labels to add to all resources
additionalLabels: {}

initializer:
# -- Initializer image registry
registry: docker.io
Expand Down
5 changes: 5 additions & 0 deletions charts/greptimedb-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ helm.sh/chart: {{ include "greptimedb-operator.chart" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/component: operator
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/part-of: greptimedb-operator
{{- with .Values.additionalLabels }}
{{ toYaml . }}
{{- end }}
{{- end }}

{{/*
Expand Down
2 changes: 2 additions & 0 deletions charts/greptimedb-operator/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "greptimedb-operator.fullname" . }}-role
labels:
{{- include "greptimedb-operator.labels" . | nindent 4 }}
rules:
- apiGroups:
- apiextensions.k8s.io
Expand Down
2 changes: 2 additions & 0 deletions charts/greptimedb-operator/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "greptimedb-operator.fullname" . }}-rolebinding
labels:
{{- include "greptimedb-operator.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down
2 changes: 2 additions & 0 deletions charts/greptimedb-operator/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: Role
metadata:
name: {{ include "greptimedb-operator.fullname" . }}-leader-election-role
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-operator.labels" . | nindent 4 }}
rules:
- apiGroups:
- ''
Expand Down
2 changes: 2 additions & 0 deletions charts/greptimedb-operator/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: RoleBinding
metadata:
name: {{ include "greptimedb-operator.fullname" . }}-leader-election-rolebinding
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-operator.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
Expand Down
2 changes: 2 additions & 0 deletions charts/greptimedb-operator/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: Service
metadata:
name: {{ include "greptimedb-operator.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-operator.labels" . | nindent 4 }}
spec:
type: ClusterIP
selector:
Expand Down
2 changes: 2 additions & 0 deletions charts/greptimedb-operator/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ kind: ServiceAccount
metadata:
name: {{ include "greptimedb-operator.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-operator.labels" . | nindent 4 }}
{{- end }}
3 changes: 3 additions & 0 deletions charts/greptimedb-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ image:
# -- The image pull secrets
pullSecrets: []

# -- additional labels to add to all resources
additionalLabels: {}

serviceAccount:
# -- Specifies whether a service account should be created
create: true
Expand Down
5 changes: 5 additions & 0 deletions charts/greptimedb-standalone/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ helm.sh/chart: {{ include "greptimedb-standalone.chart" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/component: standalone
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/part-of: greptimedb-standalone
{{- with .Values.additionalLabels }}
{{ toYaml . }}
{{- end }}
{{- end }}

{{/*
Expand Down
5 changes: 3 additions & 2 deletions charts/greptimedb-standalone/templates/podmonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ kind: PodMonitor
metadata:
name: {{ include "greptimedb-standalone.fullname" . }}
namespace: {{ .Release.Namespace }}
{{- with .Values.monitoring.labels }}
labels:
{{- include "greptimedb-standalone.labels" . | nindent 4 }}
{{- with .Values.monitoring.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{- with .Values.monitoring.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
2 changes: 2 additions & 0 deletions charts/greptimedb-standalone/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ apiVersion: v1
metadata:
name: {{ include "greptimedb-standalone.fullname" . }}-secret
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-standalone.labels" . | nindent 4 }}
kind: Secret
type: Opaque
{{- if .Values.objectStorage.credentials.serviceAccountKey }}
Expand Down
2 changes: 2 additions & 0 deletions charts/greptimedb-standalone/templates/users-auth-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: Secret
metadata:
name: {{ include "greptimedb-standalone.fullname" . }}-users-auth
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-standalone.labels" . | nindent 4 }}
type: Opaque
stringData:
{{ .Values.auth.fileName }}: |
Expand Down
3 changes: 3 additions & 0 deletions charts/greptimedb-standalone/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ nameOverride: ""
# -- Provide a name to substitute for the full names of resources
fullnameOverride: ""

# -- additional labels to add to all resources
additionalLabels: {}

serviceAccount:
# -- Specifies whether a service account should be created
create: true
Expand Down
Loading