From c4deda7eae4254d59fe01c3f82aa3076da5fbd82 Mon Sep 17 00:00:00 2001 From: Alexander Kharkevich Date: Thu, 25 Jun 2026 11:14:20 -0400 Subject: [PATCH] feat: update Chart.yaml version and enhance templates with initContainers, annotations, and service configurations --- charts/common/Chart.yaml | 2 +- charts/common/templates/_configmap.yaml | 36 ++++----- charts/common/templates/_deployment.yaml | 4 + .../templates/_persistentvolumeclaim.yaml | 55 ++++++++++++-- charts/common/templates/_service.yaml | 76 +++++++++++++++++-- 5 files changed, 141 insertions(+), 32 deletions(-) diff --git a/charts/common/Chart.yaml b/charts/common/Chart.yaml index 9e24013..b904f15 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.2.0 +version: 2.3.0 diff --git a/charts/common/templates/_configmap.yaml b/charts/common/templates/_configmap.yaml index 1603334..94ad593 100644 --- a/charts/common/templates/_configmap.yaml +++ b/charts/common/templates/_configmap.yaml @@ -1,26 +1,28 @@ +{{- /* +common.configmap - Generic ConfigMap template + +Usage with merge (recommended): + {{- include "common.configmap" (list . "myapp.configmap") -}} + {{- define "myapp.configmap" -}} + data: + MY_KEY: "value" + ANOTHER_KEY: "another" + {{- end -}} + +Usage without merge (empty data): + {{- include "common.configmap" . -}} +*/ -}} {{- define "common.configmap.tpl" -}} ---- apiVersion: v1 kind: ConfigMap {{ template "common.metadata" . }} data: {} {{- end -}} -{{- define "common.configmap" -}} -{{- template "common.util.merge" (append . "common.configmap.tpl") -}} -{{- end -}} -{{- define "common.configmap.spring.tpl" -}} -{{- $config := default (dict) .Values.config -}} -apiVersion: v1 -kind: ConfigMap -{{ template "common.metadata" . }} -data: - SPRING_APPLICATION_NAME: {{ template "common.fullname" . }} - SERVER_PORT: {{ default "8080" $config.port | quote}} - SPRING_PROFILES_ACTIVE: {{ default "prod" $config.springProfilesActive }} - SPRING_MAIN_ALLOW-BEAN-DEFINITION-OVERRIDING: {{ default "true" $config.springAllowBeanOverriding | quote}} - SERVER_SERVLET_CONTEXT-PATH: {{ default "/" $config.contextPath }} +{{- define "common.configmap" -}} +{{- if typeIs "[]interface {}" . -}} +{{- include "common.util.merge" (append . "common.configmap.tpl") -}} +{{- else -}} +{{- include "common.configmap.tpl" . -}} {{- end -}} -{{- define "common.configmap.spring" -}} -{{- template "common.util.merge" (append . "common.configmap.spring.tpl") -}} {{- end -}} diff --git a/charts/common/templates/_deployment.yaml b/charts/common/templates/_deployment.yaml index fd2b7d3..46c6ec5 100644 --- a/charts/common/templates/_deployment.yaml +++ b/charts/common/templates/_deployment.yaml @@ -38,6 +38,10 @@ spec: {{- end }} {{- end }} {{- include "common.dra.resourceClaims" . | nindent 6 }} + {{- with .Values.initContainers }} + initContainers: + {{- toYaml . | nindent 8 }} + {{- end }} containers: - {{ include "common.container.tpl" . | indent 8 }} diff --git a/charts/common/templates/_persistentvolumeclaim.yaml b/charts/common/templates/_persistentvolumeclaim.yaml index 6c1578c..8cc71d6 100644 --- a/charts/common/templates/_persistentvolumeclaim.yaml +++ b/charts/common/templates/_persistentvolumeclaim.yaml @@ -1,24 +1,63 @@ +{{- /* +common.persistentvolumeclaim - PersistentVolumeClaim template + +Values: + persistence: + enabled: true + existingClaim: "" # Use existing PVC instead of creating + accessMode: ReadWriteOnce + size: 10Gi + storageClass: "" # Empty = default, "-" = no class + annotations: {} + +Usage: + {{- include "common.persistentvolumeclaim" . -}} + +With overrides: + {{- include "common.persistentvolumeclaim" (list . "myapp.pvc") -}} + {{- define "myapp.pvc" -}} + spec: + accessModes: + - ReadWriteMany + {{- end -}} +*/ -}} {{- define "common.persistentvolumeclaim.tpl" -}} +{{- $p := default (dict) .Values.persistence -}} +{{- if and $p.enabled (not $p.existingClaim) }} apiVersion: v1 kind: PersistentVolumeClaim {{ template "common.metadata" . }} +{{- with $p.annotations }} + annotations: + {{- toYaml . | nindent 4 }} +{{- end }} spec: accessModes: - - {{ .Values.persistence.accessMode | quote }} + - {{ default "ReadWriteOnce" $p.accessMode }} resources: requests: - storage: {{ .Values.persistence.size | quote }} -{{- if .Values.persistence.storageClass }} -{{- if (eq "-" .Values.persistence.storageClass) }} + storage: {{ default "10Gi" $p.size }} +{{- with $p.storageClass }} +{{- if eq "-" . }} storageClassName: "" {{- else }} - storageClassName: "{{ .Values.persistence.storageClass }}" + storageClassName: {{ . }} +{{- end }} {{- end }} {{- end }} {{- end -}} + {{- define "common.persistentvolumeclaim" -}} -{{- $top := first . -}} -{{- if and $top.Values.persistence.enabled (not $top.Values.persistence.existingClaim) -}} -{{- template "common.util.merge" (append . "common.persistentvolumeclaim.tpl") -}} +{{- $top := . -}} +{{- if typeIs "[]interface {}" . -}} +{{- $top = first . -}} +{{- end -}} +{{- $p := default (dict) $top.Values.persistence -}} +{{- if and $p.enabled (not $p.existingClaim) -}} +{{- if typeIs "[]interface {}" . -}} +{{- include "common.util.merge" (append . "common.persistentvolumeclaim.tpl") -}} +{{- else -}} +{{- include "common.persistentvolumeclaim.tpl" . -}} +{{- end -}} {{- end -}} {{- end -}} diff --git a/charts/common/templates/_service.yaml b/charts/common/templates/_service.yaml index 3ceda44..a2920ec 100644 --- a/charts/common/templates/_service.yaml +++ b/charts/common/templates/_service.yaml @@ -1,19 +1,83 @@ +{{- /* +common.service.tpl - Base Service template + +Values structure: + service: + enabled: true # Optional, defaults to true + type: ClusterIP # ClusterIP, NodePort, LoadBalancer + port: 80 # Service port + targetPort: 8080 # Container port (defaults to config.port or 8080) + protocol: TCP # TCP, UDP + name: http # Port name + appProtocol: http # Application protocol hint + nodePort: 30080 # Only for NodePort type + clusterIP: None # For headless services + loadBalancerIP: "" # For LoadBalancer type + loadBalancerSourceRanges: [] + externalTrafficPolicy: "" # Local or Cluster + annotations: {} + labels: {} + additionalPorts: [] # Extra ports + +Usage: + {{- include "common.service" . -}} + +With overrides: + {{- include "common.service" (list . "myapp.service") -}} + {{- define "myapp.service" -}} + spec: + type: LoadBalancer + {{- end -}} +*/ -}} {{- define "common.service.tpl" -}} {{- $service := default (dict) .Values.service -}} {{- $config := default (dict) .Values.config -}} +{{- $enabled := true -}} +{{- if hasKey $service "enabled" -}} +{{- $enabled = $service.enabled -}} +{{- end -}} +{{- if $enabled }} apiVersion: v1 kind: Service {{ template "common.metadata" . }} spec: type: {{ default "ClusterIP" $service.type }} + {{- if $service.clusterIP }} + clusterIP: {{ $service.clusterIP }} + {{- end }} + {{- if $service.loadBalancerIP }} + loadBalancerIP: {{ $service.loadBalancerIP }} + {{- end }} + {{- if $service.loadBalancerSourceRanges }} + loadBalancerSourceRanges: + {{- toYaml $service.loadBalancerSourceRanges | nindent 4 }} + {{- end }} + {{- if $service.externalTrafficPolicy }} + externalTrafficPolicy: {{ $service.externalTrafficPolicy }} + {{- end }} + {{- if $service.sessionAffinity }} + sessionAffinity: {{ $service.sessionAffinity }} + {{- end }} ports: - - name: {{ default "http" $service.name }} - port: {{ default "80" $service.port }} - protocol: {{ default "TCP" $service.protocol }} - targetPort: {{ default "8080" $config.port }} - appProtocol: {{ default "http" $service.appProtocol }} + - name: {{ default "http" $service.name }} + port: {{ default "80" $service.port }} + protocol: {{ default "TCP" $service.protocol }} + targetPort: {{ default (default "8080" $config.port) $service.targetPort }} + appProtocol: {{ default "http" $service.appProtocol }} + {{- if and (eq (default "ClusterIP" $service.type) "NodePort") $service.nodePort }} + nodePort: {{ $service.nodePort }} + {{- end }} + {{- with $service.additionalPorts }} + {{- toYaml . | nindent 4 }} + {{- end }} selector: {{- include "common.labels.selector" . | indent 4 -}} +{{- end }} {{- end -}} + {{- define "common.service" -}} -{{- template "common.util.merge" (append . "common.service.tpl") -}} +{{- if typeIs "[]interface {}" . -}} +{{- include "common.util.merge" (append . "common.service.tpl") -}} +{{- else -}} +{{- include "common.service.tpl" . -}} +{{- end -}} {{- end -}}