|
1 | | -{{- define "chart.name" -}} |
2 | | -{{- if .Chart }} |
3 | | - {{- if .Chart.Name }} |
4 | | - {{- .Chart.Name | trunc 63 | trimSuffix "-" }} |
5 | | - {{- else if .Values.nameOverride }} |
6 | | - {{ .Values.nameOverride | trunc 63 | trimSuffix "-" }} |
7 | | - {{- else }} |
8 | | - network-operator |
9 | | - {{- end }} |
| 1 | +{{/* |
| 2 | +Expand the name of the chart. |
| 3 | +*/}} |
| 4 | +{{- define "network-operator.name" -}} |
| 5 | +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} |
| 6 | +{{- end }} |
| 7 | + |
| 8 | +{{/* |
| 9 | +Create a default fully qualified app name. |
| 10 | +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
| 11 | +If release name contains chart name it will be used as a full name. |
| 12 | +*/}} |
| 13 | +{{- define "network-operator.fullname" -}} |
| 14 | +{{- if .Values.fullnameOverride }} |
| 15 | +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} |
10 | 16 | {{- else }} |
11 | | - network-operator |
12 | | -{{- end }} |
13 | | -{{- end }} |
14 | | - |
15 | | - |
16 | | -{{- define "chart.labels" -}} |
17 | | -{{- if .Chart.AppVersion -}} |
18 | | -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 17 | +{{- $name := default .Chart.Name .Values.nameOverride }} |
| 18 | +{{- if contains $name .Release.Name }} |
| 19 | +{{- .Release.Name | trunc 63 | trimSuffix "-" }} |
| 20 | +{{- else }} |
| 21 | +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} |
19 | 22 | {{- end }} |
20 | | -{{- if .Chart.Version }} |
21 | | -helm.sh/chart: {{ .Chart.Version | quote }} |
22 | 23 | {{- end }} |
23 | | -app.kubernetes.io/name: {{ include "chart.name" . }} |
24 | | -app.kubernetes.io/instance: {{ .Release.Name }} |
25 | | -app.kubernetes.io/managed-by: {{ .Release.Service }} |
26 | 24 | {{- end }} |
27 | 25 |
|
28 | | - |
29 | | -{{- define "chart.selectorLabels" -}} |
30 | | -app.kubernetes.io/name: {{ include "chart.name" . }} |
31 | | -app.kubernetes.io/instance: {{ .Release.Name }} |
| 26 | +{{/* |
| 27 | +Namespace for generated references. |
| 28 | +Always uses the Helm release namespace. |
| 29 | +*/}} |
| 30 | +{{- define "network-operator.namespaceName" -}} |
| 31 | +{{- .Release.Namespace }} |
32 | 32 | {{- end }} |
33 | 33 |
|
34 | | - |
35 | | -{{- define "chart.hasMutatingWebhooks" -}} |
36 | | -{{- $hasMutating := false }} |
37 | | -{{- range . }} |
38 | | - {{- if eq .type "mutating" }} |
39 | | - $hasMutating = true }}{{- end }} |
| 34 | +{{/* |
| 35 | +Resource name with proper truncation for Kubernetes 63-character limit. |
| 36 | +Takes a dict with: |
| 37 | + - .suffix: Resource name suffix (e.g., "metrics", "webhook") |
| 38 | + - .context: Template context (root context with .Values, .Release, etc.) |
| 39 | +Dynamically calculates safe truncation to ensure total name length <= 63 chars. |
| 40 | +*/}} |
| 41 | +{{- define "network-operator.resourceName" -}} |
| 42 | +{{- $fullname := include "network-operator.fullname" .context }} |
| 43 | +{{- $suffix := .suffix }} |
| 44 | +{{- $maxLen := sub 62 (len $suffix) | int }} |
| 45 | +{{- if gt (len $fullname) $maxLen }} |
| 46 | +{{- printf "%s-%s" (trunc $maxLen $fullname | trimSuffix "-") $suffix | trunc 63 | trimSuffix "-" }} |
| 47 | +{{- else }} |
| 48 | +{{- printf "%s-%s" $fullname $suffix | trunc 63 | trimSuffix "-" }} |
40 | 49 | {{- end }} |
41 | | -{{ $hasMutating }}}}{{- end }} |
42 | | - |
43 | | - |
44 | | -{{- define "chart.hasValidatingWebhooks" -}} |
45 | | -{{- $hasValidating := false }} |
46 | | -{{- range . }} |
47 | | - {{- if eq .type "validating" }} |
48 | | - $hasValidating = true }}{{- end }} |
49 | 50 | {{- end }} |
50 | | -{{ $hasValidating }}}}{{- end }} |
0 commit comments