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.2.0
version: 2.3.0
36 changes: 19 additions & 17 deletions charts/common/templates/_configmap.yaml
Original file line number Diff line number Diff line change
@@ -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 -}}
4 changes: 4 additions & 0 deletions charts/common/templates/_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
55 changes: 47 additions & 8 deletions charts/common/templates/_persistentvolumeclaim.yaml
Original file line number Diff line number Diff line change
@@ -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 -}}
76 changes: 70 additions & 6 deletions charts/common/templates/_service.yaml
Original file line number Diff line number Diff line change
@@ -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 -}}
Loading