Skip to content

Commit 68e0d05

Browse files
committed
Put both architectures in one Service
The arm64 variant had its own `app.kubernetes.io/name`, so the chart made a second Service and a second PodDisruptionBudget for it. The HTTPRoute backs only the amd64 Service, so the arm64 pods never received traffic. Both architectures now keep the same name label. arm64 adds `app.kubernetes.io/component: arm64`, which keeps its Deployment selector unique. One Service and one budget now cover the pods of both, and the load balancer sends traffic to both. This makes the architecture difference one line in the selector helper, so the per-architecture copies in the Service and the budget templates are deleted, and `lago-rails.architecture.labels` is deleted. That helper was a copy of `lago-rails.labels` with one line different. All templates use the common helper again. The amd64 output does not change. CAUTION: `spec.selector` of a Deployment is immutable. Delete each live `*-arm64` Deployment one time before the next sync.
1 parent a380dcf commit 68e0d05

6 files changed

Lines changed: 48 additions & 70 deletions

File tree

charts/lago-rails/templates/_helpers.tpl

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Common labels
3737
*/}}
3838
{{- define "lago-rails.labels" -}}
3939
helm.sh/chart: {{ include "lago-rails.chart" . }}
40-
{{ include "lago-rails.selectorLabels" . }}
40+
{{ include "lago-rails.architecture.selectorLabels" . }}
4141
{{- if .Chart.AppVersion }}
4242
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
4343
{{- end }}
@@ -73,32 +73,14 @@ amd64 name.
7373
{{- end }}
7474

7575
{{/*
76-
Create architecture-specific selector labels. The amd64 result delegates to
77-
the existing helper so its rendered labels do not change.
76+
Create architecture-specific selector labels. Both architectures keep the same
77+
`app.kubernetes.io/name`, so the Service selects the pods of both. arm64 adds
78+
`app.kubernetes.io/component`, which keeps its Deployment selector unique.
7879
*/}}
7980
{{- define "lago-rails.architecture.selectorLabels" -}}
80-
{{- if eq (include "lago-rails.architecture.isArm64" .) "true" -}}
81-
app.kubernetes.io/name: {{ printf "%s-arm64" .Values.internalArchitectureName | trunc 63 | trimSuffix "-" }}
82-
app.kubernetes.io/instance: {{ .Release.Name }}
83-
{{- else -}}
8481
{{- include "lago-rails.selectorLabels" . -}}
85-
{{- end -}}
86-
{{- end }}
87-
88-
{{/*
89-
Create architecture-specific labels. The amd64 result delegates to the
90-
existing helper so its rendered labels do not change.
91-
*/}}
92-
{{- define "lago-rails.architecture.labels" -}}
93-
{{- if eq (include "lago-rails.architecture.isArm64" .) "true" -}}
94-
helm.sh/chart: {{ include "lago-rails.chart" . }}
95-
{{ include "lago-rails.architecture.selectorLabels" . }}
96-
{{- if .Chart.AppVersion }}
97-
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
98-
{{- end }}
99-
app.kubernetes.io/managed-by: {{ .Release.Service }}
100-
{{- else -}}
101-
{{- include "lago-rails.labels" . -}}
82+
{{- if eq (include "lago-rails.architecture.isArm64" .) "true" }}
83+
app.kubernetes.io/component: arm64
10284
{{- end -}}
10385
{{- end }}
10486

charts/lago-rails/templates/deployment.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ metadata:
88
{{- toYaml . | nindent 4 }}
99
{{- end }}
1010
labels:
11-
{{- include "lago-rails.architecture.labels" . | nindent 4 }}
11+
{{- include "lago-rails.labels" . | nindent 4 }}
1212
spec:
1313
{{- if not .Values.autoscaling.enabled }}
1414
replicas: {{ .Values.replicaCount }}
@@ -23,7 +23,7 @@ spec:
2323
{{- toYaml . | nindent 8 }}
2424
{{- end }}
2525
labels:
26-
{{- include "lago-rails.architecture.labels" . | nindent 8 }}
26+
{{- include "lago-rails.labels" . | nindent 8 }}
2727
{{- with .Values.podLabels }}
2828
{{- toYaml . | nindent 8 }}
2929
{{- end }}
@@ -480,7 +480,6 @@ spec:
480480
{{- $_ := set $amd64Values "tolerations" (concat .Values.tolerations $amd64.tolerations) }}
481481
{{- $amd64Context := dict "Values" $amd64Values "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Template" .Template "Files" .Files }}
482482
{{- $architectureFullname := include "lago-rails.fullname" $amd64Context }}
483-
{{- $architectureName := include "lago-rails.name" $amd64Context }}
484483
{{- if .Values.global.architectures.amd64.enabled }}
485484
{{ include "lago-rails.deployment" $amd64Context }}
486485
{{- end }}
@@ -492,7 +491,6 @@ spec:
492491
{{- $arm64Values := deepCopy .Values }}
493492
{{- $_ := set $arm64Values "internalArchitecture" "arm64" }}
494493
{{- $_ := set $arm64Values "internalArchitectureFullname" $architectureFullname }}
495-
{{- $_ := set $arm64Values "internalArchitectureName" $architectureName }}
496494
{{- $_ := set $arm64Values "replicaCount" $arm64.replicaCount }}
497495
{{- $_ := set $arm64Values "nodeSelector" (mustMergeOverwrite (deepCopy .Values.nodeSelector) $arm64.nodeSelector) }}
498496
{{- $_ := set $arm64Values "tolerations" (concat .Values.tolerations $arm64.tolerations) }}

charts/lago-rails/templates/hpa.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ kind: HorizontalPodAutoscaler
44
metadata:
55
name: {{ include "lago-rails.architecture.fullname" . }}
66
labels:
7-
{{- include "lago-rails.architecture.labels" . | nindent 4 }}
7+
{{- include "lago-rails.labels" . | nindent 4 }}
88
spec:
99
scaleTargetRef:
1010
apiVersion: apps/v1
@@ -42,7 +42,6 @@ spec:
4242
{{- $arm64Values := deepCopy .Values }}
4343
{{- $_ := set $arm64Values "internalArchitecture" "arm64" }}
4444
{{- $_ := set $arm64Values "internalArchitectureFullname" (include "lago-rails.fullname" .) }}
45-
{{- $_ := set $arm64Values "internalArchitectureName" (include "lago-rails.name" .) }}
4645
{{- $_ := set $arm64Values "autoscaling" $arm64.autoscaling }}
4746
{{- $arm64Context := dict "Values" $arm64Values "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Template" .Template "Files" .Files }}
4847
{{ include "lago-rails.hpa" $arm64Context }}
Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
{{- define "lago-rails.pdb" -}}
1+
{{/*
2+
One PodDisruptionBudget for all architectures. The pods of both serve the same
3+
Service, so one budget applies to them together.
4+
*/}}
5+
{{- if .Values.podDisruptionBudget.enabled }}
26
apiVersion: policy/v1
37
kind: PodDisruptionBudget
48
metadata:
5-
name: {{ include "lago-rails.architecture.fullname" . }}
9+
name: {{ include "lago-rails.fullname" . }}
610
labels:
7-
{{- include "lago-rails.architecture.labels" . | nindent 4 }}
11+
{{- include "lago-rails.labels" . | nindent 4 }}
812
spec:
913
{{- with .Values.podDisruptionBudget.minAvailable }}
1014
minAvailable: {{ . }}
@@ -14,21 +18,5 @@ spec:
1418
{{- end }}
1519
selector:
1620
matchLabels:
17-
{{- include "lago-rails.architecture.selectorLabels" . | nindent 6 }}
18-
{{- end }}
19-
20-
{{- if .Values.podDisruptionBudget.enabled }}
21-
{{- $amd64Values := deepCopy .Values }}
22-
{{- $amd64Context := dict "Values" $amd64Values "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Template" .Template "Files" .Files }}
23-
{{ include "lago-rails.pdb" $amd64Context }}
24-
{{- $arm64 := .Values.architectures.arm64 }}
25-
{{- if and .Values.global.architectures.arm64.enabled (or (gt (int $arm64.replicaCount) 0) $arm64.autoscaling.enabled) }}
26-
---
27-
{{- $arm64Values := deepCopy .Values }}
28-
{{- $_ := set $arm64Values "internalArchitecture" "arm64" }}
29-
{{- $_ := set $arm64Values "internalArchitectureFullname" (include "lago-rails.fullname" .) }}
30-
{{- $_ := set $arm64Values "internalArchitectureName" (include "lago-rails.name" .) }}
31-
{{- $arm64Context := dict "Values" $arm64Values "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Template" .Template "Files" .Files }}
32-
{{ include "lago-rails.pdb" $arm64Context }}
33-
{{- end }}
21+
{{- include "lago-rails.selectorLabels" . | nindent 6 }}
3422
{{- end }}
Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
{{- define "lago-rails.service" -}}
1+
{{/*
2+
One Service for all architectures. The selector has no
3+
`app.kubernetes.io/component`, so it matches amd64 pods and arm64 pods.
4+
*/}}
5+
{{- if .Values.service.enabled }}
26
apiVersion: v1
37
kind: Service
48
metadata:
5-
name: {{ include "lago-rails.architecture.fullname" . }}
9+
name: {{ include "lago-rails.fullname" . }}
610
labels:
7-
{{- include "lago-rails.architecture.labels" . | nindent 4 }}
11+
{{- include "lago-rails.labels" . | nindent 4 }}
812
spec:
913
type: {{ .Values.service.type }}
1014
ports:
@@ -13,21 +17,5 @@ spec:
1317
protocol: TCP
1418
name: http
1519
selector:
16-
{{- include "lago-rails.architecture.selectorLabels" . | nindent 4 }}
17-
{{- end }}
18-
19-
{{- if .Values.service.enabled }}
20-
{{- $amd64Values := deepCopy .Values }}
21-
{{- $amd64Context := dict "Values" $amd64Values "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Template" .Template "Files" .Files }}
22-
{{ include "lago-rails.service" $amd64Context }}
23-
{{- $arm64 := .Values.architectures.arm64 }}
24-
{{- if and .Values.global.architectures.arm64.enabled (or (gt (int $arm64.replicaCount) 0) $arm64.autoscaling.enabled) }}
25-
---
26-
{{- $arm64Values := deepCopy .Values }}
27-
{{- $_ := set $arm64Values "internalArchitecture" "arm64" }}
28-
{{- $_ := set $arm64Values "internalArchitectureFullname" (include "lago-rails.fullname" .) }}
29-
{{- $_ := set $arm64Values "internalArchitectureName" (include "lago-rails.name" .) }}
30-
{{- $arm64Context := dict "Values" $arm64Values "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Template" .Template "Files" .Files }}
31-
{{ include "lago-rails.service" $arm64Context }}
32-
{{- end }}
20+
{{- include "lago-rails.selectorLabels" . | nindent 4 }}
3321
{{- end }}

charts/lago/tests/architecture_test.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ suite: Test amd64 and arm64 API and worker deployments
22
templates:
33
- charts/api/templates/deployment.yaml
44
- charts/worker/templates/deployment.yaml
5+
- charts/api/templates/service.yaml
56

67
set:
78
global:
@@ -201,6 +202,28 @@ tests:
201202
- hasDocuments:
202203
count: 1
203204

205+
- it: gives the arm64 API deployment the shared name and the architecture label
206+
template: charts/api/templates/deployment.yaml
207+
documentIndex: 1
208+
asserts:
209+
- equal:
210+
path: spec.selector.matchLabels
211+
value:
212+
app.kubernetes.io/name: lago-api
213+
app.kubernetes.io/instance: RELEASE-NAME
214+
app.kubernetes.io/component: arm64
215+
216+
- it: renders one API service that selects both architectures
217+
template: charts/api/templates/service.yaml
218+
asserts:
219+
- hasDocuments:
220+
count: 1
221+
- equal:
222+
path: spec.selector
223+
value:
224+
app.kubernetes.io/name: lago-api
225+
app.kubernetes.io/instance: RELEASE-NAME
226+
204227
- it: renders an arm64 worker without replicas when KEDA controls it
205228
template: charts/worker/templates/deployment.yaml
206229
set:

0 commit comments

Comments
 (0)