From 7580133577c844e0673143787934b52243e3e3fa Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Thu, 4 Jul 2024 15:47:30 +0200 Subject: [PATCH] Change default naming to not include release name --- .../templates/_helpers-labels.tpl | 19 +++ .../templates/_helpers-names.tpl | 119 ++++++++++++++++++ binderhub-service/templates/_helpers.tpl | 65 ---------- .../build-pods-docker-config/secret.yaml | 4 +- binderhub-service/templates/deployment.yaml | 8 +- .../templates/docker-api/daemonset.yaml | 4 +- .../templates/docker-api/secret.yaml | 2 +- binderhub-service/templates/ingress.yaml | 4 +- binderhub-service/templates/role.yaml | 2 +- binderhub-service/templates/rolebinding.yaml | 6 +- binderhub-service/templates/secret.yaml | 2 +- binderhub-service/templates/service.yaml | 2 +- .../templates/serviceaccount.yaml | 2 +- binderhub-service/values.schema.yaml | 4 +- 14 files changed, 157 insertions(+), 86 deletions(-) create mode 100644 binderhub-service/templates/_helpers-labels.tpl create mode 100644 binderhub-service/templates/_helpers-names.tpl diff --git a/binderhub-service/templates/_helpers-labels.tpl b/binderhub-service/templates/_helpers-labels.tpl new file mode 100644 index 0000000..d500be3 --- /dev/null +++ b/binderhub-service/templates/_helpers-labels.tpl @@ -0,0 +1,19 @@ +{{- /* + Common labels +*/}} +{{- define "binderhub-service.labels" -}} +helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{ include "binderhub-service.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{- /* + Selector labels +*/}} +{{- define "binderhub-service.selectorLabels" -}} +app.kubernetes.io/name: {{ .Values.nameOverride | default .Chart.Name | trunc 63 | trimSuffix "-" }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/binderhub-service/templates/_helpers-names.tpl b/binderhub-service/templates/_helpers-names.tpl new file mode 100644 index 0000000..c84bdd5 --- /dev/null +++ b/binderhub-service/templates/_helpers-names.tpl @@ -0,0 +1,119 @@ +{{- /* + These helpers encapsulates logic on how we name resources. They also enable + parent charts to reference these dynamic resource names. + + To avoid duplicating documentation, for more information, please see the the + fullnameOverride entry the jupyterhub chart's configuration reference: + https://z2jh.jupyter.org/en/latest/resources/reference.html#fullnameOverride +*/}} + + + +{{- /* + Utility templates +*/}} + +{{- /* + Renders to a prefix for the chart's resource names. This prefix is assumed to + make the resource name cluster unique. +*/}} +{{- define "binderhub-service.fullname" -}} + {{- /* + We have implemented a trick to allow a parent chart depending on this + chart to call these named templates. + + Caveats and notes: + + 1. While parent charts can reference these, grandparent charts can't. + 2. Parent charts must not use an alias for this chart. + 3. There is no failsafe workaround to above due to + https://github.com/helm/helm/issues/9214. + 4. .Chart is of its own type (*chart.Metadata) and needs to be casted + using "toYaml | fromYaml" in order to be able to use normal helm + template functions on it. + */}} + {{- $fullname_override := .Values.fullnameOverride }} + {{- $name_override := .Values.nameOverride }} + {{- if ne .Chart.Name "binderhub-service" }} + {{- if .Values.jupyterhub }} + {{- $fullname_override = .Values.jupyterhub.fullnameOverride }} + {{- $name_override = .Values.jupyterhub.nameOverride }} + {{- end }} + {{- end }} + + {{- if eq (typeOf $fullname_override) "string" }} + {{- $fullname_override }} + {{- else }} + {{- $name := $name_override | default .Chart.Name }} + {{- if contains $name .Release.Name }} + {{- .Release.Name }} + {{- else }} + {{- .Release.Name }}-{{ $name }} + {{- end }} + {{- end }} +{{- end }} + +{{- /* + Renders to a blank string or if the fullname template is truthy renders to it + with an appended dash. +*/}} +{{- define "binderhub-service.fullname.dash" -}} + {{- if (include "binderhub-service.fullname" .) }} + {{- include "binderhub-service.fullname" . }}- + {{- end }} +{{- end }} + + + +{{- /* + Namespaced resources +*/}} + +{{- /* binderhub resources' default name */}} +{{- define "binderhub-service.binderhub.fullname" -}} + {{- include "binderhub-service.fullname.dash" . }}binderhub +{{- end }} + +{{- /* binderhub's ServiceAccount name */}} +{{- define "binderhub-service.binderhub.serviceaccount.fullname" -}} + {{- if .Values.serviceAccount.create }} + {{- .Values.serviceAccount.name | default (include "binderhub-service.binderhub.fullname" .) }} + {{- else }} + {{- .Values.serviceAccount.name }} + {{- end }} +{{- end }} + +{{- /* binderhub's Ingress name */}} +{{- define "binderhub-service.binderhub.ingress.fullname" -}} + {{- if (include "binderhub-service.fullname" .) }} + {{- include "binderhub-service.fullname" . }} + {{- else -}} + binderhub + {{- end }} +{{- end }} + +{{- /* docker-api resources' default name */}} +{{- define "binderhub-service.docker-api.fullname" -}} + {{- include "binderhub-service.fullname.dash" . }}docker-api +{{- end }} + +{{- /* build-pods-docker-config name */}} +{{- define "binderhub-service.build-pods-docker-config.fullname" -}} + {{- include "binderhub-service.fullname.dash" . }}build-pods-docker-config +{{- end }} + + + +{{- /* + Cluster wide resources + + We enforce uniqueness of names for our cluster wide resources. We assume that + the prefix from setting fullnameOverride to null or a string will be cluster + unique. +*/}} + +{{- /* + We currently have no cluster wide resources, but if you add one below in the + future, remove this comment and add an entry mimicing how the jupyterhub helm + chart does it. +*/}} diff --git a/binderhub-service/templates/_helpers.tpl b/binderhub-service/templates/_helpers.tpl index 5a443a6..a5762b7 100644 --- a/binderhub-service/templates/_helpers.tpl +++ b/binderhub-service/templates/_helpers.tpl @@ -1,68 +1,3 @@ -{{- /* - Expand the name of the chart. -*/}} -{{- define "binderhub-service.name" -}} -{{- .Values.nameOverride | default .Chart.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 "binderhub-service.fullname" -}} -{{- if .Values.fullnameOverride }} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- $name := .Values.nameOverride | default .Chart.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 "binderhub-service.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{- /* - Common labels -*/}} -{{- define "binderhub-service.labels" -}} -helm.sh/chart: {{ include "binderhub-service.chart" . }} -{{ include "binderhub-service.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} -{{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end }} - -{{- /* - Selector labels -*/}} -{{- define "binderhub-service.selectorLabels" -}} -app.kubernetes.io/name: {{ include "binderhub-service.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - -{{- /* - Create the name of the service account to use -*/}} -{{- define "binderhub-service.serviceAccountName" -}} -{{- if .Values.serviceAccount.create }} -{{- include "binderhub-service.fullname" . | default .Values.serviceAccount.name }} -{{- else }} -{{- .Values.serviceAccount.name }} -{{- end }} -{{- end }} - - - {{- /* binderhub-service.chart-version-to-git-ref: Renders a valid git reference from a chartpress generated version string. diff --git a/binderhub-service/templates/build-pods-docker-config/secret.yaml b/binderhub-service/templates/build-pods-docker-config/secret.yaml index 9d3a3f1..410b7a1 100644 --- a/binderhub-service/templates/build-pods-docker-config/secret.yaml +++ b/binderhub-service/templates/build-pods-docker-config/secret.yaml @@ -7,9 +7,7 @@ kind: Secret apiVersion: v1 metadata: - # If this is changed, update the value of the PUSH_SECRET_NAME environment - # variable in the binderhub deployment (in deployment.yaml) - name: {{ include "binderhub-service.fullname" . }}-build-pods-docker-config + name: {{ include "binderhub-service.build-pods-docker-config.fullname" . }} labels: {{- include "binderhub-service.labels" . | nindent 4 }} type: Opaque diff --git a/binderhub-service/templates/deployment.yaml b/binderhub-service/templates/deployment.yaml index bef5967..ae2904c 100644 --- a/binderhub-service/templates/deployment.yaml +++ b/binderhub-service/templates/deployment.yaml @@ -1,7 +1,7 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "binderhub-service.fullname" . }} + name: {{ include "binderhub-service.binderhub.fullname" . }} labels: {{- include "binderhub-service.labels" . | nindent 4 }} spec: @@ -24,7 +24,7 @@ spec: volumes: - name: secret secret: - secretName: {{ include "binderhub-service.fullname" . }} + secretName: {{ include "binderhub-service.binderhub.fullname" . }} containers: - name: binderhub image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" @@ -40,7 +40,7 @@ spec: readOnly: true env: - name: PUSH_SECRET_NAME - value: {{ include "binderhub-service.fullname" . }}-build-pods-docker-config + value: {{ include "binderhub-service.build-pods-docker-config.fullname" . }} - name: HELM_RELEASE_NAME value: {{ .Release.Name }} # Namespace build pods should be placed in @@ -70,7 +70,7 @@ spec: imagePullSecrets: {{- . | toYaml | nindent 8 }} {{- end }} - {{- with include "binderhub-service.serviceAccountName" . }} + {{- with include "binderhub-service.binderhub.serviceaccount.fullname" . }} serviceAccountName: {{ . }} {{- end }} {{- with .Values.podSecurityContext }} diff --git a/binderhub-service/templates/docker-api/daemonset.yaml b/binderhub-service/templates/docker-api/daemonset.yaml index 5385795..3427b80 100644 --- a/binderhub-service/templates/docker-api/daemonset.yaml +++ b/binderhub-service/templates/docker-api/daemonset.yaml @@ -1,7 +1,7 @@ apiVersion: apps/v1 kind: DaemonSet metadata: - name: {{ include "binderhub-service.fullname" . }}-docker-api + name: {{ include "binderhub-service.docker-api.fullname" . }} labels: {{- include "binderhub-service.labels" . | nindent 4 }} app.kubernetes.io/component: docker-api @@ -57,7 +57,7 @@ spec: {{- if .Values.dockerApi.extraFiles }} - name: files secret: - secretName: {{ include "binderhub-service.fullname" . }}-docker-api + secretName: {{ include "binderhub-service.docker-api.fullname" . }} items: {{- range $file_key, $file_details := .Values.dockerApi.extraFiles }} - key: {{ $file_key | quote }} diff --git a/binderhub-service/templates/docker-api/secret.yaml b/binderhub-service/templates/docker-api/secret.yaml index 719add6..258369d 100644 --- a/binderhub-service/templates/docker-api/secret.yaml +++ b/binderhub-service/templates/docker-api/secret.yaml @@ -2,7 +2,7 @@ kind: Secret apiVersion: v1 metadata: - name: {{ include "binderhub-service.fullname" . }}-docker-api + name: {{ include "binderhub-service.docker-api.fullname" . }} labels: {{- include "binderhub-service.labels" . | nindent 4 }} type: Opaque diff --git a/binderhub-service/templates/ingress.yaml b/binderhub-service/templates/ingress.yaml index 7b8d39b..510fbe3 100644 --- a/binderhub-service/templates/ingress.yaml +++ b/binderhub-service/templates/ingress.yaml @@ -2,7 +2,7 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: {{ include "binderhub-service.fullname" . }} + name: {{ include "binderhub-service.binderhub.ingress.fullname" . }} labels: {{- include "binderhub-service.labels" . | nindent 4 }} {{- with .Values.ingress.annotations }} @@ -21,7 +21,7 @@ spec: pathType: {{ $.Values.ingress.pathType }} backend: service: - name: {{ include "binderhub-service.fullname" $ }} + name: {{ include "binderhub-service.binderhub.fullname" $ }} port: name: http {{- if $host }} diff --git a/binderhub-service/templates/role.yaml b/binderhub-service/templates/role.yaml index 9d56b73..4032338 100644 --- a/binderhub-service/templates/role.yaml +++ b/binderhub-service/templates/role.yaml @@ -2,7 +2,7 @@ kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: - name: {{ include "binderhub-service.fullname" . }} + name: {{ include "binderhub-service.binderhub.fullname" . }} labels: {{- include "binderhub-service.labels" . | nindent 4 }} rules: diff --git a/binderhub-service/templates/rolebinding.yaml b/binderhub-service/templates/rolebinding.yaml index c8265fc..067b1db 100644 --- a/binderhub-service/templates/rolebinding.yaml +++ b/binderhub-service/templates/rolebinding.yaml @@ -2,15 +2,15 @@ kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: - name: {{ include "binderhub-service.fullname" . }} + name: {{ include "binderhub-service.binderhub.fullname" . }} labels: {{- include "binderhub-service.labels" . | nindent 4 }} subjects: - kind: ServiceAccount namespace: {{ .Release.Namespace }} - name: {{ include "binderhub-service.serviceAccountName" . }} + name: {{ include "binderhub-service.binderhub.serviceaccount.fullname" . }} roleRef: apiGroup: rbac.authorization.k8s.io kind: Role - name: {{ include "binderhub-service.fullname" . }} + name: {{ include "binderhub-service.binderhub.fullname" . }} {{- end }} diff --git a/binderhub-service/templates/secret.yaml b/binderhub-service/templates/secret.yaml index 86f1631..eca525c 100644 --- a/binderhub-service/templates/secret.yaml +++ b/binderhub-service/templates/secret.yaml @@ -5,7 +5,7 @@ kind: Secret apiVersion: v1 metadata: - name: {{ include "binderhub-service.fullname" . }} + name: {{ include "binderhub-service.binderhub.fullname" . }} labels: {{- include "binderhub-service.labels" . | nindent 4 }} type: Opaque diff --git a/binderhub-service/templates/service.yaml b/binderhub-service/templates/service.yaml index 5bd11cc..f3ba4b0 100644 --- a/binderhub-service/templates/service.yaml +++ b/binderhub-service/templates/service.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Service metadata: - name: {{ include "binderhub-service.fullname" . }} + name: {{ include "binderhub-service.binderhub.fullname" . }} labels: {{- include "binderhub-service.labels" . | nindent 4 }} {{- with .Values.service.annotations }} annotations: diff --git a/binderhub-service/templates/serviceaccount.yaml b/binderhub-service/templates/serviceaccount.yaml index ef917cc..0ba4712 100644 --- a/binderhub-service/templates/serviceaccount.yaml +++ b/binderhub-service/templates/serviceaccount.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: {{ include "binderhub-service.serviceAccountName" . }} + name: {{ include "binderhub-service.binderhub.serviceaccount.fullname" . }} labels: {{- include "binderhub-service.labels" . | nindent 4 }} {{- with .Values.serviceAccount.annotations }} diff --git a/binderhub-service/values.schema.yaml b/binderhub-service/values.schema.yaml index 66e3505..46eaedb 100644 --- a/binderhub-service/values.schema.yaml +++ b/binderhub-service/values.schema.yaml @@ -41,9 +41,9 @@ properties: # --------------------------------------------------------------------------- # nameOverride: - type: string + type: [string, "null"] fullnameOverride: - type: string + type: [string, "null"] global: type: object additionalProperties: true