diff --git a/charts/ska-tango-base/templates/itango.yaml b/charts/ska-tango-base/templates/itango.yaml index 2a56b4fe70670374bd1a95c850a4d86e5e20dd8f..579b39a27915e6df9bd5273037b4b31729c722a3 100644 --- a/charts/ska-tango-base/templates/itango.yaml +++ b/charts/ska-tango-base/templates/itango.yaml @@ -1,9 +1,9 @@ -{{ if .Values.itango.enabled }} -{{ $default_tango_host := printf "%s-%s" "databaseds-tango-base-" .Release.Name }} -{{ $tango_host := tpl (coalesce .Values.global.tango_host .Values.tango_host $default_tango_host | toString) . }} -{{ $dsconfig := coalesce .Values.global.dsconfig .Values.dsconfig}} -{{ $tries := coalesce .Values.global.tries 10}} -{{ $sleep := coalesce .Values.global.sleep 5}} +{{- if .Values.itango.enabled }} +{{- $default_tango_host := printf "%s-%s" "databaseds-tango-base-" .Release.Name }} +{{- $tango_host := tpl (coalesce .Values.global.tango_host .Values.tango_host $default_tango_host | toString) . }} +{{- $dsconfig := coalesce .Values.global.dsconfig .Values.dsconfig}} +{{- $tries := coalesce .Values.global.tries 10}} +{{- $sleep := coalesce .Values.global.sleep 5}} --- apiVersion: v1 kind: Pod @@ -16,10 +16,10 @@ metadata: function: {{ .Values.itango.function }} domain: {{ .Values.itango.domain }} intent: {{ .Values.itango.intent }} -{{ if or (.Values.global.annotations) (.Values.annotations) }} +{{- if or (.Values.global.annotations) (.Values.annotations) }} annotations: {{ toYaml (coalesce .Values.global.annotations .Values.annotations) | indent 4 }} -{{ end }} +{{- end }} spec: initContainers: - name: check-dependencies-0 @@ -68,4 +68,4 @@ spec: {{ toYaml . | indent 4 }} {{- end }} -{{ end }} +{{- end }} \ No newline at end of file diff --git a/charts/ska-tango-base/templates/tangodb-pv.yaml b/charts/ska-tango-base/templates/tangodb-pv.yaml index 89f0ef891025dce6bc6c330c331cf8279d50cbeb..a6f0c404154978b9259fd202eaf38a6142d819b2 100644 --- a/charts/ska-tango-base/templates/tangodb-pv.yaml +++ b/charts/ska-tango-base/templates/tangodb-pv.yaml @@ -1,3 +1,4 @@ +{{- if not .Values.global.operator }} {{ if .Values.tangodb.enabled }} {{ if .Values.tangodb.use_pv }} @@ -52,4 +53,5 @@ spec: storage: 1Gi {{ end }} -{{ end }} \ No newline at end of file +{{ end }} +{{- end }} \ No newline at end of file diff --git a/charts/ska-tango-base/templates/tangodb.yaml b/charts/ska-tango-base/templates/tangodb.yaml index 548bf497641fd6d851f9ea98043f31257b602717..4e42acbefc4e6c7e63570cdce3e64f71b98afaab 100644 --- a/charts/ska-tango-base/templates/tangodb.yaml +++ b/charts/ska-tango-base/templates/tangodb.yaml @@ -1,4 +1,5 @@ -{{ if .Values.tangodb.enabled }} +{{- if .Values.tangodb.enabled }} +{{- if not .Values.global.operator }} --- apiVersion: v1 @@ -159,4 +160,5 @@ spec: {{ toYaml . | indent 8 }} {{- end }} -{{ end }} \ No newline at end of file +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/ska-tango-util/templates/_deviceserver-pvc.yaml b/charts/ska-tango-util/templates/_deviceserver-pvc.yaml index 4399812937cc5a4d7e9cad673383c68b6ac601a5..b8faa9db48f9316ef8d59c6b223a7fd9ef083225 100644 --- a/charts/ska-tango-util/templates/_deviceserver-pvc.yaml +++ b/charts/ska-tango-util/templates/_deviceserver-pvc.yaml @@ -17,19 +17,15 @@ Parameters are: - local (the local chart) */}} -{{ define "ska-tango-util.deviceserver-pvc.tpl" }} - ---- -{{/* replace with "if and .volume (not .volume.existingClaimName)" for Helm >= 3.10 */}} +{{- define "ska-tango-util.deviceserver-pvc.tpl" }} +{{- /* replace with "if and .volume (not .volume.existingClaimName)" for Helm >= 3.10 */}} {{- if .volume }} {{- if not .volume.existingClaimName }} - -{{ $volume_name := .volume.name }} -{{ $volume_path := .volume.mountPath }} -{{ $volume_size := coalesce .volume.storage "250Mi" }} -{{ $labels := coalesce .local.Values.global.labels .local.Values.labels "label:none" }} -{{ $annotations := coalesce .local.Values.global.annotations .local.Values.annotations }} - +{{- $volume_name := .volume.name }} +{{- $volume_path := .volume.mountPath }} +{{- $volume_size := coalesce .volume.storage "250Mi" }} +{{- $labels := coalesce .local.Values.global.labels .local.Values.labels "label:none" }} +{{- $annotations := coalesce .local.Values.global.annotations .local.Values.annotations }} --- apiVersion: v1 kind: PersistentVolumeClaim @@ -38,16 +34,16 @@ metadata: namespace: {{ .local.Release.Namespace }} labels: {{ toYaml $labels | indent 4 }} -{{ if $annotations }} +{{- if $annotations }} annotations: {{ toYaml $annotations | indent 4 }} -{{ end }} +{{- end }} spec: -{{ if (coalesce .local.Values.global.minikube .local.Values.minikube false) }} +{{- if (coalesce .local.Values.global.minikube .local.Values.minikube false) }} storageClassName: standard -{{ else }} +{{- else }} storageClassName: nfss1 -{{ end }} +{{- end }} accessModes: - ReadWriteMany resources: @@ -55,7 +51,6 @@ spec: storage: {{ $volume_size }} --- - apiVersion: apps/v1 kind: Deployment metadata: @@ -64,10 +59,10 @@ metadata: {{ toYaml $labels | indent 4 }} name: {{ $volume_name | toString }}-admin-{{ .local.Release.Name }} namespace: {{ .local.Release.Namespace }} -{{ if $annotations }} +{{- if $annotations }} annotations: {{ toYaml $annotations | indent 4 }} -{{ end }} +{{- end }} spec: replicas: 1 selector: diff --git a/charts/ska-tango-util/templates/_entrypoints-script.yml b/charts/ska-tango-util/templates/_entrypoints-script.yml new file mode 100644 index 0000000000000000000000000000000000000000..d406f103204ff74fb443c930ca02d7af5f890994 --- /dev/null +++ b/charts/ska-tango-util/templates/_entrypoints-script.yml @@ -0,0 +1,45 @@ +{{- /* +tango-util.entrypoints-script.tpl +Parameters: +- deviceserver (the deviceserver entire yaml tag) +- DEBUG (number: activate debugpy at this port; leave empty otherwise) +*/}} +{{- define "ska-tango-util.entrypoints-script.tpl" }} +#!/usr/bin/env python + +import importlib +import importlib.util +from tango.server import run + +classes = [] + +{{- range $entrypoint := .deviceserver.entrypoints }} +splitted_name = str(" {{ $entrypoint.name }} ").split(sep='.') +module_name = ".".join(splitted_name[:-1]) +{{- if $entrypoint.path }} +spec = importlib.util.spec_from_file_location(module_name.strip(), "{{ $entrypoint.path }}") +mod = importlib.util.module_from_spec(spec) +spec.loader.exec_module(mod) + +myclass = getattr(mod, splitted_name[-1].strip()) +if not myclass in classes: + classes.append(myclass) + +{{- else }} + +mod = importlib.import_module(module_name.strip()) +myclass = getattr(mod, splitted_name[-1].strip()) +if not myclass in classes: + classes.append(myclass) + +{{- end }} +{{- end }} + +def main(args=None, **kwargs): + {{ if .DEBUG }}import debugpy; debugpy.listen({{ .DEBUG }}){{ end }} + return run(classes=(classes), args=args, **kwargs) + +if __name__ == '__main__': + main() + +{{- end }} \ No newline at end of file diff --git a/charts/ska-tango-util/templates/_multidevice-config.yaml b/charts/ska-tango-util/templates/_multidevice-config.yaml index ae1d5e31cc76714dce57343e618ad04ab6891030..e31422eefdb07135b58af086f4d05d2cc85a2ffd 100644 --- a/charts/ska-tango-util/templates/_multidevice-config.yaml +++ b/charts/ska-tango-util/templates/_multidevice-config.yaml @@ -1,10 +1,10 @@ {{ define "ska-tango-util.multidevice-config.tpl" }} ---- -{{ $labels := coalesce .local.Values.global.labels .local.Values.labels "label: none" }} -{{ $annotations := coalesce .local.Values.global.annotations .local.Values.annotations }} -{{ $deviceserver := .deviceserver }} -{{ $deviceserver_name := tpl (coalesce .name .deviceserver.name | toString) .local }} -{{ $chart := .local }} +{{- $labels := coalesce .local.Values.global.labels .local.Values.labels "label: none" }} +{{- $annotations := coalesce .local.Values.global.annotations .local.Values.annotations }} +{{- $deviceserver := .deviceserver }} +{{- $deviceserver_name := tpl (coalesce .name .deviceserver.name | toString) .local }} +{{- $chart := .local }} +{{- if not .local.Values.global.operator }} --- # Device Server configuration @@ -22,7 +22,6 @@ metadata: annotations: {{ toYaml $annotations | indent 4 }} data: -{{- if not .local.Values.global.operator }} configuration.json: | { "servers": { @@ -115,42 +114,8 @@ data: exit $rc fi fi -{{- end }} {{ $deviceserver.server.name }}.py: | - import importlib - import importlib.util - from tango.server import run - - classes = [] - - {{- range $entrypoint := $deviceserver.entrypoints }} - splitted_name = str(" {{ $entrypoint.name }} ").split(sep='.') - module_name = ".".join(splitted_name[:-1]) - {{- if $entrypoint.path }} - spec = importlib.util.spec_from_file_location(module_name.strip(), "{{ $entrypoint.path }}") - mod = importlib.util.module_from_spec(spec) - spec.loader.exec_module(mod) - - myclass = getattr(mod, splitted_name[-1].strip()) - if not myclass in classes: - classes.append(myclass) - - {{- else }} - - mod = importlib.import_module(module_name.strip()) - myclass = getattr(mod, splitted_name[-1].strip()) - if not myclass in classes: - classes.append(myclass) - - {{- end }} - {{- end }} - - def main(args=None, **kwargs): - {{ if $chart.Values.global.DEBUG }}import debugpy; debugpy.listen({{ $chart.Values.global.DEBUG }}){{ end }} - return run(classes=(classes), args=args, **kwargs) - - if __name__ == '__main__': - main() - - -{{ end }} # multidevice-config.tpl +{{- $context := dict "deviceserver" $deviceserver "DEBUG" $chart.Values.global.DEBUG }} +{{- include "ska-tango-util.entrypoints-script.tpl" $context | nindent 4}} +{{- end }} +{{- end }} # multidevice-config.tpl \ No newline at end of file diff --git a/charts/ska-tango-util/templates/_operator-ds.yaml b/charts/ska-tango-util/templates/_operator-ds.yaml index a7fd9545108aa6691b87251729d9c3b260ca5026..700e7fe4ebc942f0e39a2469ea3e74ca0e603697 100644 --- a/charts/ska-tango-util/templates/_operator-ds.yaml +++ b/charts/ska-tango-util/templates/_operator-ds.yaml @@ -7,7 +7,6 @@ Parameters: - instance (of the device server) */}} {{ define "ska-tango-util.operator-svc.tpl" }} ---- {{- $labels := coalesce .local.Values.global.labels .local.Values.labels "label:none" }} {{- $annotations := coalesce .local.Values.global.annotations .local.Values.annotations }} {{- $default_tango_host := printf "%s-%s:10000" "databaseds-tango-base-" .local.Release.Name }} @@ -31,10 +30,10 @@ metadata: function: {{ $deviceserver.function }} domain: {{ $deviceserver.domain }} subsystem: {{ $chart.Values.subsystem }} -{{ if $annotations }} +{{- if $annotations }} annotations: {{ toYaml $annotations | indent 4 }} -{{ end }} +{{- end }} spec: {{- if or ($chart.Values.global.minikube) ($chart.Values.global.exposeAllDS) ($deviceserver.exposeDS) }} enableLoadBalancer: true @@ -43,24 +42,19 @@ spec: image: "{{ tpl ($deviceserver.image.registry | toString) $chart }}/{{ tpl ($deviceserver.image.image | toString) $chart }}:{{ tpl ($deviceserver.image.tag | toString) $chart }}" imagePullPolicy: {{ tpl ($deviceserver.image.pullPolicy | toString) $chart }} args: "{{ $safe_instance | toString }}" + {{- if hasKey $deviceserver "volume" }} volumes: - - name: configuration - configMap: - name: {{$deviceserver_name | toString }}-{{ $chart.Release.Name }}-dsconfig-json - {{ if hasKey $deviceserver "volume" }} - name: volume-data persistentVolumeClaim: claimName: {{ $deviceserver.volume.existingClaimName | default (printf "%s-pvc-%s" $deviceserver.volume.name $chart.Release.Name) }} - {{ end }} + {{- end }} + {{- with $deviceserver.volume }} volumeMounts: - - name: configuration - mountPath: data - readOnly: true - {{ with $deviceserver.volume }} - name: volume-data mountPath: {{ .mountPath }} readOnly: {{ (hasKey . "readOnly" | ternary .readOnly true) }}{{/* https://github.com/helm/helm/issues/3308 */}} - {{ end }} + {{- end }} + dsname: "{{ $deviceserver_name }}" config: | { "servers": { @@ -138,9 +132,11 @@ spec: } {{- $_ := unset $deviceserver "tmp_start_instance" }} {{- if $deviceserver.command }} - script: "{{ $deviceserver.command }}" + command: "{{ $deviceserver.command }}" {{- else }} - script: "/data/{{ $deviceserver.server.name }}.py" + script: | +{{- $context := dict "deviceserver" $deviceserver "DEBUG" $chart.Values.global.DEBUG }} +{{- include "ska-tango-util.entrypoints-script.tpl" $context | nindent 4 }} {{- end }} {{- if ($deviceserver.depends_on) }} dependsOn: @@ -178,10 +174,8 @@ spec: {{- with $chart.Values.tolerations }} tolerations: {{- toYaml . | nindent 4 }} -{{- end }} -{{ end }} ## if has - -{{ end }} # range instances - -{{ end }} # ska-tango-util.operator-svc.tpl +{{- end }} +{{- end }} ## if has +{{- end }} # range instances +{{- end }} # ska-tango-util.operator-svc.tpl \ No newline at end of file