Skip to content

Commit

Permalink
improve helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
tunacicek committed Mar 5, 2024
1 parent b926572 commit ced851c
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 42 deletions.
48 changes: 48 additions & 0 deletions charts/semantic-hub/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "hub.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 "hub.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 "hub.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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


{{- define "hub.selectorLabels" -}}
app.kubernetes.io/name: {{ include "hub.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
13 changes: 5 additions & 8 deletions charts/semantic-hub/templates/graphdb/graphdb-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,24 @@
###############################################################

{{- if and (.Values.graphdb.enabled) (not .Values.hub.embeddedTripleStore) }}
{{- $deployment_name := printf "cx-%s-graphdb" .Release.Name }}
{{- $sec_name := printf "%s-sec" $deployment_name }}
{{- $pvc_name := printf "%s-pvc" $deployment_name }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $deployment_name }}
name: {{ include "hub.fullname" .}}-graphdb
spec:
replicas: {{ .Values.graphdb.replicaCount }}
selector:
matchLabels:
app: {{ $deployment_name }}
{{- include "hub.labels" . | nindent 6 }}-graphdb
template:
metadata:
labels:
app: {{ $deployment_name }}
{{- include "hub.labels" . | nindent 8 }}-graphdb
spec:
securityContext:
runAsUser: 1000
containers:
- name: {{ $deployment_name }}
- name: {{ include "hub.fullname" .}}-graphdb
image: {{ .Values.graphdb.image }}
imagePullPolicy: {{ .Values.graphdb.imagePullPolicy }}
securityContext:
Expand All @@ -64,5 +61,5 @@ spec:
volumes:
- name: graphdbdata
persistentVolumeClaim:
claimName: {{ $pvc_name }}
claimName: {{ include "hub.fullname" .}}-graphdb
{{- end -}}
4 changes: 1 addition & 3 deletions charts/semantic-hub/templates/graphdb/graphdb-pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
###############################################################

{{- if and (.Values.graphdb.enabled) (not .Values.hub.embeddedTripleStore) }}
{{- $deployment_name := printf "cx-%s-graphdb" .Release.Name }}
{{- $pvc_name := printf "%s-pvc" $deployment_name }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ $pvc_name }}
name: {{ include "hub.fullname" .}}-graphdb
spec:
storageClassName: {{ .Values.graphdb.storageClassName }}
accessModes:
Expand Down
6 changes: 2 additions & 4 deletions charts/semantic-hub/templates/graphdb/graphdb-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@
###############################################################

{{- if and (.Values.graphdb.enabled) (not .Values.hub.embeddedTripleStore) }}
{{- $deployment_name := printf "cx-%s-graphdb" .Release.Name }}
{{- $service_name := printf "cx-%s-graphdb-svc" .Release.Name }}
apiVersion: v1
kind: Service
metadata:
name: {{ $service_name }}
name: {{ include "hub.fullname" .}}-graphdb
spec:
type: ClusterIP
ports:
- port: {{ .Values.graphdb.service.port }}
targetPort: {{ .Values.graphdb.containerPort }}
selector:
app: {{ $deployment_name }}
app: {{ include "hub.fullname" .}}-graphdb
{{- end -}}
16 changes: 8 additions & 8 deletions charts/semantic-hub/templates/hub/hub-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $deployment_name }}
name: {{ include "hub.fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- include "hub.labels" . | nindent 4 }}
spec:
replicas: {{ default 1 .Values.hub.replicaCount | int }}
selector:
matchLabels:
app: {{ $deployment_name }}
replicas: {{ default 1 .Values.hub.replicaCount | int }}
{{- include "hub.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
app: {{ $deployment_name }}
{{- include "hub.selectorLabels" . | nindent 8 }}
spec:
securityContext:
runAsUser: 100
containers:
- name: {{ $deployment_name }}
- name: {{ .Chart.Name }}
image: {{ .Values.hub.image.registry }}/{{ .Values.hub.image.repository }}:{{ .Values.hub.image.version | default .Chart.AppVersion }}
imagePullPolicy: {{ .Values.hub.imagePullPolicy }}
securityContext:
Expand All @@ -57,7 +57,7 @@ spec:
value: "{{ .Values.hub.embeddedTripleStore }}"
- name: HUB_TRIPLE_STORE_BASE_URL
{{- if .Values.graphdb.enabled }}
value: {{ printf "http://%s:%v" $graphdb_svc_name .Values.graphdb.service.port }}/ds
value: {{ printf "http://hub-semantic-hub-graphdb:%v" .Values.graphdb.service.port }}/ds
{{- else }}
value: {{ .Values.hub.graphdbBaseUrl }}
{{- end }}
Expand All @@ -67,7 +67,7 @@ spec:
value: {{ .Values.graphdb.updateEndpoint }}
envFrom:
- secretRef:
name: {{ $sec_name }}
name: {{ include "hub.fullname" . }}
livenessProbe:
httpGet:
path: /actuator/health/liveness
Expand Down
9 changes: 3 additions & 6 deletions charts/semantic-hub/templates/hub/hub-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@
###############################################################

{{- if .Values.hub.ingress.enabled }}
{{- $deployment_name := printf "cx-%s-hub" .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 "hub.fullname" . }}
annotations:
{{ .Values.hub.ingress.annotations | toYaml | indent 4 }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- include "hub.labels" . | nindent 4 }}
spec:
ingressClassName: {{ .Values.hub.ingress.className }}
{{- if .Values.hub.ingress.tls }}
Expand All @@ -46,7 +43,7 @@ spec:
pathType: Prefix
backend:
service:
name: {{ $svc_name }}
name: {{ include "hub.fullname" . }}
port:
number: {{ .Values.hub.service.port }}
{{- end}}
8 changes: 3 additions & 5 deletions charts/semantic-hub/templates/hub/hub-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
# SPDX-License-Identifier: Apache-2.0
###############################################################

{{- $deployment_name := printf "cx-%s-hub" .Release.Name }}
{{- $sec_name := printf "%s-sec" $deployment_name }}
apiVersion: v1
kind: Secret
metadata:
name: {{ $sec_name }}
name: {{ include "hub.fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- include "hub.labels" . | nindent 4 }}
type: Opaque
data:
{{- if .Values.hub.idpIssuerUri }}
Expand All @@ -40,7 +38,7 @@ data:
{{ if .Values.graphdb.password -}}
HUB_TRIPLE_STORE_PASSWORD: {{ ( .Values.graphdb.password | b64enc) }}
{{ else }}
{{- $secret := (lookup "v1" "Secret" .Release.Namespace $sec_name) }}
{{- $secret := (lookup "v1" "Secret" .Release.Namespace (include "hub.fullname" .)) }}
{{ if $secret -}}
HUB_TRIPLE_STORE_PASSWORD: {{ index $secret.data "HUB_TRIPLE_STORE_PASSWORD" | quote }}
{{- else -}}
Expand Down
8 changes: 3 additions & 5 deletions charts/semantic-hub/templates/hub/hub-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-hub" .Release.Name }}
{{- $svc_name := printf "%s-svc" $deployment_name }}
apiVersion: v1
kind: Service
metadata:
name: {{ $svc_name }}
name: {{ include "hub.fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- include "hub.labels" . | nindent 4 }}
spec:
type: {{ .Values.hub.service.type }}
ports:
- port: {{ .Values.hub.service.port }}
targetPort: {{ .Values.hub.containerPort }}
selector:
app: {{ $deployment_name }}
{{- include "hub.selectorLabels" . | nindent 4 }}
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 "hub.fullname" . }}-keycloak-init-script-configmap
data:
default-realm-import.json: |-
{{ .Files.Get "config/default-realm-import.json" | indent 4 }}
3 changes: 1 addition & 2 deletions charts/semantic-hub/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ hub:

graphdb:
## Include Fuski deployment or deploy separately
enabled: false
enabled: true
image: jena-fuseki-docker:4.7.0
imagePullPolicy: IfNotPresent
replicaCount: 1
Expand All @@ -80,7 +80,6 @@ graphdb:
password:
javaOptions: "-Xmx1048m -Xms1048m"
args: ["--tdb2", "--update", "--loc", "databases/", "/ds"]
storageClassName: default
storageSize: 50Gi
pvcAccessModes:
- ReadWriteOnce
Expand Down

0 comments on commit ced851c

Please sign in to comment.