diff --git a/helm-toolkit/templates/endpoints/_authenticated_endpoint_uri_lookup.tpl b/helm-toolkit/templates/endpoints/_authenticated_endpoint_uri_lookup.tpl index 994b486f6..4927921f8 100644 --- a/helm-toolkit/templates/endpoints/_authenticated_endpoint_uri_lookup.tpl +++ b/helm-toolkit/templates/endpoints/_authenticated_endpoint_uri_lookup.tpl @@ -49,21 +49,12 @@ return: | {{- $userclass := index . 2 -}} {{- $port := index . 3 -}} {{- $context := index . 4 -}} -{{- $typeYamlSafe := $type | replace "-" "_" }} -{{- $endpointMap := index $context.Values.endpoints $typeYamlSafe }} -{{- $userMap := index $endpointMap.auth $userclass }} -{{- $clusterSuffix := printf "%s.%s" "svc" $context.Values.endpoints.cluster_domain_suffix }} -{{- with $endpointMap -}} -{{- $namespace := .namespace | default $context.Release.Namespace }} -{{- $endpointScheme := .scheme }} +{{- $endpointScheme := tuple $type $endpoint $port $context | include "helm-toolkit.endpoints.keystone_endpoint_scheme_lookup" }} +{{- $userMap := index $context.Values.endpoints ( $type | replace "-" "_" ) "auth" $userclass }} {{- $endpointUser := index $userMap "username" }} {{- $endpointPass := index $userMap "password" }} -{{- $endpointHost := index .hosts $endpoint | default .hosts.default}} -{{- $endpointPortMAP := index .port $port }} -{{- $endpointPort := index $endpointPortMAP $endpoint | default (index $endpointPortMAP "default") }} -{{- $endpointPath := .path | default "" }} -{{- $endpointClusterHostname := printf "%s.%s.%s" $endpointHost $namespace $clusterSuffix }} -{{- $endpointHostname := index .host_fqdn_override $endpoint | default .host_fqdn_override.default | default $endpointClusterHostname }} -{{- printf "%s://%s:%s@%s:%1.f%s" $endpointScheme $endpointUser $endpointPass $endpointHostname $endpointPort $endpointPath -}} -{{- end -}} +{{- $endpointHost := tuple $type $endpoint $context | include "helm-toolkit.endpoints.endpoint_host_lookup" }} +{{- $endpointPort := tuple $type $endpoint $port $context | include "helm-toolkit.endpoints.endpoint_port_lookup" }} +{{- $endpointPath := tuple $type $endpoint $port $context | include "helm-toolkit.endpoints.keystone_endpoint_path_lookup" }} +{{- printf "%s://%s:%s@%s:%s%s" $endpointScheme $endpointUser $endpointPass $endpointHost $endpointPort $endpointPath -}} {{- end -}} diff --git a/helm-toolkit/templates/endpoints/_endpoint_host_lookup.tpl b/helm-toolkit/templates/endpoints/_endpoint_host_lookup.tpl new file mode 100644 index 000000000..e789b0e71 --- /dev/null +++ b/helm-toolkit/templates/endpoints/_endpoint_host_lookup.tpl @@ -0,0 +1,49 @@ +{{/* +Copyright 2017 The Openstack-Helm Authors. + +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. +*/}} + +{{/* +abstract: | + Resolves either the fully qualified hostname, of if defined in the host feild + IPv4 for an endpoint. +values: | + endpoints: + cluster_domain_suffix: cluster.local + oslo_db: + hosts: + default: mariadb + host_fqdn_override: + default: null +usage: | + {{ tuple "oslo_db" "internal" . | include "helm-toolkit.endpoints.endpoint_host_lookup" }} +return: | + mariadb.default.svc.cluster.local +*/}} + +{{- define "helm-toolkit.endpoints.endpoint_host_lookup" -}} +{{- $type := index . 0 -}} +{{- $endpoint := index . 1 -}} +{{- $context := index . 2 -}} +{{- $endpointMap := index $context.Values.endpoints ( $type | replace "-" "_" ) }} +{{- $endpointScheme := $endpointMap.scheme }} +{{- $endpointHost := index $endpointMap.hosts $endpoint | default $endpointMap.hosts.default }} +{{- if regexMatch "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+" $endpointHost }} +{{- $endpointHostname := printf "%s" $endpointHost }} +{{- printf "%s" $endpointHostname -}} +{{- else }} +{{- $endpointHostname := tuple $type $endpoint $context | include "helm-toolkit.endpoints.hostname_fqdn_endpoint_lookup" }} +{{- printf "%s" $endpointHostname -}} +{{- end }} +{{- end -}} diff --git a/helm-toolkit/templates/endpoints/_endpoint_port_lookup.tpl b/helm-toolkit/templates/endpoints/_endpoint_port_lookup.tpl index 718af10a1..a233dbfdc 100644 --- a/helm-toolkit/templates/endpoints/_endpoint_port_lookup.tpl +++ b/helm-toolkit/templates/endpoints/_endpoint_port_lookup.tpl @@ -37,9 +37,7 @@ return: | {{- $context := index . 3 -}} {{- $typeYamlSafe := $type | replace "-" "_" }} {{- $endpointMap := index $context.Values.endpoints $typeYamlSafe }} -{{- with $endpointMap -}} -{{- $endpointPortMAP := index .port $port }} -{{- $endpointPort := index $endpointPortMAP $endpoint | default (index $endpointPortMAP "default") }} +{{- $endpointPortMAP := index $endpointMap.port $port }} +{{- $endpointPort := index $endpointPortMAP $endpoint | default ( index $endpointPortMAP "default" ) }} {{- printf "%1.f" $endpointPort -}} {{- end -}} -{{- end -}} diff --git a/helm-toolkit/templates/endpoints/_host_and_port_endpoint_uri_lookup.tpl b/helm-toolkit/templates/endpoints/_host_and_port_endpoint_uri_lookup.tpl index b4b9d44c6..39107bfb4 100644 --- a/helm-toolkit/templates/endpoints/_host_and_port_endpoint_uri_lookup.tpl +++ b/helm-toolkit/templates/endpoints/_host_and_port_endpoint_uri_lookup.tpl @@ -39,17 +39,7 @@ return: | {{- $endpoint := index . 1 -}} {{- $port := index . 2 -}} {{- $context := index . 3 -}} -{{- $typeYamlSafe := $type | replace "-" "_" }} -{{- $clusterSuffix := printf "%s.%s" "svc" $context.Values.endpoints.cluster_domain_suffix }} -{{- $endpointMap := index $context.Values.endpoints $typeYamlSafe }} -{{- with $endpointMap -}} -{{- $namespace := .namespace | default $context.Release.Namespace }} -{{- $endpointScheme := .scheme }} -{{- $endpointHost := index .hosts $endpoint | default .hosts.default }} -{{- $endpointPortMAP := index .port $port }} -{{- $endpointPort := index $endpointPortMAP $endpoint | default (index $endpointPortMAP "default") }} -{{- $endpointClusterHostname := printf "%s.%s.%s" $endpointHost $namespace $clusterSuffix }} -{{- $endpointHostname := index .host_fqdn_override $endpoint | default .host_fqdn_override.default | default $endpointClusterHostname }} -{{- printf "%s:%1.f" $endpointHostname $endpointPort -}} -{{- end -}} +{{- $endpointPort := tuple $type $endpoint $port $context | include "helm-toolkit.endpoints.endpoint_port_lookup" }} +{{- $endpointHostname := tuple $type $endpoint $context | include "helm-toolkit.endpoints.hostname_fqdn_endpoint_lookup" }} +{{- printf "%s:%s" $endpointHostname $endpointPort -}} {{- end -}} diff --git a/helm-toolkit/templates/endpoints/_hostname_fqdn_endpoint_lookup.tpl b/helm-toolkit/templates/endpoints/_hostname_fqdn_endpoint_lookup.tpl index 99ad76342..eded22dca 100644 --- a/helm-toolkit/templates/endpoints/_hostname_fqdn_endpoint_lookup.tpl +++ b/helm-toolkit/templates/endpoints/_hostname_fqdn_endpoint_lookup.tpl @@ -35,20 +35,14 @@ return: | {{- $type := index . 0 -}} {{- $endpoint := index . 1 -}} {{- $context := index . 2 -}} -{{- $typeYamlSafe := $type | replace "-" "_" }} -{{- $clusterSuffix := printf "%s.%s" "svc" $context.Values.endpoints.cluster_domain_suffix }} -{{- $endpointMap := index $context.Values.endpoints $typeYamlSafe }} -{{- with $endpointMap -}} -{{- $namespace := .namespace | default $context.Release.Namespace }} -{{- $endpointScheme := .scheme }} -{{- $endpointHost := index .hosts $endpoint | default .hosts.default }} -{{- $endpointClusterHostname := printf "%s.%s.%s" $endpointHost $namespace $clusterSuffix }} -{{- if kindIs "map" (index .host_fqdn_override $endpoint) }} -{{- $endpointHostname := index .host_fqdn_override $endpoint "host" | default .host_fqdn_override.default | default $endpointClusterHostname }} +{{- $endpointMap := index $context.Values.endpoints ( $type | replace "-" "_" ) }} +{{- $endpointHostNamespaced := tuple $type $endpoint $context | include "helm-toolkit.endpoints.hostname_namespaced_endpoint_lookup" }} +{{- $endpointClusterHostname := printf "%s.svc.%s" $endpointHostNamespaced $context.Values.endpoints.cluster_domain_suffix }} +{{- if kindIs "map" (index $endpointMap.host_fqdn_override $endpoint) }} +{{- $endpointHostname := index $endpointMap.host_fqdn_override $endpoint "host" | default $endpointMap.host_fqdn_override.default | default $endpointMap.host_fqdn_override.default | default $endpointClusterHostname }} {{- printf "%s" $endpointHostname -}} {{- else }} -{{- $endpointHostname := index .host_fqdn_override $endpoint | default .host_fqdn_override.default | default $endpointClusterHostname }} +{{- $endpointHostname := index $endpointMap.host_fqdn_override $endpoint | default $endpointMap.host_fqdn_override.default | default $endpointClusterHostname }} {{- printf "%s" $endpointHostname -}} {{- end -}} {{- end -}} -{{- end -}} diff --git a/helm-toolkit/templates/endpoints/_hostname_namespaced_endpoint_lookup.tpl b/helm-toolkit/templates/endpoints/_hostname_namespaced_endpoint_lookup.tpl index 71cfbae25..841fee222 100644 --- a/helm-toolkit/templates/endpoints/_hostname_namespaced_endpoint_lookup.tpl +++ b/helm-toolkit/templates/endpoints/_hostname_namespaced_endpoint_lookup.tpl @@ -34,14 +34,9 @@ return: | {{- $type := index . 0 -}} {{- $endpoint := index . 1 -}} {{- $context := index . 2 -}} -{{- $typeYamlSafe := $type | replace "-" "_" }} -{{- $endpointMap := index $context.Values.endpoints $typeYamlSafe }} -{{- with $endpointMap -}} -{{- $namespace := .namespace | default $context.Release.Namespace }} -{{- $endpointScheme := .scheme }} -{{- $endpointHost := index .hosts $endpoint | default .hosts.default }} +{{- $endpointMap := index $context.Values.endpoints ( $type | replace "-" "_" ) }} +{{- $namespace := $endpointMap.namespace | default $context.Release.Namespace }} +{{- $endpointHost := tuple $type $endpoint $context | include "helm-toolkit.endpoints.hostname_short_endpoint_lookup" }} {{- $endpointClusterHostname := printf "%s.%s" $endpointHost $namespace }} -{{- $endpointHostname := index .host_fqdn_override $endpoint | default .host_fqdn_override.default | default $endpointClusterHostname }} -{{- printf "%s" $endpointHostname -}} -{{- end -}} +{{- printf "%s" $endpointClusterHostname -}} {{- end -}} diff --git a/helm-toolkit/templates/endpoints/_hostname_short_endpoint_lookup.tpl b/helm-toolkit/templates/endpoints/_hostname_short_endpoint_lookup.tpl index f239253b0..50626017d 100644 --- a/helm-toolkit/templates/endpoints/_hostname_short_endpoint_lookup.tpl +++ b/helm-toolkit/templates/endpoints/_hostname_short_endpoint_lookup.tpl @@ -34,16 +34,13 @@ return: | {{- $type := index . 0 -}} {{- $endpoint := index . 1 -}} {{- $context := index . 2 -}} -{{- $typeYamlSafe := $type | replace "-" "_" }} -{{- $endpointMap := index $context.Values.endpoints $typeYamlSafe }} -{{- with $endpointMap -}} -{{- $endpointScheme := .scheme }} -{{- $endpointHost := index .hosts $endpoint | default .hosts.default}} +{{- $endpointMap := index $context.Values.endpoints ( $type | replace "-" "_" ) }} +{{- $endpointScheme := $endpointMap.scheme }} +{{- $endpointHost := index $endpointMap.hosts $endpoint | default $endpointMap.hosts.default }} {{- if regexMatch "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+" $endpointHost }} -{{- printf "%s" $typeYamlSafe -}} +{{- printf "%s" $type -}} {{- else }} {{- $endpointHostname := printf "%s" $endpointHost }} {{- printf "%s" $endpointHostname -}} {{- end }} {{- end -}} -{{- end -}} diff --git a/helm-toolkit/templates/endpoints/_keystone_endpoint_name_lookup.tpl b/helm-toolkit/templates/endpoints/_keystone_endpoint_name_lookup.tpl index b9de02a08..9a78cab2e 100644 --- a/helm-toolkit/templates/endpoints/_keystone_endpoint_name_lookup.tpl +++ b/helm-toolkit/templates/endpoints/_keystone_endpoint_name_lookup.tpl @@ -30,8 +30,7 @@ return: | {{- define "helm-toolkit.endpoints.keystone_endpoint_name_lookup" -}} {{- $type := index . 0 -}} {{- $context := index . 1 -}} -{{- $typeYamlSafe := $type | replace "-" "_" }} -{{- $endpointMap := index $context.Values.endpoints $typeYamlSafe }} +{{- $endpointMap := index $context.Values.endpoints ( $type | replace "-" "_" ) }} {{- $endpointName := index $endpointMap "name" }} {{- $endpointName | quote -}} {{- end -}} diff --git a/helm-toolkit/templates/endpoints/_keystone_endpoint_path_lookup.tpl b/helm-toolkit/templates/endpoints/_keystone_endpoint_path_lookup.tpl index 9a9977ca2..5994f7e10 100644 --- a/helm-toolkit/templates/endpoints/_keystone_endpoint_path_lookup.tpl +++ b/helm-toolkit/templates/endpoints/_keystone_endpoint_path_lookup.tpl @@ -40,10 +40,11 @@ return: | {{- $endpoint := index . 1 -}} {{- $port := index . 2 -}} {{- $context := index . 3 -}} -{{- $typeYamlSafe := $type | replace "-" "_" }} -{{- $endpointMap := index $context.Values.endpoints $typeYamlSafe }} -{{- with $endpointMap -}} -{{- $endpointPath := index .path $endpoint | default .path.default | default "/" }} +{{- $endpointMap := index $context.Values.endpoints ( $type | replace "-" "_" ) }} +{{- if kindIs "string" $endpointMap.path }} +{{- printf "%s" $endpointMap.path | default "/" -}} +{{- else -}} +{{- $endpointPath := index $endpointMap.path $endpoint | default $endpointMap.path.default | default "/" }} {{- printf "%s" $endpointPath -}} {{- end -}} {{- end -}} diff --git a/helm-toolkit/templates/endpoints/_keystone_endpoint_scheme_lookup.tpl b/helm-toolkit/templates/endpoints/_keystone_endpoint_scheme_lookup.tpl index c476078e2..bb57b28b8 100644 --- a/helm-toolkit/templates/endpoints/_keystone_endpoint_scheme_lookup.tpl +++ b/helm-toolkit/templates/endpoints/_keystone_endpoint_scheme_lookup.tpl @@ -47,10 +47,11 @@ return: | {{- $endpoint := index . 1 -}} {{- $port := index . 2 -}} {{- $context := index . 3 -}} -{{- $typeYamlSafe := $type | replace "-" "_" }} -{{- $endpointMap := index $context.Values.endpoints $typeYamlSafe }} -{{- with $endpointMap -}} -{{- $endpointScheme := index .scheme $endpoint | default .scheme.default | default "http" }} +{{- $endpointMap := index $context.Values.endpoints ( $type | replace "-" "_" ) }} +{{- if kindIs "string" $endpointMap.scheme }} +{{- printf "%s" $endpointMap.scheme | default "http" -}} +{{- else -}} +{{- $endpointScheme := index $endpointMap.scheme $endpoint | default $endpointMap.scheme.default | default "http" }} {{- printf "%s" $endpointScheme -}} {{- end -}} {{- end -}} diff --git a/helm-toolkit/templates/endpoints/_keystone_endpoint_uri_lookup.tpl b/helm-toolkit/templates/endpoints/_keystone_endpoint_uri_lookup.tpl index bb75a98cf..bb8a1e566 100644 --- a/helm-toolkit/templates/endpoints/_keystone_endpoint_uri_lookup.tpl +++ b/helm-toolkit/templates/endpoints/_keystone_endpoint_uri_lookup.tpl @@ -41,27 +41,9 @@ return: | {{- $endpoint := index . 1 -}} {{- $port := index . 2 -}} {{- $context := index . 3 -}} -{{- $typeYamlSafe := $type | replace "-" "_" }} -{{- $clusterSuffix := printf "%s.%s" "svc" $context.Values.endpoints.cluster_domain_suffix }} -{{- $endpointMap := index $context.Values.endpoints $typeYamlSafe }} -{{- with $endpointMap -}} -{{- $namespace := $endpointMap.namespace | default $context.Release.Namespace }} -{{- $endpointScheme := index .scheme $endpoint | default .scheme.default }} -{{- $endpointHost := index .hosts $endpoint | default .hosts.default }} -{{- $endpointPortMAP := index .port $port }} -{{- $endpointPort := index $endpointPortMAP $endpoint | default (index $endpointPortMAP "default") }} -{{- $endpointPath := index .path $endpoint | default .path.default | default "/" }} -{{- $endpointClusterHostname := printf "%s.%s.%s" $endpointHost $namespace $clusterSuffix }} -{{- if regexMatch "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+" $endpointHost }} -{{- printf "%s://%s:%1.f%s" $endpointScheme $endpointHost $endpointPort $endpointPath -}} -{{- else -}} -{{- if kindIs "map" (index .host_fqdn_override $endpoint) }} -{{- $endpointFqdnHostname := index .host_fqdn_override $endpoint "host" | default .host_fqdn_override.default | default $endpointClusterHostname }} -{{- printf "%s://%s:%1.f%s" $endpointScheme $endpointFqdnHostname $endpointPort $endpointPath -}} -{{- else }} -{{- $endpointFqdnHostname := index .host_fqdn_override $endpoint | default .host_fqdn_override.default | default $endpointClusterHostname }} -{{- printf "%s://%s:%1.f%s" $endpointScheme $endpointFqdnHostname $endpointPort $endpointPath -}} -{{- end -}} -{{- end -}} -{{- end -}} +{{- $endpointScheme := tuple $type $endpoint $port $context | include "helm-toolkit.endpoints.keystone_endpoint_scheme_lookup" }} +{{- $endpointHost := tuple $type $endpoint $context | include "helm-toolkit.endpoints.endpoint_host_lookup" }} +{{- $endpointPort := tuple $type $endpoint $port $context | include "helm-toolkit.endpoints.endpoint_port_lookup" }} +{{- $endpointPath := tuple $type $endpoint $port $context | include "helm-toolkit.endpoints.keystone_endpoint_path_lookup" }} +{{- printf "%s://%s:%s%s" $endpointScheme $endpointHost $endpointPort $endpointPath -}} {{- end -}} diff --git a/helm-toolkit/templates/endpoints/_service_name_endpoint_with_namespace_lookup.tpl b/helm-toolkit/templates/endpoints/_service_name_endpoint_with_namespace_lookup.tpl index e8c9277b7..9178ce5f7 100644 --- a/helm-toolkit/templates/endpoints/_service_name_endpoint_with_namespace_lookup.tpl +++ b/helm-toolkit/templates/endpoints/_service_name_endpoint_with_namespace_lookup.tpl @@ -48,7 +48,6 @@ return: | {{- $typeYamlSafe := $type | replace "-" "_" }} {{- $endpointMap := index $context.Values.endpoints $typeYamlSafe }} {{- with $endpointMap -}} -{{- $endpointScheme := .scheme }} {{- $endpointName := index .hosts $endpoint | default .hosts.default}} {{- $endpointNamespace := .namespace | default $context.Release.Namespace }} {{- if regexMatch "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+" $endpointName }}