Skip to content

Commit

Permalink
feat: add [recommended labels](https://kubernetes.io/docs/concepts/ov…
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbueschel committed Apr 25, 2024
1 parent d71e738 commit 78ad3e0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 20 deletions.
51 changes: 51 additions & 0 deletions charts/k8s-aws-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "k8s-aws-operator.name" -}}
{{- default .Chart.Name .Values.name | 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 "k8s-aws-operator.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.name }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

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

{{/*
Common labels
*/}}
{{- define "k8s-aws-operator.labels" -}}
helm.sh/chart: {{ include "k8s-aws-operator.chart" . }}
{{ include "k8s-aws-operator.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ default .Chart.AppVersion .Values.image.tag | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "k8s-aws-operator.selectorLabels" -}}
app.kubernetes.io/name: {{ include "k8s-aws-operator.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
8 changes: 4 additions & 4 deletions charts/k8s-aws-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Chart.Name }}
name: {{ include "k8s-aws-operator.fullname" . }}
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
{{- include "k8s-aws-operator.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app.kubernetes.io/name: {{ .Chart.Name }}
{{- include "k8s-aws-operator.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
{{- include "k8s-aws-operator.labels" . | nindent 8 }}
spec:
serviceAccountName: {{ .Chart.Name }}
{{- with .Values.nodeSelector }}
Expand Down
20 changes: 10 additions & 10 deletions charts/k8s-aws-operator/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Chart.Name }}
name: {{ include "k8s-aws-operator.fullname" . }}
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
{{- include "k8s-aws-operator.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{ . | toYaml | nindent 4 }}
Expand All @@ -13,9 +13,9 @@ metadata:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Chart.Name }}
name: {{ include "k8s-aws-operator.fullname" . }}
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
{{- include "k8s-aws-operator.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
resources: ["pods"]
Expand All @@ -27,9 +27,9 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ .Chart.Name }}
name: {{ include "k8s-aws-operator.fullname" . }}
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
{{- include "k8s-aws-operator.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand All @@ -44,9 +44,9 @@ subjects:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ .Chart.Name }}
name: {{ include "k8s-aws-operator.fullname" . }}
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
{{- include "k8s-aws-operator.labels" . | nindent 4 }}
rules:
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
Expand All @@ -62,9 +62,9 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ .Chart.Name }}
name: {{ include "k8s-aws-operator.fullname" . }}
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
{{- include "k8s-aws-operator.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
Expand Down
6 changes: 3 additions & 3 deletions charts/k8s-aws-operator/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Chart.Name }}-metrics
name: {{ include "k8s-aws-operator.fullname" . }}
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
{{- include "k8s-aws-operator.labels" . | nindent 4 }}
spec:
{{- with .Values.metrics.service.clusterIP }}
clusterIP: {{ . | quote }}
Expand All @@ -15,5 +15,5 @@ spec:
protocol: TCP
targetPort: 8080
selector:
app.kubernetes.io/name: {{ .Chart.Name }}
{{- include "k8s-aws-operator.selectorLabels" . | nindent 4 }}
{{- end }}
6 changes: 3 additions & 3 deletions charts/k8s-aws-operator/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ .Chart.Name }}
name: {{ include "k8s-aws-operator.fullname" . }}
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
{{- include "k8s-aws-operator.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
app.kubernetes.io/name: {{ .Chart.Name }}
{{- include "k8s-aws-operator.selectorLabels" . | nindent 6 }}
endpoints:
{{- with .Values.metrics.serviceMonitor.endpoints }}
{{ . | toYaml | nindent 2 }}
Expand Down

0 comments on commit 78ad3e0

Please sign in to comment.