Skip to content

Commit bde2885

Browse files
committed
[helm]: Include default helpers, rename using fullname
Signed-off-by: cabrinha <yuppie@hey.com>
1 parent 5955b53 commit bde2885

File tree

22 files changed

+222
-227
lines changed

22 files changed

+222
-227
lines changed

dist/chart/templates/_helpers.tpl

Lines changed: 67 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,4 @@
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-
aibrix
9-
{{- end }}
10-
{{- else }}
11-
aibrix
12-
{{- end }}
13-
{{- end }}
14-
15-
16-
{{- define "chart.labels" -}}
17-
{{- if .Chart.AppVersion -}}
18-
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
19-
{{- end }}
20-
{{- if .Chart.Version }}
21-
helm.sh/chart: {{ .Chart.Version | quote }}
22-
{{- 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-
{{- end }}
27-
28-
29-
{{- define "chart.selectorLabels" -}}
30-
app.kubernetes.io/name: {{ include "chart.name" . }}
31-
app.kubernetes.io/instance: {{ .Release.Name }}
32-
{{- end }}
33-
34-
35-
{{- define "chart.hasMutatingWebhooks" -}}
1+
{{- define "aibrix.hasMutatingWebhooks" -}}
362
{{- $d := dict "found" false -}}
373
{{- range . -}}
384
{{- if eq .type "mutating" -}}
@@ -42,7 +8,7 @@ app.kubernetes.io/instance: {{ .Release.Name }}
428
{{- $d.found -}}
439
{{- end -}}
4410

45-
{{- define "chart.hasValidatingWebhooks" -}}
11+
{{- define "aibrix.hasValidatingWebhooks" -}}
4612
{{- $d := dict "found" false -}}
4713
{{- range . -}}
4814
{{- if eq .type "validating" -}}
@@ -55,10 +21,73 @@ app.kubernetes.io/instance: {{ .Release.Name }}
5521
{{/*
5622
Renders imagePullSecrets block
5723
*/}}
58-
{{- define "chart.imagePullSecrets" -}}
24+
{{- define "aibrix.imagePullSecrets" -}}
5925
{{- $secrets := .componentSecrets | default .globalSecrets -}}
6026
{{- if $secrets -}}
6127
imagePullSecrets:
6228
{{- toYaml $secrets | nindent 2 }}
6329
{{- end -}}
64-
{{- end -}}
30+
{{- end -}}
31+
32+
{{/*
33+
Expand the name of the chart.
34+
*/}}
35+
{{- define "aibrix.name" -}}
36+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
37+
{{- end }}
38+
39+
{{/*
40+
Create a default fully qualified app name.
41+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
42+
If release name contains chart name it will be used as a full name.
43+
*/}}
44+
{{- define "aibrix.fullname" -}}
45+
{{- if .Values.fullnameOverride }}
46+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
47+
{{- else }}
48+
{{- $name := default .Chart.Name .Values.nameOverride }}
49+
{{- if contains $name .Release.Name }}
50+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
51+
{{- else }}
52+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
53+
{{- end }}
54+
{{- end }}
55+
{{- end }}
56+
57+
{{/*
58+
Create chart name and version as used by the chart label.
59+
*/}}
60+
{{- define "aibrix.chart" -}}
61+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
62+
{{- end }}
63+
64+
{{/*
65+
Common labels
66+
*/}}
67+
{{- define "aibrix.labels" -}}
68+
helm.sh/chart: {{ include "aibrix.chart" . }}
69+
{{ include "aibrix.selectorLabels" . }}
70+
{{- if .Chart.AppVersion }}
71+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
72+
{{- end }}
73+
app.kubernetes.io/managed-by: {{ .Release.Service }}
74+
{{- end }}
75+
76+
{{/*
77+
Selector labels
78+
*/}}
79+
{{- define "aibrix.selectorLabels" -}}
80+
app.kubernetes.io/name: {{ include "aibrix.name" . }}
81+
app.kubernetes.io/instance: {{ .Release.Name }}
82+
{{- end }}
83+
84+
{{/*
85+
Create the name of the service account to use
86+
*/}}
87+
{{- define "aibrix.serviceAccountName" -}}
88+
{{- if .Values.serviceAccount.create }}
89+
{{- default (include "aibrix.fullname" .) .Values.serviceAccount.name }}
90+
{{- else }}
91+
{{- default "default" .Values.serviceAccount.name }}
92+
{{- end }}
93+
{{- end }}

dist/chart/templates/controller-manager/deployment.yaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@ kind: Deployment
33
metadata:
44
labels:
55
app.kubernetes.io/component: aibrix-controller-manager
6-
{{- include "chart.labels" . | nindent 4 }}
7-
name: aibrix-controller-manager
8-
namespace: {{ .Release.Namespace }}
6+
{{- include "aibrix.labels" . | nindent 4 }}
7+
name: {{ include "aibrix.fullname" . }}-controller-manager
98
spec:
109
replicas: {{ .Values.controllerManager.replicas }}
1110
selector:
1211
matchLabels:
13-
{{- include "chart.selectorLabels" . | nindent 6 }}
12+
{{- include "aibrix.selectorLabels" . | nindent 6 }}
1413
app.kubernetes.io/component: aibrix-controller-manager
1514
template:
1615
metadata:
1716
labels:
18-
{{- include "chart.labels" . | nindent 8 }}
17+
{{- include "aibrix.labels" . | nindent 8 }}
1918
app.kubernetes.io/component: aibrix-controller-manager
2019
spec:
21-
{{- include "chart.imagePullSecrets" (dict "componentSecrets" .Values.controllerManager.imagePullSecrets "globalSecrets" .Values.global.imagePullSecrets) | nindent 6 }}
20+
{{- include "aibrix.imagePullSecrets" (dict "componentSecrets" .Values.controllerManager.imagePullSecrets "globalSecrets" .Values.global.imagePullSecrets) | nindent 6 }}
2221
containers:
2322
- args:
2423
- --leader-elect
@@ -53,13 +52,13 @@ spec:
5352
readOnly: true
5453
securityContext:
5554
runAsNonRoot: true
56-
serviceAccountName: aibrix-controller-manager
55+
serviceAccountName: {{ include "aibrix.serviceAccountName" . }}-controller-manager
5756
terminationGracePeriodSeconds: 10
5857
volumes:
5958
- name: cert
6059
secret:
6160
defaultMode: 420
62-
secretName: aibrix-webhook-server-cert
61+
secretName: {{ include "aibrix.fullname" . }}-webhook-server-cert
6362
{{- with .Values.controllerManager.tolerations }}
6463
tolerations:
6564
{{- toYaml . | nindent 8 }}

dist/chart/templates/controller-manager/rbac.yaml

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ apiVersion: v1
22
kind: ServiceAccount
33
metadata:
44
labels:
5-
{{- include "chart.labels" . | nindent 4 }}
6-
name: aibrix-controller-manager
7-
namespace: {{ .Release.Namespace }}
5+
{{- include "aibrix.labels" . | nindent 4 }}
6+
name: {{ include "aibrix.serviceAccountName" . }}-controller-manager
87
---
9-
108
apiVersion: rbac.authorization.k8s.io/v1
119
kind: ClusterRole
1210
metadata:
13-
name: aibrix-controller-manager-clusterrole
11+
name: {{ include "aibrix.fullname" . }}-controller-manager
1412
labels:
15-
{{- include "chart.labels" . | nindent 4 }}
13+
{{- include "aibrix.labels" . | nindent 4 }}
1614
rules:
1715
- apiGroups:
1816
- ""
@@ -301,33 +299,29 @@ rules:
301299
- list
302300
- update
303301
- watch
304-
305-
306302
---
307303
apiVersion: rbac.authorization.k8s.io/v1
308304
kind: ClusterRoleBinding
309305
metadata:
310306
labels:
311-
{{- include "chart.labels" . | nindent 4 }}
312-
name: aibrix-controller-manager-clusterrolebinding
307+
{{- include "aibrix.labels" . | nindent 4 }}
308+
name: {{ include "aibrix.fullname" . }}-controller-manager
313309
roleRef:
314310
apiGroup: rbac.authorization.k8s.io
315311
kind: ClusterRole
316-
name: aibrix-controller-manager-clusterrole
312+
name: {{ include "aibrix.fullname" . }}-controller-manager
317313
subjects:
318314
- kind: ServiceAccount
319-
name: aibrix-controller-manager
315+
name: {{ include "aibrix.serviceAccountName" . }}-controller-manager
320316
namespace: {{ .Release.Namespace }}
321-
322-
323317
---
324318
apiVersion: rbac.authorization.k8s.io/v1
325319
kind: Role
326320
metadata:
327-
name: aibrix-controller-manager-leader-election-role
321+
name: {{ include "aibrix.fullname" . }}-controller-manager-leader-election
328322
namespace: {{ .Release.Namespace }}
329323
labels:
330-
{{- include "chart.labels" . | nindent 4 }}
324+
{{- include "aibrix.labels" . | nindent 4 }}
331325
rules:
332326
- apiGroups:
333327
- ""
@@ -360,20 +354,18 @@ rules:
360354
verbs:
361355
- create
362356
- patch
363-
364357
---
365358
apiVersion: rbac.authorization.k8s.io/v1
366359
kind: RoleBinding
367360
metadata:
368-
name: aibrix-controller-manager-leader-election-rolebinding
369-
namespace: {{ .Release.Namespace }}
361+
name: {{ include "aibrix.fullname" . }}-controller-manager-leader-election
370362
labels:
371-
{{- include "chart.labels" . | nindent 4 }}
363+
{{- include "aibrix.labels" . | nindent 4 }}
372364
roleRef:
373365
apiGroup: rbac.authorization.k8s.io
374366
kind: Role
375-
name: aibrix-controller-manager-leader-election-role
367+
name: {{ include "aibrix.fullname" . }}-controller-manager-leader-election
376368
subjects:
377369
- kind: ServiceAccount
378-
name: aibrix-controller-manager
370+
name: {{ include "aibrix.serviceAccountName" . }}-controller-manager
379371
namespace: {{ .Release.Namespace }}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
apiVersion: v1
22
kind: Service
33
metadata:
4-
name: aibrix-controller-manager-metrics-service
5-
namespace: {{ .Release.Namespace }}
4+
name: {{ include "aibrix.fullname" . }}-controller-manager-metrics
65
annotations:
76
prometheus.io/path: /metrics
87
prometheus.io/port: "8080"
98
prometheus.io/scrape: "true"
109
labels:
11-
{{- include "chart.labels" . | nindent 4 }}
10+
{{- include "aibrix.labels" . | nindent 4 }}
1211
app.kubernetes.io/component: aibrix-controller-manager
1312
spec:
1413
ports:
@@ -17,5 +16,5 @@ spec:
1716
protocol: TCP
1817
targetPort: 8080
1918
selector:
20-
{{- include "chart.selectorLabels" . | nindent 4 }}
21-
app.kubernetes.io/component: aibrix-controller-manager
19+
{{- include "aibrix.selectorLabels" . | nindent 4 }}
20+
app.kubernetes.io/component: aibrix-controller-manager

dist/chart/templates/gateway-instance/gateway.yaml

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,27 @@
22
apiVersion: gateway.networking.k8s.io/v1
33
kind: GatewayClass
44
metadata:
5-
name: aibrix-eg
6-
namespace: {{ .Release.Namespace }}
5+
name: {{ include "aibrix.fullname" . }}-eg
76
labels:
8-
{{- include "chart.labels" . | nindent 4 }}
7+
{{- include "aibrix.labels" . | nindent 4 }}
98
app.kubernetes.io/component: aibrix-gateway
109
spec:
1110
controllerName: gateway.envoyproxy.io/gatewayclass-controller
1211
parametersRef:
1312
group: gateway.envoyproxy.io
1413
kind: EnvoyProxy
15-
name: aibrix-custom-proxy-config
14+
name: {{ include "aibrix.fullname" . }}-custom-proxy-config
1615
namespace: {{ .Release.Namespace }}
1716
---
1817
apiVersion: gateway.networking.k8s.io/v1
1918
kind: Gateway
2019
metadata:
21-
name: aibrix-eg
22-
namespace: {{ .Release.Namespace }}
20+
name: {{ include "aibrix.fullname" . }}-eg
2321
labels:
24-
{{- include "chart.labels" . | nindent 4 }}
22+
{{- include "aibrix.labels" . | nindent 4 }}
2523
app.kubernetes.io/component: aibrix-gateway
2624
spec:
27-
gatewayClassName: aibrix-eg
25+
gatewayClassName: {{ include "aibrix.fullname" . }}-eg
2826
listeners:
2927
- name: http
3028
protocol: HTTP
@@ -33,8 +31,7 @@ spec:
3331
apiVersion: gateway.envoyproxy.io/v1alpha1
3432
kind: EnvoyProxy
3533
metadata:
36-
name: aibrix-custom-proxy-config
37-
namespace: {{ .Release.Namespace }}
34+
name: {{ include "aibrix.fullname" . }}-custom-proxy-config
3835
spec:
3936
provider:
4037
type: Kubernetes
@@ -65,7 +62,7 @@ spec:
6562
app.kubernetes.io/name: envoy
6663
app.kubernetes.io/component: proxy
6764
spec:
68-
{{- include "chart.imagePullSecrets" (dict "componentSecrets" .Values.gateway.envoyProxy.imagePullSecrets "globalSecrets") | nindent 18 }}
65+
{{- include "aibrix.imagePullSecrets" (dict "componentSecrets" .Values.gateway.envoyProxy.imagePullSecrets "globalSecrets") | nindent 18 }}
6966
containers:
7067
- name: envoy
7168
image: {{ .Values.gateway.envoyProxy.container.envoy.image }}
@@ -77,36 +74,34 @@ spec:
7774
apiVersion: gateway.envoyproxy.io/v1alpha1
7875
kind: ClientTrafficPolicy
7976
metadata:
80-
name: aibrix-client-connection-buffersize
81-
namespace: {{ .Release.Namespace }}
77+
name: {{ include "aibrix.fullname" . }}-client-connection-buffersize
8278
labels:
83-
{{- include "chart.labels" . | nindent 4 }}
79+
{{- include "aibrix.labels" . | nindent 4 }}
8480
app.kubernetes.io/component: aibrix-gateway
8581
spec:
8682
targetRefs:
8783
- group: gateway.networking.k8s.io
8884
kind: Gateway
89-
name: aibrix-eg
85+
name: {{ include "aibrix.fullname" . }}-eg
9086
connection:
9187
bufferLimit: {{ .Values.gateway.clientTrafficPolicy.connection.bufferLimit }}
9288
---
9389
apiVersion: gateway.envoyproxy.io/v1alpha1
9490
kind: EnvoyPatchPolicy
9591
metadata:
96-
name: aibrix-epp
97-
namespace: {{ .Release.Namespace }}
92+
name: {{ include "aibrix.fullname" . }}-epp
9893
labels:
99-
{{- include "chart.labels" . | nindent 4 }}
94+
{{- include "aibrix.labels" . | nindent 4 }}
10095
app.kubernetes.io/component: aibrix-gateway
10196
spec:
10297
type: "JSONPatch"
10398
targetRef:
10499
group: gateway.networking.k8s.io
105100
kind: Gateway
106-
name: aibrix-eg
101+
name: {{ include "aibrix.fullname" . }}-eg
107102
jsonPatches:
108103
- type: type.googleapis.com/envoy.config.route.v3.RouteConfiguration
109-
name: "{{ .Release.Namespace }}/aibrix-eg/http"
104+
name: {{ .Release.Namespace }}/{{ include "aibrix.fullname" . }}-eg/http
110105
operation:
111106
op: add
112107
path: "/virtual_hosts/0/routes/0"
@@ -140,4 +135,4 @@ spec:
140135
connect_timeout: {{ .Values.gateway.envoyPatchPolicy.route.connectTimeout }}
141136
lb_policy: CLUSTER_PROVIDED
142137
dns_lookup_family: V4_ONLY
143-
{{- end }}
138+
{{- end }}

0 commit comments

Comments
 (0)