summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucjan Bryndza <l.bryndza@samsung.com>2020-04-09 17:02:48 +0200
committerLucjan Bryndza <l.bryndza@samsung.com>2020-05-05 08:20:54 +0000
commit326460deaa97b45e3935a7330c38484d866621a4 (patch)
treee7456618af57cb1932f2fdbfd10f702104c3ae5a
parentc81062626b69160145baac5e6a5d670cb67211fa (diff)
Host and port template for ingress setup
Depending on the ingress robot configuration host and port template should choose ingress host and port or direct cluster host and port + alternarive ingress hostname in config file Change-Id: I04c13657f5c5cf8b5f5373897bdc551dc2efdf36 Issue-ID: OOM-2341 Signed-off-by: Lucjan Bryndza <l.bryndza@samsung.com>
-rw-r--r--templates/_ingress_svc_hostname.tpl149
1 files changed, 149 insertions, 0 deletions
diff --git a/templates/_ingress_svc_hostname.tpl b/templates/_ingress_svc_hostname.tpl
new file mode 100644
index 0000000..472c121
--- /dev/null
+++ b/templates/_ingress_svc_hostname.tpl
@@ -0,0 +1,149 @@
+{{/*
+# Copyright © 2020 Samsung Electronics
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+*/}}
+
+
+{{/*
+ For internal use only!
+
+ Return true value if robot via ingress test is enabled
+
+ The template takes two arguments:
+ - .parent: environment (.)
+ - .key: robot test component name
+*/}}
+
+{{- define "robot.ingress.svchost._isen" -}}
+ {{- $key := .key -}}
+ {{- $master := .parent.Values.config.useIngressHost -}}
+ {{- if hasKey $master $key -}}
+ {{- $en_parent := (index $master $key) -}}
+ {{- if hasKey $en_parent "enabled" -}}
+ {{- default "" (index $en_parent "enabled") -}}
+ {{- else -}}
+ {{- "" -}}
+ {{- end -}}
+ {{- else -}}
+ {{- "" -}}
+ {{- end -}}
+{{- end -}}
+
+{{/*
+ For internal use only!
+
+ Return ingress alternative hotname if present
+
+ The template takes two arguments:
+ - .parent: environment (.)
+ - .key: robot test component name
+*/}}
+
+{{- define "robot.ingress.svchost._inghost" -}}
+ {{- $key := .key -}}
+ {{- $master := .parent.Values.config.useIngressHost -}}
+ {{- if hasKey $master $key -}}
+ {{- $h_parent := (index $master $key) -}}
+ {{- if hasKey $h_parent "hostname" -}}
+ {{- default "" (index $h_parent "hostname") -}}
+ {{- else -}}
+ {{- "" -}}
+ {{- end -}}
+ {{- else -}}
+ {{- "" -}}
+ {{- end -}}
+{{- end -}}
+
+{{/*
+ For internal use only!
+
+ Return robot target port depending on the robot test configuration
+ or default value if config is not available
+
+ The template takes two arguments:
+ - .parent: environment (.)
+ - .key: robot test component name
+*/}}
+{{- define "robot.ingress.svchost._port" -}}
+ {{- $key := .key -}}
+ {{- $master := .parent.Values.config.useIngressHost -}}
+ {{- if hasKey $master $key -}}
+ {{- $https_parent := (index $master $key) -}}
+ {{- if hasKey $https_parent "https" -}}
+ {{- $ishttps := (index $https_parent "https") -}}
+ {{- ternary 443 80 $ishttps -}}
+ {{- else -}}
+ {{- 80 -}}
+ {{- end -}}
+ {{- else -}}
+ {{- 80 -}}
+ {{- end -}}
+{{- end -}}
+
+{{/*
+ Return the hostname for tested compoment by robot
+ if the ingress is enabled it return cluster ingress
+ controller hostname. If the ingress controller in robot
+ test is disabled it returns the internal cluster hostname
+
+ The template takes two arguments:
+ - .root: root environment (.)
+ - .hostname: basename of host
+
+ Return string target hostname for robot test on particular component
+*/}}
+{{- define "robot.ingress.svchost" -}}
+ {{- $hostname := required "service hostname" .hostname -}}
+ {{- $tplhname := $hostname | replace "-" "_" -}}
+ {{- $ingress_enabled := include "robot.ingress.svchost._isen" (dict "parent" .root "key" $tplhname) -}}
+ {{- if $ingress_enabled -}}
+ {{- if .root.Values.global.ingress -}}
+ {{- if .root.Values.global.ingress.virtualhost -}}
+ {{- $domain := .root.Values.global.ingress.virtualhost.baseurl -}}
+ {{- $ihostname := default $hostname (include "robot.ingress.svchost._inghost") -}}
+ {{- printf "%s.%s" $ihostname $domain -}}
+ {{- end -}}
+ {{- end -}}
+ {{- else -}}
+ {{- $domain := include "common.namespace" .root -}}
+ {{- printf "%s.%s" $hostname $domain -}}
+ {{- end -}}
+{{- end -}}
+
+
+{{/*
+ Return the target port for the robot testing purpose
+ if the ingress is enabled it return cluster ingress
+ controller port. If the target port doesn't exists
+ it return default port
+
+ The template takes three arguments:
+ - .root: root environment (.)
+ - .hostname: basename of host
+ - .port Default target port
+
+ Return target port for tested components
+*/}}
+{{- define "robot.ingress.port" -}}
+ {{- $hostname := required "service hostname" .hostname -}}
+ {{- $port := required "service port" .port -}}
+ {{- $tplhname := $hostname | replace "-" "_" -}}
+ {{- $ingress_enabled := include "robot.ingress.svchost._isen" (dict "parent" .root "key" $tplhname) -}}
+ {{- if $ingress_enabled -}}
+ {{- include "robot.ingress.svchost._port" (dict "parent" .root "key" $tplhname) -}}
+ {{- else -}}
+ {{- printf "%d" $port -}}
+ {{- end -}}
+{{- end -}}
+