Skip to content

Commit 8df8570

Browse files
committed
refactor: simplify service/ingress/deployment templates
Removes conditional logic based on `endpoints` vs `port` for service, ingress, and deployment templates. - Simplifies template logic by assuming all apps will define endpoints. - Removes redundant `if` statements, making the templates easier to read and maintain. - Improves consistency across application definitions.
1 parent 149415f commit 8df8570

File tree

3 files changed

+3
-60
lines changed

3 files changed

+3
-60
lines changed

chart/templates/app/deployment.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,12 @@ spec:
4848
exec:
4949
command: ["/bin/sh", "-c", "sleep 10"]
5050
ports:
51-
{{- if $app.endpoints }}
5251
{{- range $service := $app.endpoints }}
5352
- containerPort: {{ $service.port }}
5453
{{- end }}
55-
{{- else }}
56-
- containerPort: {{ $app.port }}
57-
{{- end }}
5854
readinessProbe:
5955
tcpSocket:
60-
{{- if $app.endpoints }}
6156
port: {{ (index $app.endpoints 0).port }}
62-
{{- else }}
63-
port: {{ $app.port }}
64-
{{- end }}
6557
initialDelaySeconds: 20
6658
periodSeconds: 10
6759
successThreshold: 3
Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{{- range $app := .Values.applications }}
22
{{- if $app.git.hash }}
3-
{{- if $app.endpoints }}
43
{{- range $service := $app.endpoints }}
54
{{- range $route := $service.routes }}
65
{{- $domain := regexFind "^[^/]+" $route }}
@@ -27,38 +26,11 @@ spec:
2726
{{- end }}
2827
{{- end }}
2928
{{- end }}
30-
{{- else }}
31-
{{- range $route := $app.routes }}
32-
{{- $domain := regexFind "^[^/]+" $route }}
33-
{{- $path := regexFind "/.*" $route | default "" }}
34-
---
35-
apiVersion: traefik.io/v1alpha1
36-
kind: IngressRoute
37-
metadata:
38-
name: {{ $.Values.project }}-{{ $app.name }}-{{ $domain | replace "." "-" }}{{ if $path }}{{ $path | replace "/" "-" }}{{ end }}-route
39-
namespace: {{ $.Values.project }}
40-
spec:
41-
entryPoints:
42-
- web
43-
- websecure
44-
routes:
45-
- match: Host(`{{ $domain }}`){{ if $path }} && PathPrefix(`{{ $path }}`){{ end }}
46-
kind: Rule
47-
services:
48-
- name: {{ $app.name }}
49-
port: {{ $app.port }}
50-
{{- if $path }}
51-
middlewares:
52-
- name: {{ $.Values.project }}-{{ $app.name }}-{{ $path | replace "/" "-" | trimPrefix "-" }}-strip-prefix
53-
{{- end }}
54-
{{- end }}
55-
{{- end }}
5629
{{- end }}
5730
{{- end }}
5831

5932
{{- range $app := .Values.applications }}
6033
{{- if $app.git.hash }}
61-
{{- if $app.endpoints }}
6234
{{- range $service := $app.endpoints }}
6335
{{- range $route := $service.routes }}
6436
{{- $path := regexFind "/.*" $route | default "" }}
@@ -76,22 +48,5 @@ spec:
7648
{{- end }}
7749
{{- end }}
7850
{{- end }}
79-
{{- else }}
80-
{{- range $route := $app.routes }}
81-
{{- $path := regexFind "/.*" $route | default "" }}
82-
{{- if $path }}
83-
---
84-
apiVersion: traefik.io/v1alpha1
85-
kind: Middleware
86-
metadata:
87-
name: {{ $.Values.project }}-{{ $app.name }}-{{ $path | replace "/" "-" | trimPrefix "-" }}-strip-prefix
88-
namespace: {{ $.Values.project }}
89-
spec:
90-
stripPrefix:
91-
prefixes:
92-
- {{ $path }}
93-
{{- end }}
94-
{{- end }}
95-
{{- end }}
9651
{{- end }}
9752
{{- end }}

chart/templates/app/service.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ metadata:
88
namespace: {{ $.Values.project }}
99
spec:
1010
ports:
11-
{{- if $app.endpoints }}
12-
{{- range $service := $app.endpoints }}
13-
- port: {{ $service.port }}
11+
{{- range $index, $service := $app.endpoints }}
12+
- name: {{ if $service.name }}{{ $service.name }}{{ else }}port-{{ $service.port }}{{ end }}
13+
port: {{ $service.port }}
1414
targetPort: {{ $service.port }}
1515
{{- end }}
16-
{{- else }}
17-
- port: {{ $app.port }}
18-
targetPort: {{ $app.port }}
19-
{{- end }}
2016
selector:
2117
app: {{ $app.name }}-app
2218
{{- end }}

0 commit comments

Comments
 (0)