[COMMON] Allow use of second Node Port Prefix 27/104227/11
authorSylvain Desbureaux <sylvain.desbureaux@orange.com>
Tue, 24 Mar 2020 08:22:22 +0000 (09:22 +0100)
committerSylvain Desbureaux <sylvain.desbureaux@orange.com>
Tue, 14 Apr 2020 14:35:02 +0000 (16:35 +0200)
OOM uses two node port prefix.
Templates were not able to use the second one.
This patch allows templates to use the second node port prefix and also
to override on a per chart basis the value of the node port prefix.

Issue-ID: OOM-1971
Signed-off-by: Sylvain Desbureaux <sylvain.desbureaux@orange.com>
Change-Id: I05f43e3dad93d6f0fbf575657ea41082e7c91053

kubernetes/common/common/templates/_service.tpl

index 0c7660e..98b8d67 100644 (file)
   {{- default $name .Values.service.name | trunc 63 | trimSuffix "-" -}}
 {{- end -}}
 
+{{/*
+  Resolve the prefix node port to use. We look at these different values in
+  order of priority (first found, first chosen)
+  - .Values.service.nodePortPrefixOverride: override value for nodePort which
+                                            will be use locally;
+  - .Values.global.nodePortPrefix         : global value for nodePort which will
+                                            be used for all charts (unless
+                                            previous one is used);
+  - .Values.global.nodePortPrefixExt      : global value for nodePort which will
+                                            be used for all charts (unless
+                                            previous one is used) if
+                                            useNodePortExt is set to true in
+                                            service or on port;
+  - .Values.service.nodePortPrefix        : value used on a pert chart basis if
+                                            no other version exists.
+
+  The function takes two arguments (inside a dictionary):
+     - .dot : environment (.)
+     - .useNodePortExt : does the port use the "extended" nodeport part or the
+                         normal one?
+*/}}
+{{- define "common.nodePortPrefix" -}}
+{{-   $dot := default . .dot -}}
+{{-   $useNodePortExt := default false .useNodePortExt -}}
+{{-   if or $useNodePortExt $dot.Values.service.useNodePortExt -}}
+{{      $dot.Values.service.nodePortPrefixOverride | default $dot.Values.global.nodePortPrefixExt | default $dot.Values.nodePortPrefix }}
+{{-   else -}}
+{{      $dot.Values.service.nodePortPrefixOverride | default $dot.Values.global.nodePortPrefix | default $dot.Values.nodePortPrefix }}
+{{-   end -}}
+{{- end -}}
+
 {{/* Define the metadata of Service
      The function takes from one to four arguments (inside a dictionary):
      - .dot : environment (.)
@@ -96,7 +127,7 @@ labels: {{- include "common.labels" (dict "labels" $labels "dot" $dot) | nindent
   name: {{ $port.name }}
 {{-       end }}
 {{-       if (eq $serviceType "NodePort") }}
-  nodePort: {{ $dot.Values.global.nodePortPrefix | default $dot.Values.nodePortPrefix }}{{ $port.nodePort }}
+  nodePort: {{ include "common.nodePortPrefix" (dict "dot" $dot "portNodePortExt" $port.useNodePortExt) }}{{ $port.nodePort }}
 {{-       end }}
 {{-     else }}
 - port: {{ default $port.port $port.plain_port }}