Skip to content

Commit

Permalink
Change default naming to not include release name
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Jul 4, 2024
1 parent be5fd8d commit f836186
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 84 deletions.
19 changes: 19 additions & 0 deletions binderhub-service/templates/_helpers-labels.tpl
Original file line number Diff line number Diff line change
@@ -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 }}
118 changes: 118 additions & 0 deletions binderhub-service/templates/_helpers-names.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{{- /*
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 we do, mimic what we do in
the future, add an entry mimicing how the jupyterhub helm chart does it.
*/}}
65 changes: 0 additions & 65 deletions binderhub-service/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions binderhub-service/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 }}"
Expand All @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions binderhub-service/templates/docker-api/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion binderhub-service/templates/docker-api/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions binderhub-service/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion binderhub-service/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions binderhub-service/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion binderhub-service/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion binderhub-service/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion binderhub-service/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit f836186

Please sign in to comment.