From b65238e4f65f2ea2d6ab81a6f38737ae09578f55 Mon Sep 17 00:00:00 2001 From: Alexander Kharkevich Date: Sun, 29 Mar 2026 16:32:45 -0400 Subject: [PATCH] feat: update common lib --- charts/common/Chart.yaml | 2 +- charts/common/templates/_affinity.yaml | 2 +- charts/common/templates/_chartref.yaml | 34 +++++++++++- charts/common/templates/_container.yaml | 51 +++++++++++++++-- charts/common/templates/_deployment.yaml | 11 +++- .../templates/_deployment_strategy.yaml | 5 +- charts/common/templates/_dra.yaml | 55 +++++++++++++++++++ charts/common/templates/_fullname.yaml | 2 +- charts/common/templates/_healthcheck.yaml | 18 +++--- charts/common/templates/_hpa.yaml | 21 +++---- charts/common/templates/_httproute.yaml | 40 ++++++++++++++ charts/common/templates/_ingress.yaml | 41 ++++++++++++++ charts/common/templates/_metadata.yaml | 5 +- .../templates/_metadata_annotations.yaml | 14 ++++- charts/common/templates/_metadata_labels.yaml | 2 +- charts/common/templates/_name.yaml | 2 +- charts/common/templates/_resources.yaml | 1 + .../common/templates/_security_context.yaml | 13 +++-- charts/common/templates/_service.yaml | 4 +- charts/common/templates/_servicemonitor.yaml | 7 ++- charts/common/templates/_vmservicescrape.yaml | 22 ++++++++ 21 files changed, 302 insertions(+), 50 deletions(-) create mode 100644 charts/common/templates/_dra.yaml create mode 100644 charts/common/templates/_httproute.yaml create mode 100644 charts/common/templates/_ingress.yaml create mode 100644 charts/common/templates/_vmservicescrape.yaml diff --git a/charts/common/Chart.yaml b/charts/common/Chart.yaml index eabf520..9e24013 100644 --- a/charts/common/Chart.yaml +++ b/charts/common/Chart.yaml @@ -7,4 +7,4 @@ maintainers: - email: alex@kharkevich.org name: Alexander Kharkevich name: common -version: 2.1.5 +version: 2.2.0 diff --git a/charts/common/templates/_affinity.yaml b/charts/common/templates/_affinity.yaml index eceb499..b6febfd 100644 --- a/charts/common/templates/_affinity.yaml +++ b/charts/common/templates/_affinity.yaml @@ -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 }} diff --git a/charts/common/templates/_chartref.yaml b/charts/common/templates/_chartref.yaml index e6c1486..8e2647b 100644 --- a/charts/common/templates/_chartref.yaml +++ b/charts/common/templates/_chartref.yaml @@ -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. @@ -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 -}} diff --git a/charts/common/templates/_container.yaml b/charts/common/templates/_container.yaml index 3e53291..e8ee9af 100644 --- a/charts/common/templates/_container.yaml +++ b/charts/common/templates/_container.yaml @@ -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: @@ -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" . }} @@ -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 */ -}} diff --git a/charts/common/templates/_deployment.yaml b/charts/common/templates/_deployment.yaml index 53e4584..fd2b7d3 100644 --- a/charts/common/templates/_deployment.yaml +++ b/charts/common/templates/_deployment.yaml @@ -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 }} @@ -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") -}} diff --git a/charts/common/templates/_deployment_strategy.yaml b/charts/common/templates/_deployment_strategy.yaml index 8521803..f93697b 100644 --- a/charts/common/templates/_deployment_strategy.yaml +++ b/charts/common/templates/_deployment_strategy.yaml @@ -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 -}} diff --git a/charts/common/templates/_dra.yaml b/charts/common/templates/_dra.yaml new file mode 100644 index 0000000..afb5cae --- /dev/null +++ b/charts/common/templates/_dra.yaml @@ -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 -}} diff --git a/charts/common/templates/_fullname.yaml b/charts/common/templates/_fullname.yaml index 2da6cdf..ba3d464 100644 --- a/charts/common/templates/_fullname.yaml +++ b/charts/common/templates/_fullname.yaml @@ -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 -}} diff --git a/charts/common/templates/_healthcheck.yaml b/charts/common/templates/_healthcheck.yaml index 97250b6..c53ea5b 100644 --- a/charts/common/templates/_healthcheck.yaml +++ b/charts/common/templates/_healthcheck.yaml @@ -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 }} @@ -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: @@ -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 }} @@ -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: @@ -75,13 +75,13 @@ 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 }} @@ -89,7 +89,7 @@ startupProbe: {{- end -}} {{- define "common.healthcheck.startup.tcp" -}} {{- $healthCheck := .Values.healthCheck -}} -{{- $startup := $healthCheck.startup -}} +{{- $startup := default (dict) $healthCheck.startup -}} {{- $config := default (dict) .Values.config -}} startupProbe: tcpSocket: diff --git a/charts/common/templates/_hpa.yaml b/charts/common/templates/_hpa.yaml index 61977be..b62c863 100644 --- a/charts/common/templates/_hpa.yaml +++ b/charts/common/templates/_hpa.yaml @@ -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 -}} diff --git a/charts/common/templates/_httproute.yaml b/charts/common/templates/_httproute.yaml new file mode 100644 index 0000000..3635da4 --- /dev/null +++ b/charts/common/templates/_httproute.yaml @@ -0,0 +1,40 @@ +{{- define "common.httproute.tpl" -}} +{{- $gateway := default (dict) .Values.gateway -}} +--- +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +{{ template "common.metadata" . }} +spec: + {{- if $gateway.parentRefs }} + parentRefs: + {{- toYaml $gateway.parentRefs | nindent 4 }} + {{- end }} + {{- if $gateway.hostnames }} + hostnames: + {{- toYaml $gateway.hostnames | nindent 4 }} + {{- end }} + rules: + {{- if $gateway.rules }} + {{- toYaml $gateway.rules | nindent 4 }} + {{- else }} + - matches: + - path: + type: PathPrefix + value: / + backendRefs: + - name: {{ template "common.fullname" . }} + port: {{ (default (dict) .Values.service).port | default 80 }} + {{- end }} +{{- end -}} + +{{- define "common.httproute" -}} +{{- $top := first . -}} +{{- $gateway := default (dict) $top.Values.gateway -}} +{{- $gatewayEnabled := true -}} +{{- if hasKey $gateway "enabled" -}} + {{- $gatewayEnabled = $gateway.enabled -}} +{{- end -}} +{{- if $gatewayEnabled }} +{{- template "common.util.merge" (append . "common.httproute.tpl") -}} +{{- end }} +{{- end -}} diff --git a/charts/common/templates/_ingress.yaml b/charts/common/templates/_ingress.yaml new file mode 100644 index 0000000..779f704 --- /dev/null +++ b/charts/common/templates/_ingress.yaml @@ -0,0 +1,41 @@ +{{- define "common.ingress.tpl" -}} +{{- $ingress := default (dict) .Values.ingress -}} +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +{{ template "common.metadata" . }} +{{- with $ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} +{{- end }} +spec: + ingressClassName: {{ $ingress.className | default "traefik" }} + {{- if $ingress.tls }} + tls: + {{- toYaml $ingress.tls | nindent 4 }} + {{- end }} + rules: + {{- range $ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ .pathType | default "Prefix" }} + backend: + service: + name: {{ .serviceName | default (include "common.fullname" $) }} + port: + number: {{ .servicePort | default 80 }} + {{- end }} + {{- end }} +{{- end -}} + +{{- define "common.ingress" -}} +{{- $top := first . -}} +{{- $ingress := default (dict) $top.Values.ingress -}} +{{- $ingressEnabled := default false $ingress.enabled -}} +{{- if $ingressEnabled }} +{{- template "common.util.merge" (append . "common.ingress.tpl") -}} +{{- end }} +{{- end -}} diff --git a/charts/common/templates/_metadata.yaml b/charts/common/templates/_metadata.yaml index 167bfdf..f85a39b 100644 --- a/charts/common/templates/_metadata.yaml +++ b/charts/common/templates/_metadata.yaml @@ -10,8 +10,5 @@ metadata: {{- end -}} {{ define "common.metadata.deployment" -}} -metadata: - name: {{ template "common.fullname" . }} - labels: -{{ include "common.labels.standard" . | indent 4 -}} +{{- template "common.metadata" . }} {{- end -}} diff --git a/charts/common/templates/_metadata_annotations.yaml b/charts/common/templates/_metadata_annotations.yaml index 85bcfd1..c2f2fab 100644 --- a/charts/common/templates/_metadata_annotations.yaml +++ b/charts/common/templates/_metadata_annotations.yaml @@ -20,10 +20,20 @@ Any valid hook may be passed in. Separate multiple hooks with a ",". {{- define "common.annotations.deployment" -}} {{- $extended := default (dict) .Values.solution -}} {{- $lifecycle := default (dict) .Values.lifecycle -}} +{{- $configmap := default (dict) .Values.configmap -}} +{{- $configmapChecksumEnabled := false -}} +{{- if hasKey $configmap "checksumEnabled" -}} +{{- $configmapChecksumEnabled = $configmap.checksumEnabled -}} +{{- end -}} +{{- if $configmapChecksumEnabled }} {{- $configmapTemplate := (print $.Template.BasePath "/configmap.yaml") -}} -checksum/config: {{ include $configmapTemplate . | sha256sum | trunc 63}} +checksum/config: {{ include $configmapTemplate . | sha256sum | trunc 63 }} +{{- end }} +{{- range $name, $tpl := .Values.checksumAnnotations }} +checksum/{{ $name }}: {{ include $tpl $ | sha256sum | trunc 63 }} +{{- end }} {{- $prometheus := default (dict) .Values.prometheus -}} -{{- if $prometheus }} +{{- if .Values.prometheus }} prometheus.io/scrape: "true" prometheus.io/path: "{{ default "/actuator/prometheus" $prometheus.path }}" prometheus.io/port: "{{ default "8080" $prometheus.port }}" diff --git a/charts/common/templates/_metadata_labels.yaml b/charts/common/templates/_metadata_labels.yaml index 000540a..e57769f 100644 --- a/charts/common/templates/_metadata_labels.yaml +++ b/charts/common/templates/_metadata_labels.yaml @@ -26,7 +26,7 @@ app.kubernetes.io/name: {{ template "common.name" . }} helm.sh/chart: {{ template "common.chartref" . }} app.kubernetes.io/instance: {{ template "common.fullname" . }} app.kubernetes.io/managed-by: {{ .Release.Service }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote}} +app.kubernetes.io/version: {{ include "common.chart.appVersion" . | toString | quote }} {{- end -}} {{- define "common.labels.extended" -}} diff --git a/charts/common/templates/_name.yaml b/charts/common/templates/_name.yaml index 79b2af9..838810b 100644 --- a/charts/common/templates/_name.yaml +++ b/charts/common/templates/_name.yaml @@ -19,7 +19,7 @@ Usage: 'name: "{{- template "common.name" . -}}"' */ -}} {{- define "common.name"}} {{- $global := default (dict) .Values.global -}} - {{- $base := default .Chart.Name .Values.nameOverride -}} + {{- $base := default (include "common.chart.name" .) .Values.nameOverride -}} {{- $gpre := default "" $global.namePrefix -}} {{- $pre := default "" .Values.namePrefix -}} {{- $suf := default "" .Values.nameSuffix -}} diff --git a/charts/common/templates/_resources.yaml b/charts/common/templates/_resources.yaml index 592194a..4314354 100644 --- a/charts/common/templates/_resources.yaml +++ b/charts/common/templates/_resources.yaml @@ -1,6 +1,7 @@ {{- define "common.resources" -}} {{- $resources := .Values.resources -}} resources: + {{- include "common.dra.containerClaims" . | nindent 2 }} requests: memory: {{ default "640Mi" $resources.requests.memory }} cpu: {{ default "100m" $resources.requests.cpu }} diff --git a/charts/common/templates/_security_context.yaml b/charts/common/templates/_security_context.yaml index 766e79d..b978f2c 100644 --- a/charts/common/templates/_security_context.yaml +++ b/charts/common/templates/_security_context.yaml @@ -1,9 +1,12 @@ ---- {{- define "common.security.context" -}} {{- $context := default (dict) .Values.securityContext -}} +{{- $runAsUser := ternary $context.runAsUser 1001 (hasKey $context "runAsUser") -}} +{{- $runAsGroup := ternary $context.runAsGroup $runAsUser (hasKey $context "runAsGroup") -}} +{{- $fsGroup := ternary $context.fsGroup 1001 (hasKey $context "fsGroup") -}} +{{- $runAsNonRoot := ternary $context.runAsNonRoot true (hasKey $context "runAsNonRoot") -}} securityContext: - runAsUser: {{ $context.runAsUser | default "1001" }} - runAsGroup: {{ $context.runAsGroup | default ( $context.runAsUser | default "1001" ) }} - fsGroup: {{ $context.fsGroup | default "1001" }} - runAsNonRoot: {{ $context.runAsNonRoot | default "true" }} + runAsUser: {{ $runAsUser }} + runAsGroup: {{ $runAsGroup }} + fsGroup: {{ $fsGroup }} + runAsNonRoot: {{ $runAsNonRoot }} {{- end -}} diff --git a/charts/common/templates/_service.yaml b/charts/common/templates/_service.yaml index 144c1df..3ceda44 100644 --- a/charts/common/templates/_service.yaml +++ b/charts/common/templates/_service.yaml @@ -11,9 +11,7 @@ spec: port: {{ default "80" $service.port }} protocol: {{ default "TCP" $service.protocol }} targetPort: {{ default "8080" $config.port }} - # enable this for istio 1.6 - # https://istio.io/latest/docs/ops/configuration/traffic-management/protocol-selection/ - # appProtocol: {{ default "http" $service.protocol }} + appProtocol: {{ default "http" $service.appProtocol }} selector: {{- include "common.labels.selector" . | indent 4 -}} {{- end -}} {{- define "common.service" -}} diff --git a/charts/common/templates/_servicemonitor.yaml b/charts/common/templates/_servicemonitor.yaml index 999a33b..41c605f 100644 --- a/charts/common/templates/_servicemonitor.yaml +++ b/charts/common/templates/_servicemonitor.yaml @@ -1,5 +1,10 @@ {{- define "common.serviceMonitor.tpl" -}} {{- $monitoring := default (dict) .Values.monitoring -}} +{{- $monitoringEnabled := true -}} +{{- if hasKey $monitoring "enabled" -}} + {{- $monitoringEnabled = $monitoring.enabled -}} +{{- end -}} +{{- if $monitoringEnabled }} {{- $config := default (dict) .Values.config -}} {{- $config_port:= default "8080" $config.port -}} apiVersion: monitoring.coreos.com/v1 @@ -12,7 +17,7 @@ spec: - interval: {{ default "60s" $monitoring.interval | quote }} targetPort: {{ default $config_port $monitoring.port | quote }} path: {{ default "/metrics" $monitoring.path | quote }} - # TODO: add namespace selector if needed +{{- end -}} {{- end -}} {{- define "common.serviceMonitor" -}} {{- template "common.util.merge" (append . "common.serviceMonitor.tpl") -}} diff --git a/charts/common/templates/_vmservicescrape.yaml b/charts/common/templates/_vmservicescrape.yaml new file mode 100644 index 0000000..2b1e4cb --- /dev/null +++ b/charts/common/templates/_vmservicescrape.yaml @@ -0,0 +1,22 @@ +{{- define "common.vmServiceScrape.tpl" -}} +{{- $monitoring := default (dict) .Values.monitoring -}} +{{- $monitoringEnabled := true -}} +{{- if hasKey $monitoring "enabled" -}} + {{- $monitoringEnabled = $monitoring.enabled -}} +{{- end -}} +{{- if $monitoringEnabled }} +apiVersion: operator.victoriametrics.com/v1beta1 +kind: VMServiceScrape +{{ template "common.metadata" . }} +spec: + selector: + matchLabels: {{- include "common.labels.selector" . | nindent 6 }} + endpoints: + - interval: {{ default "60s" $monitoring.interval | quote }} + port: {{ default "http" $monitoring.port | quote }} + path: {{ default "/metrics" $monitoring.path | quote }} +{{- end -}} +{{- end -}} +{{- define "common.vmServiceScrape" -}} +{{- template "common.util.merge" (append . "common.vmServiceScrape.tpl") -}} +{{- end -}}