From c21555fce0d4f9dffce219d1be70e5d5cebca2a7 Mon Sep 17 00:00:00 2001 From: Evgeny L Date: Thu, 18 Jul 2019 21:25:49 +0000 Subject: [PATCH] Use a direct connectivity to RabbitMQ This patch makes Celery to connect to RabbitMQ directly instead of using LB. It also brings a forked version of a transport url template, the reason for this is the format for Kombu/Celery broker url is different from oslo_messaging transport url: 1. URLs need to be separated with semicolons vs commas. 2. Every item in Kombu broker url needs to be a complete url that includes schema, vhost, and all credentials. This format is specific to Airflow and is not used in upstream OSH projects, hence it is included here and not in htk. Depends-On: I5150a64bd29fa062e30496c1f2127de138322863 Change-Id: I0b4ae6a9538f2f6988ed42c8f5cf0a54e7a7ad2e --- .../templates/configmap-airflow-etc.yaml | 2 +- ...nticated_transport_endpoint_uri_lookup.tpl | 123 ++++++++++++++++++ .../templates/secret-user-rabbitmq.yaml | 4 +- .../utils/_joinListWithSemicolon.tpl | 33 +++++ charts/shipyard/values.yaml | 3 + 5 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 charts/shipyard/templates/endpoints/_authenticated_transport_endpoint_uri_lookup.tpl create mode 100644 charts/shipyard/templates/utils/_joinListWithSemicolon.tpl diff --git a/charts/shipyard/templates/configmap-airflow-etc.yaml b/charts/shipyard/templates/configmap-airflow-etc.yaml index 6d37fd43..33796ef2 100644 --- a/charts/shipyard/templates/configmap-airflow-etc.yaml +++ b/charts/shipyard/templates/configmap-airflow-etc.yaml @@ -35,7 +35,7 @@ # Add endpoint URI lookup for RabbitMQ Connection {{- if empty .Values.conf.airflow.celery.broker_url -}} -{{- tuple "oslo_messaging" "internal" "user" "amqp" . | include "helm-toolkit.endpoints.authenticated_endpoint_uri_lookup" | set .Values.conf.airflow.celery "broker_url" | quote | trunc 0 -}} +{{- tuple "oslo_messaging" "internal" "user" "amqp" . | include "shipyard.endpoints.authenticated_transport_endpoint_uri_lookup" | set .Values.conf.airflow.celery "broker_url" | quote | trunc 0 -}} {{- end -}} --- diff --git a/charts/shipyard/templates/endpoints/_authenticated_transport_endpoint_uri_lookup.tpl b/charts/shipyard/templates/endpoints/_authenticated_transport_endpoint_uri_lookup.tpl new file mode 100644 index 00000000..5bc8c91e --- /dev/null +++ b/charts/shipyard/templates/endpoints/_authenticated_transport_endpoint_uri_lookup.tpl @@ -0,0 +1,123 @@ +{{/* +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 endpoint string suitible for use with celery broker url + See: http://docs.celeryproject.org/projects/kombu/en/stable/reference/kombu.connection.html +examples: + - values: | + endpoints: + cluster_domain_suffix: cluster.local + oslo_messaging: + auth: + user: + username: airflow + password: password + statefulset: + replicas: 2 + name: rabbitmq-rabbitmq + hosts: + default: rabbitmq + host_fqdn_override: + default: null + path: /airflow + scheme: amqp + port: + amqp: + default: 5672 + usage: | + {{ tuple "oslo_messaging" "internal" "airflow" "amqp" . | include "shipyard.endpoints.authenticated_transport_endpoint_uri_lookup" }} + return: | + amqp://airflow:password@rabbitmq-rabbitmq-0.rabbitmq.default.svc.cluster.local:5672/airflow;amqp://airflow:password@rabbitmq-rabbitmq-1.rabbitmq.default.svc.cluster.local:5672/airflow + - values: | + endpoints: + cluster_domain_suffix: cluster.local + oslo_messaging: + auth: + user: + username: airflow + password: password + statefulset: null + hosts: + default: rabbitmq + host_fqdn_override: + default: null + path: / + scheme: amqp + port: + amqp: + default: 5672 + usage: | + {{ tuple "oslo_messaging" "internal" "airflow" "amqp" . | include "shipyard.endpoints.authenticated_transport_endpoint_uri_lookup" }} + return: | + amqp://airflow:password@rabbitmq.default.svc.cluster.local:5672/ + - values: | + endpoints: + cluster_domain_suffix: cluster.local + oslo_messaging: + auth: + user: + username: airflow + password: password + statefulset: + replicas: 2 + name: rabbitmq-rabbitmq + hosts: + default: rabbitmq + host_fqdn_override: + default: rabbitmq.openstackhelm.org + path: / + scheme: amqp + port: + amqp: + default: 5672 + usage: | + {{ tuple "oslo_messaging" "internal" "airflow" "amqp" . | include "shipyard.endpoints.authenticated_transport_endpoint_uri_lookup" }} + return: | + amqp://airflow:password@rabbitmq.openstackhelm.org:5672/ +*/}} + +{{- define "shipyard.endpoints.authenticated_transport_endpoint_uri_lookup" -}} +{{- $type := index . 0 -}} +{{- $endpoint := index . 1 -}} +{{- $userclass := index . 2 -}} +{{- $port := index . 3 -}} +{{- $context := index . 4 -}} +{{- $endpointScheme := tuple $type $endpoint $port $context | include "helm-toolkit.endpoints.keystone_endpoint_scheme_lookup" }} +{{- $userMap := index $context.Values.endpoints ( $type | replace "-" "_" ) "auth" $userclass }} +{{- $ssMap := index $context.Values.endpoints ( $type | replace "-" "_" ) "statefulset" | default false}} +{{- $hostFqdnOverride := index $context.Values.endpoints ( $type | replace "-" "_" ) "host_fqdn_override" }} +{{- $endpointUser := index $userMap "username" }} +{{- $endpointPass := index $userMap "password" }} +{{- $endpointHostSuffix := 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" }} +{{- $local := dict "endpointCredsAndHosts" list -}} +{{- if not (or (index $hostFqdnOverride $endpoint | default ( index $hostFqdnOverride "default" ) ) ( not $ssMap ) ) }} +{{- $endpointHostPrefix := $ssMap.name }} +{{- range $podInt := until ( atoi (print $ssMap.replicas ) ) }} +{{- $endpointCredAndHost := printf "%s://%s:%s@%s-%d.%s:%s%s" $endpointScheme $endpointUser $endpointPass $endpointHostPrefix $podInt $endpointHostSuffix $endpointPort $endpointPath }} +{{- $_ := set $local "endpointCredsAndHosts" ( append $local.endpointCredsAndHosts $endpointCredAndHost ) }} +{{- end }} +{{- else }} +{{- $endpointHost := tuple $type $endpoint $context | include "helm-toolkit.endpoints.endpoint_host_lookup" }} +{{- $endpointCredAndHost := printf "%s://%s:%s@%s:%s%s" $endpointScheme $endpointUser $endpointPass $endpointHost $endpointPort $endpointPath }} +{{- $_ := set $local "endpointCredsAndHosts" ( append $local.endpointCredsAndHosts $endpointCredAndHost ) }} +{{- end }} +{{- $endpointCredsAndHosts := include "shipyard.utils.joinListWithSemicolon" $local.endpointCredsAndHosts }} +{{- printf "%s" $endpointCredsAndHosts }} +{{- end -}} diff --git a/charts/shipyard/templates/secret-user-rabbitmq.yaml b/charts/shipyard/templates/secret-user-rabbitmq.yaml index c69795d7..810b8bda 100644 --- a/charts/shipyard/templates/secret-user-rabbitmq.yaml +++ b/charts/shipyard/templates/secret-user-rabbitmq.yaml @@ -24,5 +24,5 @@ metadata: name: {{ $secretName }} type: Opaque data: - RABBITMQ_CONNECTION: {{ tuple "oslo_messaging" "internal" "user" "amqp" $envAll | include "helm-toolkit.endpoints.authenticated_endpoint_uri_lookup" | b64enc }} -{{- end }} \ No newline at end of file + RABBITMQ_CONNECTION: {{ tuple "oslo_messaging" "internal" "user" "amqp" $envAll | include "helm-toolkit.endpoints.authenticated_transport_endpoint_uri_lookup" | b64enc }} +{{- end }} diff --git a/charts/shipyard/templates/utils/_joinListWithSemicolon.tpl b/charts/shipyard/templates/utils/_joinListWithSemicolon.tpl new file mode 100644 index 00000000..97b2e482 --- /dev/null +++ b/charts/shipyard/templates/utils/_joinListWithSemicolon.tpl @@ -0,0 +1,33 @@ +{{/* +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: | + Joins a list of values into a semicolon separated string +values: | + test: + - foo + - bar +usage: | + {{ include "shipyard.utils.joinListWithSemicolon" .Values.test }} +return: | + foo;bar +*/}} + +{{- define "shipyard.utils.joinListWithSemicolon" -}} +{{- $local := dict "first" true -}} +{{- range $k, $v := . -}}{{- if not $local.first -}};{{- end -}}{{- $v -}}{{- $_ := set $local "first" false -}}{{- end -}} +{{- end -}} diff --git a/charts/shipyard/values.yaml b/charts/shipyard/values.yaml index edd87598..6cba3e0d 100644 --- a/charts/shipyard/values.yaml +++ b/charts/shipyard/values.yaml @@ -279,6 +279,9 @@ endpoints: host_fqdn_override: default: null oslo_messaging: + statefulset: + replicas: 1 + name: rabbitmq-rabbitmq auth: user: username: airflow