Skip to content

Commit

Permalink
Merge pull request #281 from bci-oss/feature/chart-improvement
Browse files Browse the repository at this point in the history
Helm improvement
  • Loading branch information
tunacicek authored Jan 30, 2024
2 parents 95ccab1 + 58ae395 commit f1f95b9
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 89 deletions.
2 changes: 1 addition & 1 deletion charts/registry/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sources:
- https://github.com/eclipse-tractusx/sldt-digital-twin-registry

type: application
version: 0.3.31
version: 0.3.32
appVersion: 0.3.23

dependencies:
Expand Down
108 changes: 57 additions & 51 deletions charts/registry/README.md

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions charts/registry/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "dtr.name" -}}
{{- default .Chart.Name .Values.nameOverride | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end }}

{{/*
Create a default fully qualified app name.
If release name contains chart name it will be used as a full name.
*/}}
{{- define "dtr.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "dtr.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "dtr.labels" -}}
helm.sh/chart: {{ include "dtr.chart" . }}
{{ include "dtr.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}


{{- define "dtr.selectorLabels" -}}
app.kubernetes.io/name: {{ include "dtr.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
apiVersion: v1
kind: Secret
metadata:
name: keycloak-database-credentials
name: {{ .Values.keycloak.externalDatabase.existingSecret }}
type: Opaque
data:
db-host: {{ printf "%s-postgresql" .Release.Name | b64enc }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: init-script-vol
name: {{ include "dtr.fullname" . }}-keycloak-configmap
data:
default-realm-import.json: |-
{{ .Files.Get "config/default-realm-import.json" | indent 4 }}
27 changes: 13 additions & 14 deletions charts/registry/templates/registry/registry-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,26 @@
# SPDX-License-Identifier: Apache-2.0
###############################################################

{{- $deployment_name := printf "cx-%s-registry" .Release.Name }}
{{- $sec_name := printf "%s-sec" $deployment_name }}
{{- $svc_name := printf "%s-svc" $deployment_name }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $deployment_name }}
name: {{ include "dtr.fullname" . }}
labels:
{{- include "dtr.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.registry.replicaCount }}
selector:
matchLabels:
app: {{ $deployment_name }}
{{- include "dtr.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
app: {{ $deployment_name }}
{{- include "dtr.selectorLabels" . | nindent 8 }}
spec:
securityContext:
runAsUser: 100
containers:
- name: {{ $deployment_name }}
- name: {{ .Chart.Name }}
image: {{ .Values.registry.image.registry }}/{{ .Values.registry.image.repository }}:{{ .Values.registry.image.version | default .Chart.AppVersion }}
imagePullPolicy: {{ .Values.registry.imagePullPolicy }}
securityContext:
Expand All @@ -58,19 +57,19 @@ spec:
httpGet:
path: /actuator/health/liveness
port: {{ .Values.registry.containerPort }}
initialDelaySeconds: 100
periodSeconds: 3
failureThreshold: 3
initialDelaySeconds: {{ .Values.registry.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.registry.livenessProbe.periodSeconds }}
failureThreshold: {{ .Values.registry.livenessProbe.failureThreshold }}
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: {{ .Values.registry.containerPort }}
initialDelaySeconds: 60
periodSeconds: 3
failureThreshold: 3
initialDelaySeconds: {{ .Values.registry.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.registry.readinessProbe.periodSeconds }}
failureThreshold: {{ .Values.registry.readinessProbe.failureThreshold }}
envFrom:
- secretRef:
name: {{ $sec_name }}
name: {{ include "dtr.fullname" . }}
resources:
{{ .Values.registry.resources | toYaml | indent 12 }}
imagePullSecrets:
Expand Down
9 changes: 3 additions & 6 deletions charts/registry/templates/registry/registry-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@
# SPDX-License-Identifier: Apache-2.0
###############################################################

{{- $deployment_name := printf "cx-%s-registry" .Release.Name }}
{{- $svc_name := printf "%s-svc" $deployment_name }}
{{- $ingr_name := printf "%s-ingr" $deployment_name }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $ingr_name }}
name: {{ include "dtr.fullname" . }}
annotations:
{{ .Values.registry.ingress.annotations | toYaml | indent 4 }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- include "dtr.labels" . | nindent 4 }}
spec:
ingressClassName: {{ .Values.registry.ingress.className }}
{{- if .Values.registry.ingress.tls }}
Expand All @@ -46,7 +43,7 @@ spec:
pathType: Prefix
backend:
service:
name: {{ $svc_name }}
name: {{ include "dtr.fullname" . }}
port:
number: {{ .Values.registry.service.port }}
{{- end}}
4 changes: 1 addition & 3 deletions charts/registry/templates/registry/registry-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
# SPDX-License-Identifier: Apache-2.0
###############################################################

{{- $deployment_name := printf "cx-%s-registry" .Release.Name }}
{{- $sec_name := printf "%s-sec" $deployment_name }}
apiVersion: v1
kind: Secret
metadata:
name: {{ $sec_name }}
name: {{ include "dtr.fullname" . }}
type: Opaque
data:
{{- if .Values.enablePostgres }}
Expand Down
8 changes: 3 additions & 5 deletions charts/registry/templates/registry/registry-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@
# SPDX-License-Identifier: Apache-2.0
###############################################################

{{- $deployment_name := printf "cx-%s-registry" .Release.Name }}
{{- $svc_name := printf "%s-svc" $deployment_name }}
apiVersion: v1
kind: Service
metadata:
name: {{ $svc_name }}
name: {{ include "dtr.fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- include "dtr.labels" . | nindent 4 }}
spec:
type: {{ .Values.registry.service.type }}
ports:
- port: {{ .Values.registry.service.port }}
targetPort: {{ .Values.registry.containerPort }}
selector:
app: {{ $deployment_name }}
{{- include "dtr.selectorLabels" . | nindent 4 }}
11 changes: 8 additions & 3 deletions charts/registry/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
#
# SPDX-License-Identifier: Apache-2.0
###############################################################

{{- $fullName := include "dtr.fullname" . }}
{{- $testconnection_name := printf "%s-test-script-pod" $fullName }}
{{- $testsec_name := printf "%s-test-credentials" $fullName }}
{{- $testconfig_name := printf "%s-test-script" $fullName }}
apiVersion: v1
kind: Pod
metadata:
name: "test-script-pod"
name: {{ $testconnection_name }}
annotations:
"helm.sh/hook": test
spec:
Expand All @@ -40,12 +45,12 @@ spec:
- name: AAS_REGISTRY_API_URL
valueFrom:
secretKeyRef:
name: test-credentials
name: {{ $testsec_name }}
key: aasRegistryUrl
volumes:
- name: test-script
configMap:
name: test-script
name: {{ $testconfig_name }}
defaultMode: 0777
- name: test-output
hostPath:
Expand Down
6 changes: 4 additions & 2 deletions charts/registry/templates/tests/test-credentials.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
#
# SPDX-License-Identifier: Apache-2.0
###############################################################
{{- $fullName := include "dtr.fullname" . }}
{{- $testsec_name := printf "%s-test-credentials" $fullName }}
apiVersion: v1
kind: Secret
metadata:
name: test-credentials
name: {{ $testsec_name }}
type: Opaque
data:
aasRegistryUrl: {{ printf "http://cx-%s-registry-svc:8080" .Release.Name | b64enc }}
aasRegistryUrl: {{ printf "http://%s:8080" $fullName | b64enc }}
3 changes: 2 additions & 1 deletion charts/registry/templates/tests/test-script-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
#
# SPDX-License-Identifier: Apache-2.0
###############################################################

kind: ConfigMap
apiVersion: v1
metadata:
name: test-script
name: {{ include "dtr.fullname" . }}-test-script
data:
test-script.sh: |
#!/bin/sh
Expand Down
11 changes: 10 additions & 1 deletion charts/registry/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# SPDX-License-Identifier: Apache-2.0
###############################################################


nameOverride:
fullnameOverride:
# enables the default postgres database
enablePostgres: true
# enables the default keycloak identity provider
Expand Down Expand Up @@ -51,6 +52,14 @@ registry:
service:
port: 8080
type: ClusterIP
livenessProbe:
failureThreshold: 3
periodSeconds: 3
initialDelaySeconds: 100
readinessProbe:
failureThreshold: 3
periodSeconds: 3
initialDelaySeconds: 100
dataSource:
driverClassName: org.postgresql.Driver
sqlInitPlatform: pg
Expand Down

0 comments on commit f1f95b9

Please sign in to comment.