[COMMON] Fix problem with useNodePortExt
[oom.git] / kubernetes / common / common / templates / _service.tpl
index 98b8d67..9c3010c 100644 (file)
@@ -94,6 +94,7 @@ annotations:
         "version": "{{ default "v1" $msb_information.version }}",
         "url": "{{ default "/" $msb_information.url }}",
         "protocol": "{{ default "REST" $msb_information.protocol }}",
+        "enable_ssl": {{ default false $msb_information.enable_ssl }},
         "port": "{{ $msb_information.port }}",
         "visualRange":"{{ default "1" $msb_information.visualRange }}"
       }
@@ -127,7 +128,7 @@ labels: {{- include "common.labels" (dict "labels" $labels "dot" $dot) | nindent
   name: {{ $port.name }}
 {{-       end }}
 {{-       if (eq $serviceType "NodePort") }}
-  nodePort: {{ include "common.nodePortPrefix" (dict "dot" $dot "portNodePortExt" $port.useNodePortExt) }}{{ $port.nodePort }}
+  nodePort: {{ include "common.nodePortPrefix" (dict "dot" $dot "useNodePortExt" $port.useNodePortExt) }}{{ $port.nodePort }}
 {{-       end }}
 {{-     else }}
 - port: {{ default $port.port $port.plain_port }}
@@ -222,8 +223,8 @@ spec:
 {{-   $labels := default (dict) .labels -}}
 {{-   $matchLabels := default (dict) .matchLabels -}}
 
-{{-   if (and (include "common.needTLS" .) $both_tls_and_plain) }}
-{{      include "common.genericService" (dict "suffix" $suffix "annotations" $annotations "msb_informations" $msb_informations "dot" . "publishNotReadyAddresses" $publishNotReadyAddresses "ports" $ports "serviceType" "ClusterIP" "add_plain_port" true $labels "matchLabels" $matchLabels) }}
+{{-   if (and (include "common.needTLS" $dot) $both_tls_and_plain) }}
+{{      include "common.genericService" (dict "suffix" $suffix "annotations" $annotations "msb_informations" $msb_informations "dot" $dot "publishNotReadyAddresses" $publishNotReadyAddresses "ports" $ports "serviceType" "ClusterIP" "add_plain_port" true $labels "matchLabels" $matchLabels) }}
 {{-     if (ne $serviceType "ClusterIP") }}
 ---
 {{-       if $suffix }}
@@ -231,10 +232,10 @@ spec:
 {{-       else }}
 {{-         $suffix = "external" }}
 {{-       end }}
-{{        include "common.genericService" (dict "suffix" $suffix "annotations" $annotations "dot" . "publishNotReadyAddresses" $publishNotReadyAddresses "ports" $ports "serviceType" $serviceType $labels "matchLabels" $matchLabels) }}
+{{        include "common.genericService" (dict "suffix" $suffix "annotations" $annotations "dot" $dot "publishNotReadyAddresses" $publishNotReadyAddresses "ports" $ports "serviceType" $serviceType $labels "matchLabels" $matchLabels) }}
 {{-     end }}
 {{-   else }}
-{{      include "common.genericService" (dict "suffix" $suffix "annotations" $annotations "dot" . "publishNotReadyAddresses" $publishNotReadyAddresses "ports" $ports "serviceType" $serviceType $labels "matchLabels" $matchLabels) }}
+{{      include "common.genericService" (dict "suffix" $suffix "annotations" $annotations "dot" $dot "publishNotReadyAddresses" $publishNotReadyAddresses "ports" $ports "serviceType" $serviceType $labels "matchLabels" $matchLabels) }}
 {{-   end }}
 {{- end -}}
 
@@ -302,3 +303,33 @@ true
 {{-     end }}
 {{-   end }}
 {{- end -}}
+
+{{- define "common.port.buildCache" -}}
+  {{- $global := . }}
+  {{- if not $global.Values._DmaapDrNodePortsCache }}
+    {{- $portCache := dict }}
+    {{- range $port := .Values.service.ports }}
+      {{- $_ := set $portCache $port.name (dict "port" $port.port "plain_port" $port.plain_port) }}
+    {{- end }}
+    {{- $_ := set $global.Values "_DmaapDrNodePortsCache" $portCache }}
+  {{- end }}
+{{- end -}}
+
+{/*
+  Get Port value according to its name and if we want tls or plain port.
+  The template takes below arguments:
+    - .global: environment (.)
+    - .name: name of the port
+    - .getPlain: boolean allowing to choose between tls (false, default) or
+                 plain (true)
+    If plain_port is not set and we ask for plain, it will return empty.
+*/}
+{{- define "common.getPort" -}}
+  {{- $global := .global }}
+  {{- $name := .name }}
+  {{- $getPlain := default false .getPlain }}
+  {{- include "common.port.buildCache" $global }}
+  {{- $portCache := $global.Values._DmaapDrNodePortsCache }}
+  {{- $port := index $portCache $name }}
+  {{- ternary $port.plain_port $port.port $getPlain }}
+{{- end -}}