Skip to content

Commit

Permalink
many mods
Browse files Browse the repository at this point in the history
  • Loading branch information
hamelchRIT authored and hylkevds committed Aug 12, 2024
1 parent ba0b913 commit 42848df
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 85 deletions.
6 changes: 3 additions & 3 deletions helm/frost-server/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ Hereafter the list of available exposed FROST-Server's resources:
FROST-Server's resource | Access URL
--------------------------- | ----------------------------------------------
HTTP - Homepage | {{ include "frost-server.http.serviceRootUrl" . }}
HTTP - SensorThings API | {{ include "frost-server.http.serviceRootUrl" . }}/{{ include "frost-server.http.apiVersion" . }}
HTTP - SensorThings API | {{ include "frost-server.http.serviceRootUrl" . }}{{ include "frost-server.http.apiVersion" . }}
{{- if .Values.frost.mqtt.enabled }}
MQTT - TCP | {{ .Values.frost.http.serviceHost }}:{{ .Values.frost.mqtt.ports.mqtt.nodePort }}
MQTT - Websocket | {{ .Values.frost.http.serviceHost }}:{{ .Values.frost.mqtt.ports.websocket.nodePort }}
MQTT - TCP | {{ include "frost-server.mqtt.serviceEndpoint" . }}
MQTT - Websocket | {{ include "frost-server.mqtt.serviceRootUrl" . }}
{{- end }}

For more information about FROST-Server, please visit https://github.com/FraunhoferIOSB/FROST-Server
166 changes: 160 additions & 6 deletions helm/frost-server/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,174 @@ Get the HTTP service API version.
v1.0
{{- end -}}

{{/*
Get the HTTP serviceHost.
*/}}
{{- define "frost-server.http.serviceHost" -}}
{{ if not .Values.frost.http.serviceHost | empty }}{{ .Values.frost.http.serviceHost }}{{else}}"frost-server"{{end}}
{{- end -}}

{{/*
Get the HTTP service root URL.
*/}}
{{- define "frost-server.http.serviceRootUrl" -}}
{{ .Values.frost.http.serviceProtocol }}://{{ .Values.frost.http.serviceHost }}{{ if .Values.frost.http.servicePort }}:{{ .Values.frost.http.servicePort }}{{ else if not .Values.frost.http.ingress.enabled }}:{{ .Values.frost.http.ports.http.nodePort }}{{ end }}{{ if .Values.frost.http.urlSubPath }}/{{ .Values.frost.http.urlSubPath }}{{ end }}
{{ .Values.frost.http.serviceProtocol }}://{{ .Values.frost.http.serviceHost }}{{ if .Values.frost.http.servicePort }}:{{ .Values.frost.http.servicePort }}{{ else if not .Values.frost.http.ingress.enabled }}:{{ .Values.frost.http.ports.http.nodePort }}{{ end }}{{ template "frost-server.http.serviceSubPath" . }}
{{- end -}}

{{/*
Get the HTTP service SubPath
*/}}
{{- define "frost-server.http.serviceSubPath" -}}
{{- if not .Values.frost.http.urlSubPath | empty -}}
{{- printf "/%s/" .Values.frost.http.urlSubPath | replace "//" "/" -}}
{{- else -}}
{{- printf "/" -}}
{{- end -}}
{{- end -}}

{{/*
Get the MQTT serviceHost.
*/}}
{{- define "frost-server.mqtt.serviceHost" -}}
{{ if not .Values.frost.mqtt.serviceHost | empty }}{{ .Values.frost.mqtt.serviceHost }}{{else}}{{ .Values.frost.http.serviceHost }}{{end}}
{{- end -}}

{{/*
Get the MQTT service root URL.
*/}}
{{- define "frost-server.mqtt.serviceRootUrl" -}}
{{ .Values.frost.mqtt.serviceProtocol }}://{{ template "frost-server.mqtt.serviceHost" . }}{{ if .Values.frost.mqtt.servicePort }}:{{ .Values.frost.mqtt.servicePort }}{{ else if not .Values.frost.mqtt.ingress.enabled }}:{{ .Values.frost.mqtt.ports.mqtt.nodePort }}{{ end }}{{ if .Values.frost.mqtt.ingress.enabled }}{{ template "frost-server.mqtt.websockPath" . }}{{ end }}
{{- end -}}

{{/*
{{- end -}}

{{/*
Get the MQTT Websock-Path.
*/}}
{{- define "frost-server.mqtt.websockPath" -}}
{{- if not .Values.frost.mqtt.urlSubPath | empty -}}
{{- printf "/%s/" .Values.frost.mqtt.urlSubPath | replace "//" "/" -}}
{{- else -}}
{{- printf "/mqtt/" -}}
{{- end -}}
{{- end -}}

{{/*
Get the MQTT TCP service EndPoint
*/}}
{{- define "frost-server.mqtt.serviceEndpoint" -}}
{{- if and .Values.frost.http.serviceHost .Values.frost.mqtt.ports.mqtt.nodePort -}}
{{- printf "%s:%s" .Values.frost.http.serviceHost .Values.frost.mqtt.ports.mqtt.nodePort -}}
{{- else -}}
{{- printf "NOT CONFIGURED -- please set frost.mqtt.ports.mqtt.nodePort in values.yaml" -}}
{{- end -}}
{{- end -}}

{{/*
Get the default HTTP nginx rewriteAnnotations.
*/}}
{{- define "frost-server.http.ingressProvider.nginx.rewriteAnnotation" -}}
{{- $mydict := dict -}}
{{- if .Values.frost.http.ingress.tls.enabled -}}
{{- $_ := set $mydict "nginx.ingress.kubernetes.io/ssl-redirect" "true" -}}
{{- end -}}
{{- $_ := set $mydict "nginx.ingress.kubernetes.io/rewrite-target" "/FROST-Server/$1" -}}
{{- $mydict | toYaml -}}
{{- end -}}

{{/*
Get the default HTTP agic rewriteAnnotations.
*/}}
{{- define "frost-server.http.ingressProvider.agic.rewriteAnnotation" -}}
{{- $mydict := dict -}}
{{- if .Values.frost.http.ingress.tls.enabled -}}
{{- $_ := set $mydict "appgw.ingress.kubernetes.io/ssl-redirect" "true" -}}
{{- end -}}
{{- $_ := set $mydict "appgw.ingress.kubernetes.io/backend-path-prefix" "/FROST-Server/" -}}
{{- $mydict | toYaml -}}
{{- end -}}

{{/*
Get the default HTTP traefik rewriteAnnotations.
*/}}
{{- define "frost-server.http.ingressProvider.traefik.rewriteAnnotation" -}}
{{- $mydict := dict -}}
{{- if .Values.frost.http.ingress.tls.enabled -}}
{{- $_ := set $mydict "traefik.ingress.kubernetes.io/router.tls" "true" -}}
{{- end -}}
{{/*
rewrite path annotation to implement: /FROST-Server/
*/}}
{{- $mydict | toYaml -}}
{{- end -}}

{{/*
Get the default agic rewriteAnnotations for HTTP.
*/}}
{{- define "frost-server.http.ingress.rewriteAnnotation" -}}
{{- if eq .Values.frost.http.ingress.ingressProvider "agic" -}}
{{ template "frost-server.http.ingressProvider.agic.rewriteAnnotation" . }}
{{- else -}} # default to nginx
{{ template "frost-server.http.ingressProvider.nginx.rewriteAnnotation" . }}
{{- end -}}
{{- end -}}


{{/*
Get the default MQTT nginx rewriteAnnotations.
*/}}
{{- define "frost-server.mqtt.ingressProvider.nginx.rewriteAnnotation" -}}
{{- $mydict := dict -}}
{{- if .Values.frost.mqtt.ingress.tls.enabled -}}
{{- $_ := set $mydict "nginx.ingress.kubernetes.io/ssl-redirect" "true" -}}
{{- end -}}
{{- $mydict | toYaml -}}
{{- end -}}

{{/*
Get the default MQTT agic rewriteAnnotations.
*/}}
{{- define "frost-server.mqtt.ingressProvider.agic.rewriteAnnotation" -}}
{{- $mydict := dict -}}
{{- if .Values.frost.mqtt.ingress.tls.enabled -}}
{{- $_ := set $mydict "appgw.ingress.kubernetes.io/ssl-redirect" "true" -}}
{{- end -}}
{{- $mydict | toYaml -}}
{{- end -}}

{{/*
Get the default MQTT traefik rewriteAnnotations.
*/}}
{{- define "frost-server.mqtt.ingressProvider.traefik.rewriteAnnotation" -}}
{{- $mydict := dict -}}
{{- if .Values.frost.mqtt.ingress.tls.enabled -}}
{{- $_ := set $mydict "traefik.ingress.kubernetes.io/router.tls" "true" -}}
{{- end -}}
{{- $mydict | toYaml -}}
{{- end -}}


{{/*
Get the default agic rewriteAnnotations for MQTT.
*/}}
{{- define "frost-server.mqtt.ingress.rewriteAnnotation" -}}
{{- if eq .Values.frost.mqtt.ingress.ingressProvider "agic" -}}
{{ template "frost-server.mqtt.ingressProvider.agic.rewriteAnnotation" . }}
{{- else -}} # default to nginx
{{ template "frost-server.mqtt.ingressProvider.nginx.rewriteAnnotation" . }}
{{- end -}}
{{- end -}}

{{/*
Get the DB secret.
*/}}
{{- define "frost-server.db.secret" -}}
{{- if .Values.frost.db.existingSecret -}}
{{ .Values.frost.db.existingSecret }}
{{- else -}}
{{ include "frost-server.fullName" . }}
{{- end -}}
{{- if .Values.frost.db.existingSecret -}}
{{- .Values.frost.db.existingSecret -}}
{{- else -}}
{{ include "frost-server.fullName" . }}
{{- end -}}
{{- end -}}


38 changes: 38 additions & 0 deletions helm/frost-server/templates/_tplvalues.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{/*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{/* vim: set filetype=mustache: */}}
{{/*
Renders a value that contains template perhaps with scope if the scope is present.
Usage:
{{ include "common.tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $ ) }}
{{ include "common.tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $ "scope" $app ) }}
*/}}
{{- define "common.tplvalues.render" -}}
{{- $value := typeIs "string" .value | ternary .value (.value | toYaml) }}
{{- if contains "{{" (toJson .value) }}
{{- if .scope }}
{{- tpl (cat "{{- with $.RelativeScope -}}" $value "{{- end }}") (merge (dict "RelativeScope" .scope) .context) }}
{{- else }}
{{- tpl $value .context }}
{{- end }}
{{- else }}
{{- $value }}
{{- end }}
{{- end -}}

{{/*
Merge a list of values that contains template after rendering them.
Merge precedence is consistent with http://masterminds.github.io/sprig/dicts.html#merge-mustmerge
Usage:
{{ include "common.tplvalues.merge" ( dict "values" (list .Values.path.to.the.Value1 .Values.path.to.the.Value2) "context" $ ) }}
*/}}
{{- define "common.tplvalues.merge" -}}
{{- $dst := dict -}}
{{- range .values -}}
{{- $dst = include "common.tplvalues.render" (dict "value" . "context" $.context "scope" $.scope) | fromYaml | merge $dst -}}
{{- end -}}
{{ $dst | toYaml }}
{{- end -}}
12 changes: 10 additions & 2 deletions helm/frost-server/templates/db-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ spec:
command:
- /bin/sh
- -c
- exec pg_isready -U {{ default "postgres" $customUser | quote }} -h 127.0.0.1 -p 5432
- exec pg_isready -h 127.0.0.1 -p 5432
# command:
# - /bin/sh
# - -c
# - exec pg_isready -U {{ default "postgres" "placeholder" | quote }} -h 127.0.0.1 -p 5432
initialDelaySeconds: 120
periodSeconds: 10
timeoutSeconds: 5
Expand All @@ -71,7 +75,11 @@ spec:
command:
- /bin/sh
- -c
- exec pg_isready -U {{ default "postgres" $customUser | quote }} -h 127.0.0.1 -p 5432
- exec pg_isready -h 127.0.0.1 -p 5432
# command:
# - /bin/sh
# - -c
# - exec pg_isready -U {{ default "postgres" "placeholder" | quote }} -h 127.0.0.1 -p 5432
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
Expand Down
47 changes: 20 additions & 27 deletions helm/frost-server/templates/http-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
{{- if .Values.frost.http.ingress.enabled -}}
{{- $tier := "http" -}}
{{- $fullName := include "frost-server.fullName" (merge (dict "tier" $tier) .) -}}
# {{- if and .Values.frost.http.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
# {{- if not (hasKey .Values.frost.http.ingress.annotations "kubernetes.io/ingress.class") }}
# {{- $_ := set .Values.frost.http.ingress.annotations "kubernetes.io/ingress.class" .Values.frost.http.ingress.className}}
# {{- end }}
# {{- end }}
# {{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
{{- $defaultRewriteAnnotations := include "frost-server.http.ingress.rewriteAnnotation" . -}}
{{- if and .Values.frost.http.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.frost.http.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.frost.http.ingress.annotations "kubernetes.io/ingress.class" .Values.frost.http.ingress.className}}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
# {{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
# apiVersion: networking.k8s.io/v1beta1
# {{- else -}}
# apiVersion: extensions/v1beta1
# {{- end }}
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
namespace: {{ .Release.Namespace }}
{{- if .Values.frost.http.ingress.annotations or and .Values.frost.http.ingress.rewriteAnnotation .Values.frost.http.ingress.rewriteTarget }}
annotations:
{{- if and .Values.frost.http.ingress.rewriteAnnotation .Values.frost.http.ingress.rewriteTarget }}
{{ .Values.frost.http.ingress.rewriteAnnotation}}: {{ .Values.frost.http.ingress.rewriteTarget}}
{{- end }}
{{- if .Values.frost.http.ingress.annotations }}
{{- with .Values.ingress.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.frost.http.ingress.annotations $defaultRewriteAnnotations ) "context" . ) }}
annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
labels:
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
Expand All @@ -35,25 +28,25 @@ metadata:
component: {{ $tier }}
spec:
{{- if and .Values.frost.http.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.frost.http.ingress.className }}
ingressClassName: {{ .Values.frost.http.ingress.className | default "nginx" }}
{{- end }}
{{- if .Values.frost.http.ingress.tls.enabled }}
tls:
- hosts:
- {{ .Values.frost.http.serviceHost }}
- hosts:
- {{ include "frost-server.http.serviceHost" . }}
{{- if .Values.frost.http.ingress.tls.secretName }}
secretName: {{ .Values.frost.http.ingress.tls.secretName }}
{{- end -}}
{{- end }}
rules:
- host: {{ .Values.frost.http.serviceHost }}
- host: {{ include "frost-server.http.serviceHost" . }}
http:
paths:
- path: {{ .Values.frost.http.ingress.path }}
- path: {{ template "frost-server.http.serviceSubPath" . }}
pathType: Prefix
backend:
service:
name: {{ $fullName }}
port:
number: 80
number: {{ .Values.frost.http.ports.http.servicePort }}
{{- end -}}
2 changes: 1 addition & 1 deletion helm/frost-server/templates/mqtt-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ spec:
env:
# Internal properties
- name: serviceRootUrl
value: {{ include "frost-server.http.serviceRootUrl" . | quote }}
value: {{ include "frost-server.mqtt.serviceRootUrl" . | quote }}
- name: alwaysOrderbyId
value: "{{ .Values.frost.alwaysOrderbyId }}"
- name: logSensitiveData
Expand Down
19 changes: 10 additions & 9 deletions helm/frost-server/templates/mqtt-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{- if .Values.frost.mqtt.ingress.enabled -}}
{{- $tier := "mqtt" -}}
{{- $fullName := include "frost-server.fullName" (merge (dict "tier" $tier) .) -}}
{{- $defaultRewriteAnnotations := include "frost-server.mqtt.ingress.rewriteAnnotation" . -}}
{{- if and .Values.frost.mqtt.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.frost.mqtt.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.frost.mqtt.ingress.annotations "kubernetes.io/ingress.class" .Values.frost.mqtt.ingress.className}}
Expand All @@ -16,11 +17,11 @@ apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
annotations:
nginx.org/websocket-services: '"{{ $fullName }}"'
{{- if .Values.frost.mqtt.ingress.annotations }}
{{- toYaml .Values.frost.mqtt.ingress.annotations | nindent 4 }}
{{ end }}
{{- if not (hasKey .Values.frost.mqtt.ingress.annotations "nginx.org/websocket-services") -}}
{{- $_ := set .Values.frost.mqtt.ingress.annotations "nginx.org/websocket-services" $fullName -}}
{{- end -}}
{{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.frost.mqtt.ingress.annotations $defaultRewriteAnnotations ) "context" . ) }}
annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
labels:
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
Expand All @@ -29,19 +30,19 @@ metadata:
component: {{ $tier }}
spec:
{{- if and .Values.frost.mqtt.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.frost.mqtt.ingress.className }}
ingressClassName: {{ .Values.frost.mqtt.ingress.className | default "nginx" }}
{{- end }}
{{- if .Values.frost.mqtt.ingress.tls.enabled }}
tls:
- hosts:
- {{ .Values.frost.mqtt.serviceHost }}
- {{ include "frost-server.mqtt.serviceHost" . }}
secretName: {{ .Values.frost.mqtt.ingress.tls.secretName }}
{{- end }}
rules:
- host: {{tpl .Values.frost.mqtt.serviceHost . }}
- host: {{ include "frost-server.mqtt.serviceHost" . }}
http:
paths:
- path: {{ .Values.frost.mqtt.ingress.path }}
- path: {{ template "frost-server.mqtt.websockPath" . }}
pathType: ImplementationSpecific
backend:
service:
Expand Down
Loading

0 comments on commit 42848df

Please sign in to comment.