Sylvain Desbureaux | 16bdf24 | 2020-12-07 10:28:24 +0100 | [diff] [blame] | 1 | {{/* |
| 2 | # Copyright © 2020 Samsung Electronics |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | */}} |
| 16 | |
| 17 | |
| 18 | {{/* |
| 19 | For internal use only! |
| 20 | |
| 21 | Return true value if robot via ingress test is enabled |
| 22 | |
| 23 | The template takes two arguments: |
| 24 | - .parent: environment (.) |
| 25 | - .key: robot test component name |
| 26 | */}} |
| 27 | |
| 28 | {{- define "robot.ingress.svchost._isen" -}} |
| 29 | {{- $key := .key -}} |
| 30 | {{- $master := .parent.Values.config.useIngressHost -}} |
| 31 | {{- if hasKey $master "enabled" -}} |
| 32 | {{- if (index $master "enabled") -}} |
| 33 | {{- if hasKey $master $key -}} |
| 34 | {{- $en_parent := (index $master $key) -}} |
| 35 | {{- if hasKey $en_parent "enabled" -}} |
| 36 | {{- default "" (index $en_parent "enabled") -}} |
| 37 | {{- else -}} |
| 38 | {{- "" -}} |
| 39 | {{- end -}} |
| 40 | {{- else -}} |
| 41 | {{- "" -}} |
| 42 | {{- end -}} |
| 43 | {{- else -}} |
| 44 | {{- "" -}} |
| 45 | {{- end -}} |
| 46 | {{- else -}} |
| 47 | {{- "" -}} |
| 48 | {{- end -}} |
| 49 | {{- end -}} |
| 50 | |
| 51 | {{/* |
| 52 | For internal use only! |
| 53 | |
| 54 | Return ingress alternative hotname if present |
| 55 | |
| 56 | The template takes two arguments: |
| 57 | - .parent: environment (.) |
| 58 | - .key: robot test component name |
| 59 | */}} |
| 60 | |
| 61 | {{- define "robot.ingress.svchost._inghost" -}} |
| 62 | {{- $key := .key -}} |
| 63 | {{- $master := .parent.Values.config.useIngressHost -}} |
| 64 | {{- if hasKey $master $key -}} |
| 65 | {{- $h_parent := (index $master $key) -}} |
| 66 | {{- if hasKey $h_parent "hostname" -}} |
| 67 | {{- default "" (index $h_parent "hostname") -}} |
| 68 | {{- else -}} |
| 69 | {{- "" -}} |
| 70 | {{- end -}} |
| 71 | {{- else -}} |
| 72 | {{- "" -}} |
| 73 | {{- end -}} |
| 74 | {{- end -}} |
| 75 | |
| 76 | {{/* |
| 77 | For internal use only! |
| 78 | |
| 79 | Return robot target port depending on the robot test configuration |
| 80 | or default value if config is not available |
| 81 | |
| 82 | The template takes two arguments: |
| 83 | - .parent: environment (.) |
| 84 | - .key: robot test component name |
| 85 | */}} |
| 86 | {{- define "robot.ingress.svchost._port" -}} |
| 87 | {{- $key := .key -}} |
| 88 | {{- $master := .parent.Values.config.useIngressHost -}} |
| 89 | {{- if hasKey $master $key -}} |
| 90 | {{- $https_parent := (index $master $key) -}} |
| 91 | {{- if hasKey $https_parent "https" -}} |
| 92 | {{- $ishttps := (index $https_parent "https") -}} |
| 93 | {{- ternary 443 80 $ishttps -}} |
| 94 | {{- else -}} |
| 95 | {{- 80 -}} |
| 96 | {{- end -}} |
| 97 | {{- else -}} |
| 98 | {{- 80 -}} |
| 99 | {{- end -}} |
| 100 | {{- end -}} |
| 101 | |
| 102 | {{/* |
| 103 | Return the hostname for tested compoment by robot |
| 104 | if the ingress is enabled it return cluster ingress |
| 105 | controller hostname. If the ingress controller in robot |
| 106 | test is disabled it returns the internal cluster hostname |
| 107 | |
| 108 | The template takes two arguments: |
| 109 | - .root: root environment (.) |
| 110 | - .hostname: basename of host |
| 111 | |
| 112 | Return string target hostname for robot test on particular component |
| 113 | */}} |
| 114 | {{- define "robot.ingress.svchost" -}} |
| 115 | {{- $hostname := required "service hostname" .hostname -}} |
| 116 | {{- $tplhname := $hostname | replace "-" "_" -}} |
| 117 | {{- $ingress_enabled := include "robot.ingress.svchost._isen" (dict "parent" .root "key" $tplhname) -}} |
| 118 | {{- if $ingress_enabled -}} |
| 119 | {{- if .root.Values.global.ingress -}} |
| 120 | {{- if .root.Values.global.ingress.virtualhost -}} |
| 121 | {{- $domain := .root.Values.global.ingress.virtualhost.baseurl -}} |
| 122 | {{- $ihostname := default $hostname (include "robot.ingress.svchost._inghost" (dict "parent" .root "key" $tplhname)) -}} |
| 123 | {{- printf "%s.%s" $ihostname $domain -}} |
| 124 | {{- end -}} |
| 125 | {{- end -}} |
| 126 | {{- else -}} |
| 127 | {{- $domain := include "common.namespace" .root -}} |
| 128 | {{- printf "%s.%s" $hostname $domain -}} |
| 129 | {{- end -}} |
| 130 | {{- end -}} |
| 131 | |
| 132 | |
| 133 | {{/* |
| 134 | Return the target port for the robot testing purpose |
| 135 | if the ingress is enabled it return cluster ingress |
| 136 | controller port. If the target port doesn't exists |
| 137 | it return default port |
| 138 | |
| 139 | The template takes three arguments: |
| 140 | - .root: root environment (.) |
| 141 | - .hostname: basename of host |
| 142 | - .port Default target port |
| 143 | |
| 144 | Return target port for tested components |
| 145 | */}} |
| 146 | {{- define "robot.ingress.port" -}} |
| 147 | {{- $hostname := required "service hostname" .hostname -}} |
| 148 | {{- $port := required "service port" .port -}} |
| 149 | {{- $tplhname := $hostname | replace "-" "_" -}} |
| 150 | {{- $ingress_enabled := include "robot.ingress.svchost._isen" (dict "parent" .root "key" $tplhname) -}} |
| 151 | {{- if $ingress_enabled -}} |
| 152 | {{- include "robot.ingress.svchost._port" (dict "parent" .root "key" $tplhname) -}} |
| 153 | {{- else -}} |
| 154 | {{- printf "%d" $port -}} |
| 155 | {{- end -}} |
| 156 | {{- end -}} |
| 157 | |