|
| 1 | +{{/* |
| 2 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +you may not use this file except in compliance with the License. |
| 4 | +You may obtain a copy of the License at |
| 5 | +
|
| 6 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +
|
| 8 | +Unless required by applicable law or agreed to in writing, software |
| 9 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +See the License for the specific language governing permissions and |
| 12 | +limitations under the License. |
| 13 | +*/}} |
| 14 | + |
| 15 | +{{/* |
| 16 | +abstract: | |
| 17 | + Resolves endpoint string suitible for use with oslo.messaging transport url |
| 18 | + See: https://docs.openstack.org/oslo.messaging/latest/reference/transport.html#oslo_messaging.TransportURL |
| 19 | +examples: |
| 20 | + - values: | |
| 21 | + endpoints: |
| 22 | + cluster_domain_suffix: cluster.local |
| 23 | + oslo_messaging: |
| 24 | + auth: |
| 25 | + cinder: |
| 26 | + username: cinder |
| 27 | + password: password |
| 28 | + statefulset: |
| 29 | + replicas: 2 |
| 30 | + name: rabbitmq-rabbitmq |
| 31 | + hosts: |
| 32 | + default: rabbitmq |
| 33 | + host_fqdn_override: |
| 34 | + default: null |
| 35 | + path: /cinder |
| 36 | + scheme: rabbit |
| 37 | + port: |
| 38 | + amqp: |
| 39 | + default: 5672 |
| 40 | + usage: | |
| 41 | + {{ tuple "oslo_messaging" "internal" "cinder" "amqp" . | include "helm-toolkit.endpoints.authenticated_transport_endpoint_uri_lookup" }} |
| 42 | + return: | |
| 43 | + rabbit://cinder:password@rabbitmq-rabbitmq-0.rabbitmq.default.svc.cluster.local:5672,cinder:password@rabbitmq-rabbitmq-1.rabbitmq.default.svc.cluster.local:5672/cinder |
| 44 | + - values: | |
| 45 | + endpoints: |
| 46 | + cluster_domain_suffix: cluster.local |
| 47 | + oslo_messaging: |
| 48 | + auth: |
| 49 | + cinder: |
| 50 | + username: cinder |
| 51 | + password: password |
| 52 | + statefulset: null |
| 53 | + hosts: |
| 54 | + default: rabbitmq |
| 55 | + host_fqdn_override: |
| 56 | + default: null |
| 57 | + path: /cinder |
| 58 | + scheme: rabbit |
| 59 | + port: |
| 60 | + amqp: |
| 61 | + default: 5672 |
| 62 | + usage: | |
| 63 | + {{ tuple "oslo_messaging" "internal" "cinder" "amqp" . | include "helm-toolkit.endpoints.authenticated_transport_endpoint_uri_lookup" }} |
| 64 | + return: | |
| 65 | + rabbit://cinder:password@rabbitmq.default.svc.cluster.local:5672/cinder |
| 66 | + - values: | |
| 67 | + endpoints: |
| 68 | + cluster_domain_suffix: cluster.local |
| 69 | + oslo_messaging: |
| 70 | + auth: |
| 71 | + cinder: |
| 72 | + username: cinder |
| 73 | + password: password |
| 74 | + statefulset: |
| 75 | + replicas: 2 |
| 76 | + name: rabbitmq-rabbitmq |
| 77 | + hosts: |
| 78 | + default: rabbitmq |
| 79 | + host_fqdn_override: |
| 80 | + default: rabbitmq.openstackhelm.org |
| 81 | + path: /cinder |
| 82 | + scheme: rabbit |
| 83 | + port: |
| 84 | + amqp: |
| 85 | + default: 5672 |
| 86 | + usage: | |
| 87 | + {{ tuple "oslo_messaging" "internal" "cinder" "amqp" . | include "helm-toolkit.endpoints.authenticated_transport_endpoint_uri_lookup" }} |
| 88 | + return: | |
| 89 | + rabbit://cinder:password@rabbitmq.openstackhelm.org:5672/cinder |
| 90 | +*/}} |
| 91 | + |
| 92 | +{{- define "helm-toolkit.endpoints.authenticated_transport_endpoint_uri_lookup" -}} |
| 93 | +{{- $type := index . 0 -}} |
| 94 | +{{- $endpoint := index . 1 -}} |
| 95 | +{{- $userclass := index . 2 -}} |
| 96 | +{{- $port := index . 3 -}} |
| 97 | +{{- $context := index . 4 -}} |
| 98 | +{{- $endpointScheme := tuple $type $endpoint $port $context | include "helm-toolkit.endpoints.keystone_endpoint_scheme_lookup" }} |
| 99 | +{{- $userMap := index $context.Values.endpoints ( $type | replace "-" "_" ) "auth" $userclass }} |
| 100 | +{{- $ssMap := index $context.Values.endpoints ( $type | replace "-" "_" ) "statefulset" | default false}} |
| 101 | +{{- $hostFqdnOverride := index $context.Values.endpoints ( $type | replace "-" "_" ) "host_fqdn_override" }} |
| 102 | +{{- $endpointUser := index $userMap "username" }} |
| 103 | +{{- $endpointPass := index $userMap "password" | urlquery }} |
| 104 | +{{- $endpointHostSuffix := tuple $type $endpoint $context | include "helm-toolkit.endpoints.endpoint_host_lookup" }} |
| 105 | +{{- $endpointPort := tuple $type $endpoint $port $context | include "helm-toolkit.endpoints.endpoint_port_lookup" }} |
| 106 | +{{- $local := dict "endpointCredsAndHosts" list -}} |
| 107 | +{{- if not (or (index $hostFqdnOverride $endpoint | default ( index $hostFqdnOverride "default" ) ) ( not $ssMap ) ) }} |
| 108 | +{{- $endpointHostPrefix := $ssMap.name }} |
| 109 | +{{- range $podInt := until ( atoi (print $ssMap.replicas ) ) }} |
| 110 | +{{- $endpointCredAndHost := printf "%s:%s@%s-%d.%s:%s" $endpointUser $endpointPass $endpointHostPrefix $podInt $endpointHostSuffix $endpointPort }} |
| 111 | +{{- $_ := set $local "endpointCredsAndHosts" ( append $local.endpointCredsAndHosts $endpointCredAndHost ) }} |
| 112 | +{{- end }} |
| 113 | +{{- else }} |
| 114 | +{{- $endpointHost := tuple $type $endpoint $context | include "helm-toolkit.endpoints.endpoint_host_lookup" }} |
| 115 | +{{- $endpointCredAndHost := printf "%s:%s@%s:%s" $endpointUser $endpointPass $endpointHost $endpointPort }} |
| 116 | +{{- $_ := set $local "endpointCredsAndHosts" ( append $local.endpointCredsAndHosts $endpointCredAndHost ) }} |
| 117 | +{{- end }} |
| 118 | +{{- $endpointCredsAndHosts := include "helm-toolkit.utils.joinListWithComma" $local.endpointCredsAndHosts }} |
| 119 | +{{- $endpointPath := tuple $type $endpoint $port $context | include "helm-toolkit.endpoints.keystone_endpoint_path_lookup" }} |
| 120 | +{{- printf "%s://%s%s" $endpointScheme $endpointCredsAndHosts $endpointPath }} |
| 121 | +{{- end -}} |
0 commit comments