From 538e6307741cece168423a4638c12462dfc0b656 Mon Sep 17 00:00:00 2001 From: "Grzegorz Grasza (xek)" Date: Tue, 10 Oct 2017 09:48:18 +0000 Subject: [PATCH] Support services in different namespaces Pass the service namespace to kubernetes-entrypoint in order to support dependencies between namespaces. Add documentation about endpoint/service namespaces. Change-Id: I208c3240e9f2c8900323595f7b0e488bef5cb1fc Implements: blueprint entrypoint-namespaces --- doc/source/devref/endpoints.rst | 5 +++ ...ce_name_endpoint_with_namespace_lookup.tpl | 34 +++++++++++++++++++ .../_kubernetes_entrypoint_init_container.tpl | 2 +- ...ist.tpl => _comma_joined_service_list.tpl} | 4 +-- 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 helm-toolkit/templates/endpoints/_service_name_endpoint_with_namespace_lookup.tpl rename helm-toolkit/templates/utils/{_comma_joined_hostname_list.tpl => _comma_joined_service_list.tpl} (86%) diff --git a/doc/source/devref/endpoints.rst b/doc/source/devref/endpoints.rst index 3bbefdb000..414a35ab34 100644 --- a/doc/source/devref/endpoints.rst +++ b/doc/source/devref/endpoints.rst @@ -98,3 +98,8 @@ Charts should not use hard coded values such as ``http://keystone-api:5000`` because these are not compatible with operator overrides and do not support spreading components out over various namespaces. + +By default, each endpoint is located in the same namespace as the current +service's helm chart. To connect to a service which is running in a different +kubernetes namespace, a ``namespace`` can be provided to each individual +endpoint. 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 new file mode 100644 index 0000000000..c4a82a60a9 --- /dev/null +++ b/helm-toolkit/templates/endpoints/_service_name_endpoint_with_namespace_lookup.tpl @@ -0,0 +1,34 @@ +{{/* +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. +*/}} + +# This function returns endpoint ":" pair from an endpoint +# definition. This is used in kubernetes-entrypoint to support dependencies +# between different services in different namespaces. +# returns: the endpoint namespace and the service name, delimited by a colon + +{{- define "helm-toolkit.endpoints.service_name_endpoint_with_namespace_lookup" -}} +{{- $type := index . 0 -}} +{{- $endpoint := index . 1 -}} +{{- $context := index . 2 -}} +{{- $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 }} +{{- printf "%s:%s" $endpointNamespace $endpointName -}} +{{- end -}} +{{- end -}} diff --git a/helm-toolkit/templates/snippets/_kubernetes_entrypoint_init_container.tpl b/helm-toolkit/templates/snippets/_kubernetes_entrypoint_init_container.tpl index 3c96d07184..80fd4df9d8 100644 --- a/helm-toolkit/templates/snippets/_kubernetes_entrypoint_init_container.tpl +++ b/helm-toolkit/templates/snippets/_kubernetes_entrypoint_init_container.tpl @@ -35,7 +35,7 @@ limitations under the License. - name: INTERFACE_NAME value: eth0 - name: DEPENDENCY_SERVICE - value: "{{ tuple $deps.services $envAll | include "helm-toolkit.utils.comma_joined_hostname_list" }}" + value: "{{ tuple $deps.services $envAll | include "helm-toolkit.utils.comma_joined_service_list" }}" - name: DEPENDENCY_JOBS value: "{{ include "helm-toolkit.utils.joinListWithComma" $deps.jobs }}" - name: DEPENDENCY_DAEMONSET diff --git a/helm-toolkit/templates/utils/_comma_joined_hostname_list.tpl b/helm-toolkit/templates/utils/_comma_joined_service_list.tpl similarity index 86% rename from helm-toolkit/templates/utils/_comma_joined_hostname_list.tpl rename to helm-toolkit/templates/utils/_comma_joined_service_list.tpl index 69747687ea..7f965eade7 100644 --- a/helm-toolkit/templates/utils/_comma_joined_hostname_list.tpl +++ b/helm-toolkit/templates/utils/_comma_joined_service_list.tpl @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "helm-toolkit.utils.comma_joined_hostname_list" -}} +{{- define "helm-toolkit.utils.comma_joined_service_list" -}} {{- $deps := index . 0 -}} {{- $envAll := index . 1 -}} -{{- range $k, $v := $deps -}}{{- if $k -}},{{- end -}}{{ tuple $v.service $v.endpoint $envAll | include "helm-toolkit.endpoints.hostname_short_endpoint_lookup" }}{{- end -}} +{{- range $k, $v := $deps -}}{{- if $k -}},{{- end -}}{{ tuple $v.service $v.endpoint $envAll | include "helm-toolkit.endpoints.service_name_endpoint_with_namespace_lookup" }}{{- end -}} {{- end -}}