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
2 changes: 1 addition & 1 deletion charts/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ maintainers:
- email: alex@kharkevich.org
name: Alexander Kharkevich
name: common
version: 2.1.5
version: 2.2.0
2 changes: 1 addition & 1 deletion charts/common/templates/_affinity.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- define "common.affinity"}}
{{- $labels := default (tuple "kubernetes.io/hostname" "failure-domain.beta.kubernetes.io/zone") .Values.antiAffinityLabels -}}
{{- $labels := default (tuple "kubernetes.io/hostname" "topology.kubernetes.io/zone") .Values.antiAffinityLabels -}}
{{- $nodeAffinity := .Values.nodeAffinity | default (dict) | toYaml -}}
affinity:
nodeAffinity: {{- $nodeAffinity | nindent 4 }}
Expand Down
34 changes: 33 additions & 1 deletion charts/common/templates/_chartref.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
{{- /*
Helpers for safe access to .Chart fields.
In Helm 3, .Chart is a Go struct with uppercase fields (.Chart.Name);
accessing lowercase (.Chart.name) causes a hard error.
In Helm 4 and after JSON round-trip (deepCopy | toJson | fromJson),
.Chart is a map — uppercase keys in Helm 4, lowercase in JSON round-trip.
The map branch handles both by trying uppercase first, falling back to lowercase.
*/ -}}
{{- define "common.chart.name" -}}
{{- if kindIs "map" .Chart -}}
{{- default .Chart.name .Chart.Name -}}
{{- else -}}
{{- .Chart.Name -}}
{{- end -}}
{{- end -}}

{{- define "common.chart.version" -}}
{{- if kindIs "map" .Chart -}}
{{- default .Chart.version .Chart.Version -}}
{{- else -}}
{{- .Chart.Version -}}
{{- end -}}
{{- end -}}

{{- define "common.chart.appVersion" -}}
{{- if kindIs "map" .Chart -}}
{{- default .Chart.appVersion .Chart.AppVersion -}}
{{- else -}}
{{- .Chart.AppVersion -}}
{{- end -}}
{{- end -}}

{{- /*
common.chartref prints a chart name and version.

Expand All @@ -10,5 +42,5 @@ Example output:

*/ -}}
{{- define "common.chartref" -}}
{{- replace "+" "_" .Chart.Version | printf "%s-%s" .Chart.Name -}}
{{- replace "+" "_" (include "common.chart.version" . | toString) | printf "%s-%s" (include "common.chart.name" . | toString) -}}
{{- end -}}
51 changes: 46 additions & 5 deletions charts/common/templates/_container.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
{{- define "common.container.tpl" -}}
{{- $fullname := include "common.fullname" . -}}
{{- $config := default (dict) .Values.config -}}
{{- $lifecycle := default (dict) .Values.lifecycle -}}
{{- $lifecycle := default "" .Values.lifecycle -}}
{{- $healthCheck := default (dict) .Values.healthCheck -}}
{{- $configmap := default (dict) .Values.configmap -}}
{{- $configmapEnabled := true -}}
{{- if hasKey $configmap "enabled" -}}
{{- $configmapEnabled = $configmap.enabled -}}
{{- end -}}
name: app
image: "{{ default "ghcr.io/technicaldomain" .Values.image.registry }}/{{ .Values.image.name }}:{{ .Values.image.tag }}"
image: "{{ default "ghcr.io/technicaldomain" .Values.image.registry }}/{{ .Values.image.name }}:{{ .Values.image.tag | default (include "common.chart.appVersion" .) }}"
imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }}
{{- with .Values.command }}
command:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.args }}
args:
{{- toYaml . | nindent 2 }}
{{- end }}
ports:
- name: {{ default "http" $config.applicationName }}
- name: {{ default "http" $config.portName }}
containerPort: {{ default "8080" $config.port }}
protocol: TCP
{{- if $lifecycle }}
{{- if .Values.lifecycle }}
{{- if eq $lifecycle "spa" }}
lifecycle:
preStop:
Expand All @@ -21,12 +34,36 @@ lifecycle:
- quit
{{- end }}
{{- end }}
{{- if or $configmapEnabled .Values.sharedConfigs .Values.sharedSecrets .Values.envFrom .Values.secretData }}
envFrom:
{{- $configmapTemplate := (print $.Template.BasePath "/configmap.yaml") }}
{{- if .Values.envFrom }}
{{- toYaml .Values.envFrom | nindent 0 }}
{{- else }}
{{- if $configmapEnabled }}
- configMapRef:
name: {{ template "common.fullname" . }}
{{- end }}
{{- if .Values.secretData }}
- secretRef:
name: {{ template "common.fullname" . }}
{{- end }}
{{ include "common.envvar.shared.configs" . | indent 2 }}
{{ include "common.envvar.shared.secrets" . | indent 2 }}
{{- end }}
{{- end }}
{{- if or .Values.env .Values.secretRefs }}
env:
{{- if .Values.env }}
{{- toYaml .Values.env | nindent 2 }}
{{- end }}
{{- range $envName, $ref := .Values.secretRefs }}
- name: {{ $envName }}
valueFrom:
secretKeyRef:
name: {{ $ref.name }}
key: {{ $ref.key }}
{{- end }}
{{- end }}
{{- if eq $healthCheck.kind "tcp" }}
{{ include "common.healthcheck.liveness.tcp" . }}
{{ include "common.healthcheck.readiness.tcp" . }}
Expand All @@ -38,6 +75,10 @@ envFrom:
{{ include "common.healthcheck.startup" . }}
{{- end }}
{{ include "common.resources" . }}
{{- if .Values.volumeMounts }}
volumeMounts:
{{- toYaml .Values.volumeMounts | nindent 2 }}
{{- end }}
{{- end -}}
{{- define "common.container" -}}
{{- /* clear new line so indentation works correctly */ -}}
Expand Down
11 changes: 10 additions & 1 deletion charts/common/templates/_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ kind: Deployment
{{ template "common.metadata.deployment" . }}
spec:
{{- if not $hpaEnabled }}
{{- $replicas := default "1" .Values.replicas }}
{{- $replicas := default 1 .Values.replicas }}
replicas: {{ $replicas }}
{{- end }}
selector:
matchLabels: {{- include "common.labels.selector" . | nindent 6 }}
{{- if eq (default "RollingUpdate" .Values.deploymentStrategy) "Recreate" }}
strategy: {{- include "common.deployment.strategy.recreate" . | nindent 4 }}
{{- else }}
strategy: {{- include "common.deployment.strategy.rollingUpdate" . | nindent 4 }}
{{- end }}
template:
metadata:
labels: {{- include "common.labels.standard" . | nindent 8 }}
Expand All @@ -33,9 +37,14 @@ spec:
- name: {{ . }}
{{- end }}
{{- end }}
{{- include "common.dra.resourceClaims" . | nindent 6 }}
containers:
-
{{ include "common.container.tpl" . | indent 8 }}
{{- if .Values.volumes }}
volumes:
{{- toYaml .Values.volumes | nindent 8 }}
{{- end }}
{{- end -}}
{{- define "common.deployment" -}}
{{- template "common.util.merge" (append . "common.deployment.tpl") -}}
Expand Down
5 changes: 3 additions & 2 deletions charts/common/templates/_deployment_strategy.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{{- define "common.deployment.strategy.rollingUpdate" -}}
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
maxSurge: {{ default "25%" ((.Values.rollingUpdate).maxSurge) }}
maxUnavailable: {{ default 0 ((.Values.rollingUpdate).maxUnavailable) }}
{{- end -}}

{{- define "common.deployment.strategy.recreate" -}}
type: Recreate
{{- end -}}
55 changes: 55 additions & 0 deletions charts/common/templates/_dra.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{{/*
DRA (Dynamic Resource Allocation) helpers for GPU workloads.
Uses the GA API (resource.k8s.io/v1) which requires a separate
ResourceClaimTemplate object referenced by name.

Values structure:
gpu:
count: 1
deviceClassName: gpu.nvidia.com
*/}}

{{/*
ResourceClaimTemplate manifest.
Render as a standalone template file in the consuming chart.
*/}}
{{- define "common.dra.resourceClaimTemplate" -}}
{{- if .Values.gpu }}
apiVersion: resource.k8s.io/v1
kind: ResourceClaimTemplate
metadata:
name: {{ include "common.fullname" . }}-gpu
labels: {{- include "common.labels.standard" . | nindent 4 }}
spec:
spec:
devices:
requests:
- name: gpu
exactly:
deviceClassName: {{ default "gpu.nvidia.com" .Values.gpu.deviceClassName }}
count: {{ default 1 .Values.gpu.count }}
{{- end }}
{{- end -}}

{{/*
Pod-level resourceClaims block.
Include at the same level as containers/volumes in pod spec.
*/}}
{{- define "common.dra.resourceClaims" -}}
{{- if .Values.gpu }}
resourceClaims:
- name: gpu
resourceClaimTemplateName: {{ include "common.fullname" . }}-gpu
{{- end }}
{{- end -}}

{{/*
Container-level resource claims reference.
Include inside the container resources block.
*/}}
{{- define "common.dra.containerClaims" -}}
{{- if .Values.gpu }}
claims:
- name: gpu
{{- end }}
{{- end -}}
2 changes: 1 addition & 1 deletion charts/common/templates/_fullname.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Usage: 'name: "{{- template "common.fullname" . -}}"'
*/ -}}
{{- define "common.fullname"}}
{{- $global := default (dict) .Values.global -}}
{{- $base := default (printf "%s-%s" .Release.Name .Chart.Name) .Values.fullnameOverride -}}
{{- $base := default (printf "%s-%s" .Release.Name (include "common.chart.name" .)) .Values.fullnameOverride -}}
{{- $gpre := default "" $global.fullnamePrefix -}}
{{- $pre := default "" .Values.fullnamePrefix -}}
{{- $suf := default "" .Values.fullnameSuffix -}}
Expand Down
18 changes: 9 additions & 9 deletions charts/common/templates/_healthcheck.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ The kubelet uses liveness probes to know when to restart a container.
*/ -}}
{{- define "common.healthcheck.liveness" -}}
{{- $healthCheck := .Values.healthCheck -}}
{{- $liveness := $healthCheck.liveness -}}
{{- $liveness := default (dict) $healthCheck.liveness -}}
{{- $config := default (dict) .Values.config -}}
{{- $liveness_disabled := $liveness.disabled -}}
{{- if ne $liveness_disabled true -}}
livenessProbe:
httpGet:
path: {{ default "" $config.contextPath}}/{{ default "" $liveness.path }}
path: {{ default "" $config.contextPath | trimSuffix "/" }}/{{ default (default "" $healthCheck.path) $liveness.path | trimPrefix "/" }}
port: {{ default "8080" $config.port }}
initialDelaySeconds: {{ default "180" $liveness.initialDelaySeconds }}
timeoutSeconds: {{ default "2" $liveness.timeoutSeconds }}
Expand All @@ -20,7 +20,7 @@ livenessProbe:

{{- define "common.healthcheck.liveness.tcp" -}}
{{- $healthCheck := .Values.healthCheck -}}
{{- $liveness := $healthCheck.liveness -}}
{{- $liveness := default (dict) $healthCheck.liveness -}}
{{- $config := default (dict) .Values.config -}}
livenessProbe:
tcpSocket:
Expand All @@ -39,13 +39,13 @@ from Service load balancers.
*/ -}}
{{- define "common.healthcheck.readiness" -}}
{{- $healthCheck := .Values.healthCheck -}}
{{- $readiness := $healthCheck.readiness -}}
{{- $readiness := default (dict) $healthCheck.readiness -}}
{{- $config := default (dict) .Values.config -}}
{{- $readiness_disabled := $readiness.disabled -}}
{{- if ne $readiness_disabled true -}}
readinessProbe:
httpGet:
path: {{ default "" $config.contextPath}}/{{ default "" $readiness.path }}
path: {{ default "" $config.contextPath | trimSuffix "/" }}/{{ default (default "" $healthCheck.path) $readiness.path | trimPrefix "/" }}
port: {{ default "8080" $config.port }}
initialDelaySeconds: {{ default "40" $readiness.initialDelaySeconds }}
timeoutSeconds: {{ default "2" $readiness.timeoutSeconds }}
Expand All @@ -56,7 +56,7 @@ readinessProbe:

{{- define "common.healthcheck.readiness.tcp" -}}
{{- $healthCheck := .Values.healthCheck -}}
{{- $readiness := $healthCheck.readiness -}}
{{- $readiness := default (dict) $healthCheck.readiness -}}
{{- $config := default (dict) .Values.config -}}
readinessProbe:
tcpSocket:
Expand All @@ -75,21 +75,21 @@ it succeeds, making sure those probes don't interfere with the application start
*/ -}}
{{- define "common.healthcheck.startup" -}}
{{- $healthCheck := .Values.healthCheck -}}
{{- $startup := $healthCheck.startup -}}
{{- $startup := default (dict) $healthCheck.startup -}}
{{- $config := default (dict) .Values.config -}}
{{- $startup_disabled := $startup.disabled -}}
{{- if ne $startup_disabled true -}}
startupProbe:
httpGet:
path: {{ default "" $config.contextPath}}/{{ default "" $startup.path }}
path: {{ default "" $config.contextPath | trimSuffix "/" }}/{{ default (default "" $healthCheck.path) $startup.path | trimPrefix "/" }}
port: {{ default "8080" $config.port }}
failureThreshold: {{ default "30" $startup.failureThreshold }}
periodSeconds: {{ default "5" $startup.periodSeconds }}
{{- end -}}
{{- end -}}
{{- define "common.healthcheck.startup.tcp" -}}
{{- $healthCheck := .Values.healthCheck -}}
{{- $startup := $healthCheck.startup -}}
{{- $startup := default (dict) $healthCheck.startup -}}
{{- $config := default (dict) .Values.config -}}
startupProbe:
tcpSocket:
Expand Down
21 changes: 9 additions & 12 deletions charts/common/templates/_hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,32 @@ spec:
apiVersion: apps/v1
kind: Deployment
name: {{ template "common.fullname" . }}
minReplicas: {{ $hpa_config.minReplicas | default 1 $hpa_config.minReplicas }}
maxReplicas: {{ $hpa_config.maxReplicas | default 10 $hpa_config.maxReplicas }}
minReplicas: {{ $hpa_config.minReplicas | default 1 }}
maxReplicas: {{ $hpa_config.maxReplicas | default 10 }}
metrics:
{{- if $hpa_config.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ $hpa_config.targetCPUUtilizationPercentage }}
type: Utilization
averageUtilization: {{ $hpa_config.targetCPUUtilizationPercentage }}
{{- end }}
{{- if $hpa_config.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
name: memory
target:
type: Utilization
averageUtilization: {{ $hpa_config.targetMemoryUtilizationPercentage }}
{{- end }}
{{- if empty $hpa_config.targetCPUUtilizationPercentage }}
{{- if empty $hpa_config.targetMemoryUtilizationPercentage }}
metrics:
- resource:
{{- if and (not $hpa_config.targetCPUUtilizationPercentage) (not $hpa_config.targetMemoryUtilizationPercentage) }}
- type: Resource
resource:
name: cpu
target:
averageUtilization: 50
type: Utilization
type: Resource
{{- end }}
averageUtilization: 50
{{- end }}
{{- end -}}

Expand Down
Loading
Loading