aboutsummaryrefslogtreecommitdiffstats
path: root/templates/_ingress_svc_hostname.tpl
blob: 160bfbf86830f804b5d693c96442054de34ce4bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{{/*
# 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 "enabled" -}}
    {{- if (index $master "enabled") -}}
      {{- if hasKey $master $key -}}
        {{- $en_parent := (index $master $key) -}}
        {{- if hasKey $en_parent "enabled" -}}
          {{- default "" (index $en_parent "enabled") -}}
        {{- else -}}
          {{- "" -}}
        {{- end -}}
      {{- else -}}
        {{- "" -}}
      {{- end -}}
  {{- 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" (dict "parent" .root "key" $tplhname)) -}}
      {{- 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 -}}