item-atlas/deploy/helm/item-atlas/templates/workloads.yaml

133 lines
4.9 KiB
YAML

{{- $root := . -}}
{{- $gateway := printf "%s-gateway" .Release.Name -}}
{{- $inventory := printf "%s-inventory-service" .Release.Name -}}
{{- $intake := printf "%s-intake-service" .Release.Name -}}
{{- $candidate := printf "%s-inventory-canary" .Release.Name -}}
{{- $workloads := list (dict "name" $gateway "image" "gateway" "port" 8080 "tag" .Values.image.tag) (dict "name" $inventory "image" "inventory-service" "port" 8081 "tag" .Values.image.tag "secret" .Values.inventorySecret) (dict "name" $intake "image" "intake-service" "port" 8082 "tag" .Values.image.tag "secret" .Values.intakeSecret) -}}
{{- if .Values.canary.enabled -}}
{{- $weight := int .Values.canary.weight -}}
{{- if or (lt $weight 1) (gt $weight 99) -}}
{{- fail "canary.weight must be between 1 and 99" -}}
{{- end -}}
{{- $workloads = append $workloads (dict "name" $candidate "image" "inventory-service" "port" 8081 "tag" (required "canary.tag is required" .Values.canary.tag) "secret" .Values.inventorySecret "candidate" true) -}}
{{- end -}}
{{- range $workload := $workloads }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $workload.name }}
labels:
app.kubernetes.io/name: {{ $workload.name }}
app.kubernetes.io/instance: {{ $root.Release.Name }}
spec:
replicas: 1
revisionHistoryLimit: 5
progressDeadlineSeconds: 660
selector:
matchLabels:
app.kubernetes.io/name: {{ $workload.name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ $workload.name }}
app.kubernetes.io/instance: {{ $root.Release.Name }}
spec:
automountServiceAccountToken: false
{{- with $root.Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
runAsNonRoot: true
runAsUser: 10001
runAsGroup: 10001
seccompProfile:
type: RuntimeDefault
containers:
- name: app
image: {{ printf "%s/item-atlas-%s:%s" $root.Values.image.repository $workload.image $workload.tag | quote }}
imagePullPolicy: {{ $root.Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ $workload.port }}
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
env:
- name: PORT
value: {{ $workload.port | quote }}
- name: JAVA_TOOL_OPTIONS
value: "-XX:MaxRAMPercentage=65.0"
- name: ATLAS_TRACE_SAMPLE_RATE
value: {{ $root.Values.observability.traceSampleRate | quote }}
{{- with $root.Values.observability.otlpTracesEndpoint }}
- name: ATLAS_OTLP_TRACES_ENABLED
value: "true"
- name: ATLAS_OTLP_TRACES_ENDPOINT
value: {{ . | quote }}
{{- end }}
{{- if ne $workload.image "gateway" }}
- name: SPRING_PROFILES_ACTIVE
value: {{ $root.Values.profile | quote }}
{{- end }}
{{- if ne $workload.image "inventory-service" }}
- name: ATLAS_INVENTORY_URL
value: {{ printf "http://%s:8081" $inventory | quote }}
{{- end }}
{{- if eq $workload.image "gateway" }}
- name: ATLAS_INTAKE_URL
value: {{ printf "http://%s:8082" $intake | quote }}
{{- if $root.Values.canary.enabled }}
- name: ATLAS_CANARY_INVENTORY_ENABLED
value: "true"
- name: ATLAS_CANARY_INVENTORY_URI
value: {{ printf "http://%s:8081" $candidate | quote }}
- name: ATLAS_CANARY_INVENTORY_WEIGHT
value: {{ $root.Values.canary.weight | quote }}
{{- end }}
{{- end }}
{{- if $workload.candidate }}
- name: SPRING_FLYWAY_ENABLED
value: "false"
{{- end }}
{{- with $workload.secret }}
envFrom:
- secretRef:
name: {{ . | quote }}
{{- end }}
startupProbe:
httpGet:
path: /actuator/health/liveness
port: http
periodSeconds: 4
failureThreshold: 40
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: http
periodSeconds: 5
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: http
periodSeconds: 10
resources:
{{- toYaml (index $root.Values.resources $workload.image) | nindent 12 }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ $workload.name }}
labels:
app.kubernetes.io/instance: {{ $root.Release.Name }}
spec:
selector:
app.kubernetes.io/name: {{ $workload.name }}
ports:
- name: http
port: {{ $workload.port }}
targetPort: http
{{- end }}