Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions charts/lago-rails/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Common labels
*/}}
{{- define "lago-rails.labels" -}}
helm.sh/chart: {{ include "lago-rails.chart" . }}
{{ include "lago-rails.selectorLabels" . }}
{{ include "lago-rails.architecture.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand Down Expand Up @@ -73,32 +73,40 @@ amd64 name.
{{- end }}

{{/*
Create architecture-specific selector labels. The amd64 result delegates to
the existing helper so its rendered labels do not change.
Create architecture-specific selector labels. Each architecture keeps its own
`app.kubernetes.io/name`, so a Deployment selector matches only its own pods.
The Deployment selector is immutable, so this helper must not change.
*/}}
{{- define "lago-rails.architecture.selectorLabels" -}}
{{- if eq (include "lago-rails.architecture.isArm64" .) "true" -}}
app.kubernetes.io/name: {{ printf "%s-arm64" .Values.internalArchitectureName | trunc 63 | trimSuffix "-" }}
app.kubernetes.io/name: {{ printf "%s-arm64" (include "lago-rails.name" .) | trunc 63 | trimSuffix "-" }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- else -}}
{{- include "lago-rails.selectorLabels" . -}}
{{- end -}}
{{- end }}

{{/*
Create architecture-specific labels. The amd64 result delegates to the
existing helper so its rendered labels do not change.
The architecture-independent label that every pod of this workload carries. The
Service and the PodDisruptionBudget select it, so they reach the pods of all
architectures.
*/}}
{{- define "lago-rails.architecture.labels" -}}
{{- if eq (include "lago-rails.architecture.isArm64" .) "true" -}}
helm.sh/chart: {{ include "lago-rails.chart" . }}
{{ include "lago-rails.architecture.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- define "lago-rails.componentLabel" -}}
app.kubernetes.io/component: {{ include "lago-rails.name" . }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}

{{/*
Selector labels for the Service and the PodDisruptionBudget. arm64 pods have a
different `app.kubernetes.io/name`, so the selector moves to the `component`
label when arm64 is enabled. Every pod already carries that label, because the
chart adds it to all pod templates.
*/}}
{{- define "lago-rails.service.selectorLabels" -}}
{{- if .Values.global.architectures.arm64.enabled -}}
app.kubernetes.io/instance: {{ .Release.Name }}
{{ include "lago-rails.componentLabel" . }}
{{- else -}}
{{- include "lago-rails.labels" . -}}
{{- include "lago-rails.selectorLabels" . -}}
{{- end -}}
{{- end }}

Expand Down
7 changes: 3 additions & 4 deletions charts/lago-rails/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "lago-rails.architecture.labels" . | nindent 4 }}
{{- include "lago-rails.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
Expand All @@ -23,7 +23,8 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "lago-rails.architecture.labels" . | nindent 8 }}
{{- include "lago-rails.labels" . | nindent 8 }}
{{- include "lago-rails.componentLabel" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -480,7 +481,6 @@ spec:
{{- $_ := set $amd64Values "tolerations" (concat .Values.tolerations $amd64.tolerations) }}
{{- $amd64Context := dict "Values" $amd64Values "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Template" .Template "Files" .Files }}
{{- $architectureFullname := include "lago-rails.fullname" $amd64Context }}
{{- $architectureName := include "lago-rails.name" $amd64Context }}
{{- if .Values.global.architectures.amd64.enabled }}
{{ include "lago-rails.deployment" $amd64Context }}
{{- end }}
Expand All @@ -492,7 +492,6 @@ spec:
{{- $arm64Values := deepCopy .Values }}
{{- $_ := set $arm64Values "internalArchitecture" "arm64" }}
{{- $_ := set $arm64Values "internalArchitectureFullname" $architectureFullname }}
{{- $_ := set $arm64Values "internalArchitectureName" $architectureName }}
{{- $_ := set $arm64Values "replicaCount" $arm64.replicaCount }}
{{- $_ := set $arm64Values "nodeSelector" (mustMergeOverwrite (deepCopy .Values.nodeSelector) $arm64.nodeSelector) }}
{{- $_ := set $arm64Values "tolerations" (concat .Values.tolerations $arm64.tolerations) }}
Expand Down
3 changes: 1 addition & 2 deletions charts/lago-rails/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: HorizontalPodAutoscaler
metadata:
name: {{ include "lago-rails.architecture.fullname" . }}
labels:
{{- include "lago-rails.architecture.labels" . | nindent 4 }}
{{- include "lago-rails.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
Expand Down Expand Up @@ -42,7 +42,6 @@ spec:
{{- $arm64Values := deepCopy .Values }}
{{- $_ := set $arm64Values "internalArchitecture" "arm64" }}
{{- $_ := set $arm64Values "internalArchitectureFullname" (include "lago-rails.fullname" .) }}
{{- $_ := set $arm64Values "internalArchitectureName" (include "lago-rails.name" .) }}
{{- $_ := set $arm64Values "autoscaling" $arm64.autoscaling }}
{{- $arm64Context := dict "Values" $arm64Values "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Template" .Template "Files" .Files }}
{{ include "lago-rails.hpa" $arm64Context }}
Expand Down
28 changes: 8 additions & 20 deletions charts/lago-rails/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{{- define "lago-rails.pdb" -}}
{{/*
One PodDisruptionBudget for all architectures. The pods of both serve the same
Service, so one budget applies to them together.
*/}}
{{- if .Values.podDisruptionBudget.enabled }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "lago-rails.architecture.fullname" . }}
name: {{ include "lago-rails.fullname" . }}
labels:
{{- include "lago-rails.architecture.labels" . | nindent 4 }}
{{- include "lago-rails.labels" . | nindent 4 }}
spec:
{{- with .Values.podDisruptionBudget.minAvailable }}
minAvailable: {{ . }}
Expand All @@ -14,21 +18,5 @@ spec:
{{- end }}
selector:
matchLabels:
{{- include "lago-rails.architecture.selectorLabels" . | nindent 6 }}
{{- end }}

{{- if .Values.podDisruptionBudget.enabled }}
{{- $amd64Values := deepCopy .Values }}
{{- $amd64Context := dict "Values" $amd64Values "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Template" .Template "Files" .Files }}
{{ include "lago-rails.pdb" $amd64Context }}
{{- $arm64 := .Values.architectures.arm64 }}
{{- if and .Values.global.architectures.arm64.enabled (or (gt (int $arm64.replicaCount) 0) $arm64.autoscaling.enabled) }}
---
{{- $arm64Values := deepCopy .Values }}
{{- $_ := set $arm64Values "internalArchitecture" "arm64" }}
{{- $_ := set $arm64Values "internalArchitectureFullname" (include "lago-rails.fullname" .) }}
{{- $_ := set $arm64Values "internalArchitectureName" (include "lago-rails.name" .) }}
{{- $arm64Context := dict "Values" $arm64Values "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Template" .Template "Files" .Files }}
{{ include "lago-rails.pdb" $arm64Context }}
{{- end }}
{{- include "lago-rails.service.selectorLabels" . | nindent 6 }}
{{- end }}
28 changes: 8 additions & 20 deletions charts/lago-rails/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{{- define "lago-rails.service" -}}
{{/*
One Service for all architectures. The selector has no
`app.kubernetes.io/component`, so it matches amd64 pods and arm64 pods.
*/}}
{{- if .Values.service.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "lago-rails.architecture.fullname" . }}
name: {{ include "lago-rails.fullname" . }}
labels:
{{- include "lago-rails.architecture.labels" . | nindent 4 }}
{{- include "lago-rails.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
Expand All @@ -13,21 +17,5 @@ spec:
protocol: TCP
name: http
selector:
{{- include "lago-rails.architecture.selectorLabels" . | nindent 4 }}
{{- end }}

{{- if .Values.service.enabled }}
{{- $amd64Values := deepCopy .Values }}
{{- $amd64Context := dict "Values" $amd64Values "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Template" .Template "Files" .Files }}
{{ include "lago-rails.service" $amd64Context }}
{{- $arm64 := .Values.architectures.arm64 }}
{{- if and .Values.global.architectures.arm64.enabled (or (gt (int $arm64.replicaCount) 0) $arm64.autoscaling.enabled) }}
---
{{- $arm64Values := deepCopy .Values }}
{{- $_ := set $arm64Values "internalArchitecture" "arm64" }}
{{- $_ := set $arm64Values "internalArchitectureFullname" (include "lago-rails.fullname" .) }}
{{- $_ := set $arm64Values "internalArchitectureName" (include "lago-rails.name" .) }}
{{- $arm64Context := dict "Values" $arm64Values "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Template" .Template "Files" .Files }}
{{ include "lago-rails.service" $arm64Context }}
{{- end }}
{{- include "lago-rails.service.selectorLabels" . | nindent 4 }}
{{- end }}
54 changes: 54 additions & 0 deletions charts/lago/tests/architecture_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ suite: Test amd64 and arm64 API and worker deployments
templates:
- charts/api/templates/deployment.yaml
- charts/worker/templates/deployment.yaml
- charts/api/templates/service.yaml

set:
global:
Expand Down Expand Up @@ -201,6 +202,59 @@ tests:
- hasDocuments:
count: 1

- it: keeps a separate name in each deployment selector
template: charts/api/templates/deployment.yaml
asserts:
- equal:
path: spec.selector.matchLabels
value:
app.kubernetes.io/name: lago-api
app.kubernetes.io/instance: RELEASE-NAME
documentIndex: 0
- equal:
path: spec.selector.matchLabels
value:
app.kubernetes.io/name: lago-api-arm64
app.kubernetes.io/instance: RELEASE-NAME
documentIndex: 1

- it: gives the pods of both architectures the same component label
template: charts/api/templates/deployment.yaml
asserts:
- equal:
path: spec.template.metadata.labels["app.kubernetes.io/component"]
value: lago-api
documentIndex: 0
- equal:
path: spec.template.metadata.labels["app.kubernetes.io/component"]
value: lago-api
documentIndex: 1

- it: renders one API service that selects the component when arm64 is on
template: charts/api/templates/service.yaml
asserts:
- hasDocuments:
count: 1
- equal:
path: spec.selector
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/component: lago-api

- it: keeps the original API service selector when arm64 is off
template: charts/api/templates/service.yaml
set:
global:
architectures:
arm64:
enabled: false
asserts:
- equal:
path: spec.selector
value:
app.kubernetes.io/name: lago-api
app.kubernetes.io/instance: RELEASE-NAME

- it: renders an arm64 worker without replicas when KEDA controls it
template: charts/worker/templates/deployment.yaml
set:
Expand Down
Loading