{{/*
Expand the name of the chart.
*/}}
{{- define "flink-sql-gateway.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 "flink-sql-gateway.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 chart name and version as used by the chart label.
*/}}
{{- define "flink-sql-gateway.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "flink-sql-gateway.labels" -}}
helm.sh/chart: {{ include "flink-sql-gateway.chart" . }}
{{ include "flink-sql-gateway.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.global.labels }}
{{ toYaml . }}
{{- end }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "flink-sql-gateway.selectorLabels" -}}
app.kubernetes.io/name: {{ include "flink-sql-gateway.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "flink-sql-gateway.serviceAccountName" -}}
{{- if .Values.rbac.create }}
{{- default (include "flink-sql-gateway.fullname" .) .Values.rbac.serviceAccountName }}
{{- else }}
{{- default "default" .Values.rbac.serviceAccountName }}
{{- end }}
{{- end }}

{{/*
Create namespace name
*/}}
{{- define "flink-sql-gateway.namespace" -}}
{{- default .Values.global.namespace .Release.Namespace }}
{{- end }}

{{/*
Create image name
*/}}
{{- define "flink-sql-gateway.image" -}}
{{- printf "%s:%s" .Values.global.image.repository .Values.global.image.tag }}
{{- end }}


{{/*
Session Cluster labels
*/}}
{{- define "flink-sql-gateway.sessionCluster.labels" -}}
{{ include "flink-sql-gateway.labels" . }}
app: {{ .Values.sessionCluster.name }}
component: flink-session-cluster
{{- end }}

{{/*
SQL Gateway labels
*/}}
{{- define "flink-sql-gateway.sqlGateway.labels" -}}
{{ include "flink-sql-gateway.labels" . }}
app: {{ .Values.sqlGateway.name }}
component: flink-sql-gateway
{{- end }}

{{/*
SQL Client labels
*/}}
{{- define "flink-sql-gateway.sqlClient.labels" -}}
{{ include "flink-sql-gateway.labels" . }}
app: {{ .Values.sqlClient.name }}
component: flink-sql-client
{{- end }}