Skip to content

Commit e8c607b

Browse files
authored
feat(charts): add "common.hostAliases" helper in common (#433)
* feat(charts): add "common.hostAliases" helper in common --------- On-behalf-of: @SAP [email protected] Signed-off-by: Angel Kafazov <[email protected]>
1 parent 59dea16 commit e8c607b

File tree

13 files changed

+259
-28
lines changed

13 files changed

+259
-28
lines changed

charts/common/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ description: A Helm chart containing reuse templates
44

55
type: library
66

7-
version: 0.7.0
7+
version: 0.8.0

charts/common/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ A Helm chart containing reuse templates
2323
| defaults.health.port | int | `8090` | health port |
2424
| defaults.health.readiness | object | `{"initialDelaySeconds":5,"path":"/readyz","periodSeconds":10}` | readiness probe parameters |
2525
| defaults.health.startup | object | `{"failureThreshold":30,"path":"/readyz"}` | startup probe parameters |
26+
| defaults.hostAliases.enabled | bool | `false` | toggle to enable/disable hostAliases configuration |
27+
| defaults.hostAliases.entries | list | `[{"hostnames":["kcp.api.portal.dev.local","portal.dev.local"],"ip":"10.96.188.4"}]` | host aliases |
2628
| defaults.imagePullPolicy | string | `"IfNotPresent"` | imagePullPolicy is the policy to use when pulling images for all charts |
2729
| defaults.istio.enabled | bool | `false` | toggle to enable/disable istio |
2830
| defaults.istio.gateway.name | string | `"gateway"` | name of the gateway |
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{{- /*
2+
Render hostAliases using lookup order:
3+
1. hostAliasesOverride
4+
2. global.hostAliases
5+
3. hostAliases
6+
4. defaults.hostAliases
7+
8+
Each of these keys is expected to be an array, or a map with "enabled" and "entries" keys.
9+
If the chosen one is empty or unset, render nothing.
10+
*/ -}}
11+
{{- define "common.hostAliases" -}}
12+
{{- $v := .Values -}}
13+
{{- $source := dict -}}
14+
{{- $aliases := list -}}
15+
{{- $aliasesEnabled := false -}}
16+
{{- $defaultKey := "common.defaults.hostAliases" -}}
17+
18+
{{- if and $v (hasKey $v "hostAliasesOverride") -}}
19+
{{- $source = index $v "hostAliasesOverride" -}}
20+
{{- else if and $v.global (hasKey $v.global "hostAliases") -}}
21+
{{- $source = index $v.global "hostAliases" -}}
22+
{{- else if and $v (hasKey $v "hostAliases") -}}
23+
{{- $source = index $v "hostAliases" -}}
24+
{{- else if eq (include "common.hasNestedKey" (dict "Values" $v "key" $defaultKey)) "true" }}
25+
{{- $source = index $v.common.defaults "hostAliases" -}}
26+
{{- end }}
27+
28+
{{- if $source -}}
29+
{{- if kindIs "slice" $source -}}
30+
{{- $aliases = $source -}}
31+
{{- else if and (kindIs "map" $source) (default true $source.enabled) -}}
32+
{{- $aliases = $source.entries | default $v.common.defaults.hostAliases.entries -}}
33+
{{- $aliasesEnabled = $source.enabled -}}
34+
{{- end -}}
35+
{{- end -}}
36+
37+
{{- if $aliasesEnabled -}}
38+
hostAliases:
39+
{{- toYaml $aliases | nindent 8 }}
40+
{{- end -}}
41+
{{- end }}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dependencies:
22
- name: common
33
repository: file://..
4-
version: 0.6.0
5-
digest: sha256:7ef6218c37c536063d41574993e0588c39c0267d6dd3764be36d17a16f9a21d8
6-
generated: "2025-10-28T08:07:32.522363+01:00"
4+
version: 0.8.0
5+
digest: sha256:8bc71da3fdc2d1bf0560bb58038a292105c1a87d825e2c003768bbe83126b550
6+
generated: "2025-11-17T15:05:29.464986171+02:00"

charts/common/test-chart/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ appVersion: "1.16.0"
2525

2626
dependencies:
2727
- name: common
28-
version: 0.6.0
28+
version: 0.8.0
2929
repository: file://..

charts/common/test-chart/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ A Helm chart for Kubernetes
3636

3737
| Repository | Name | Version |
3838
|------------|------|---------|
39-
| file://.. | common | 0.6.0 |
39+
| file://.. | common | 0.8.0 |
4040

4141
## Values
4242

-5.64 KB
Binary file not shown.
6.28 KB
Binary file not shown.

charts/common/test-chart/templates/deployment.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ spec:
1313
{{- include "common.labelMatcher" . | indent 8 }}
1414
spec:
1515
{{- include "common.pod.securityContext" . | indent 6 }}
16-
terminationGracePeriodSeconds: {{ include "common.terminationGracePeriodSeconds" .}}
16+
terminationGracePeriodSeconds: {{ include "common.terminationGracePeriodSeconds" . }}
17+
{{ include "common.hostAliases" . | indent 0 }}
1718
containers:
1819
- {{- include "common.podBasics" . | indent 8 }}
1920
{{- include "common.container.securityContext" . | indent 8 }}

charts/common/test-chart/tests/__snapshot__/deployment_test.yaml.snap

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,99 @@ test global region:
352352
terminationGracePeriodSeconds: 10
353353
volumeMounts: null
354354
volumes: null
355+
test host aliases:
356+
1: |
357+
apiVersion: apps/v1
358+
kind: Deployment
359+
metadata:
360+
name: RELEASE-NAME-test-chart
361+
spec:
362+
revisionHistoryLimit: 3
363+
selector:
364+
matchLabels:
365+
app: RELEASE-NAME-test-chart
366+
strategy:
367+
rollingUpdate:
368+
maxSurge: 5
369+
maxUnavailable: 0
370+
type: RollingUpdate
371+
template:
372+
metadata:
373+
labels:
374+
app: RELEASE-NAME-test-chart
375+
spec:
376+
automountServiceAccountToken: true
377+
containers:
378+
- args:
379+
- -- operator
380+
- --leader-elect
381+
- --metrics-bind-address=:9090
382+
- --health-probe-bind-address=:8090
383+
- --log-level=warn
384+
- --region=local
385+
- --environment=local
386+
- --image-tag=0.1.0
387+
- --image-name="ghcr.io/your-org/your-image"
388+
- --shutdown-timeout=1m
389+
- --max-concurrent-reconciles=10
390+
env: null
391+
image: ghcr.io/your-org/your-image:0.1.0
392+
imagePullPolicy: IfNotPresent
393+
livenessProbe:
394+
failureThreshold: 1
395+
httpGet:
396+
path: /healthz
397+
port: 8090
398+
periodSeconds: 10
399+
name: RELEASE-NAME-test-chart
400+
ports:
401+
- containerPort: 8080
402+
name: http
403+
protocol: TCP
404+
- containerPort: 9090
405+
name: metrics
406+
protocol: TCP
407+
- containerPort: 8090
408+
name: health-port
409+
protocol: TCP
410+
readinessProbe:
411+
httpGet:
412+
path: /readyz
413+
port: 8090
414+
initialDelaySeconds: 5
415+
periodSeconds: 10
416+
resources:
417+
limits:
418+
memory: 512Mi
419+
requests:
420+
cpu: 40m
421+
memory: 50Mi
422+
securityContext:
423+
readOnlyRootFilesystem: true
424+
runAsNonRoot: true
425+
seccompProfile:
426+
type: RuntimeDefault
427+
startupProbe:
428+
failureThreshold: 30
429+
httpGet:
430+
path: /readyz
431+
port: 8090
432+
periodSeconds: 10
433+
hostAliases:
434+
- hostnames:
435+
- local.test
436+
ip: 127.0.0.1
437+
- hostnames:
438+
- my.test
439+
ip: 192.168.1.1
440+
securityContext:
441+
runAsNonRoot: true
442+
seccompProfile:
443+
type: RuntimeDefault
444+
serviceAccountName: RELEASE-NAME-test-chart
445+
terminationGracePeriodSeconds: 10
446+
volumeMounts: null
447+
volumes: null
355448
test name override:
356449
1: |
357450
apiVersion: apps/v1

0 commit comments

Comments
 (0)