Skip to content

Commit

Permalink
Define template helpers to emit match labels including the modern labels
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Jan 12, 2025
1 parent 47c2b3f commit aaa0423
Showing 1 changed file with 72 additions and 11 deletions.
83 changes: 72 additions & 11 deletions jupyterhub/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -124,52 +124,113 @@
app.kubernetes.io/managed-by ("heritage")
*/}}
{{- define "jupyterhub.commonLabels" -}}
{{- if .legacyLabels -}}
app: {{ .appLabel | default (include "jupyterhub.appLabel" .) | quote }}
release: {{ .Release.Name | quote }}
{{- if not .matchLabels }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
heritage: {{ .Release.Service }}
{{- end }}
{{- end }}
{{- if and .legacyLabels .modernLabels -}}
{{ printf "\n" }}
{{- end }}
{{- if .modernLabels -}}
app.kubernetes.io/name: {{ .appLabel | default (include "jupyterhub.appLabel" .) | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
{{- if not .matchLabels }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{- end }}
{{- end }}
{{- /*
jupyterhub.labels:
Provides old labels:
Provides labels conditionally on .legacyLabels, .modernLabels, and .matchLabels,
that are supposed to in the scoped passed this helper function.
The legacy labels are:
component
app
release
chart (omitted for matchLabels)
heritage (omitted for matchLabels)
Provides modern labels (omitted for matchLabels):
app.kubernetes.io/component ("component")
app.kubernetes.io/name ("app")
app.kubernetes.io/instance release ("release")
helm.sh/chart ("chart")
app.kubernetes.io/managed-by ("heritage")
The equivalent modern labels are:
app.kubernetes.io/component
app.kubernetes.io/name
app.kubernetes.io/instance release
helm.sh/chart (omitted for matchLabels)
app.kubernetes.io/managed-by (omitted for matchLabels)
*/}}
{{- define "jupyterhub.labels" -}}
{{- /*
.legacyLabels defaults to true
.modernLabels defaults to false
*/ -}}
{{- $_ := . -}}
{{- if typeIs "<nil>" .legacyLabels -}}
{{- $_ = merge (dict "legacyLabels" true) $_ -}}
{{- end -}}
{{- if typeIs "<nil>" .modernLabels -}}
{{- $_ = merge (dict "modernLabels" true) $_ -}}
{{- end -}}
{{- if $_.legacyLabels -}}
component: {{ include "jupyterhub.componentLabel" . }}
{{- if not .matchLabels }}
{{- end }}
{{- if and $_.legacyLabels $_.modernLabels -}}
{{ printf "\n" }}
{{- end }}
{{- if $_.modernLabels -}}
app.kubernetes.io/component: {{ include "jupyterhub.componentLabel" . }}
{{- end }}
{{ include "jupyterhub.commonLabels" . }}
{{ include "jupyterhub.commonLabels" $_ }}
{{- end }}
{{- /*
jupyterhub.matchLabels:
Provides old labels:
Provides legacy labels:
component
app
release
*/}}
{{- define "jupyterhub.matchLabels" -}}
{{- $_ := merge (dict "matchLabels" true) . -}}
{{- $_ := merge (dict "matchLabels" true "legacyLabels" true "modernLabels" false) . -}}
{{ include "jupyterhub.labels" $_ }}
{{- end }}
{{- /*
jupyterhub.matchLabelsModern:
Provides modern labels:
app.kubernetes.io/component
app.kubernetes.io/name
app.kubernetes.io/instance
*/}}
{{- define "jupyterhub.matchLabelsModern" -}}
{{- $_ := merge (dict "matchLabels" true "legacyLabels" false "modernLabels" true) . -}}
{{ include "jupyterhub.labels" $_ }}
{{- end }}
{{- /*
jupyterhub.matchLabelsLegacyAndModern:
Provides legacy and modern labels:
component
app
release
app.kubernetes.io/component
app.kubernetes.io/name
app.kubernetes.io/instance
*/}}
{{- define "jupyterhub.matchLabelsLegacyAndModern" -}}
{{- $_ := merge (dict "matchLabels" true "legacyLabels" true "modernLabels" true) . -}}
{{ include "jupyterhub.labels" $_ }}
{{- end }}
Expand Down

0 comments on commit aaa0423

Please sign in to comment.