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
This commit is contained in:
Evgeny L 2019-07-18 21:25:49 +00:00 committed by Evgeniy L
parent fed3407634
commit c21555fce0
5 changed files with 162 additions and 3 deletions

View File

@ -35,7 +35,7 @@
# Add endpoint URI lookup for RabbitMQ Connection # Add endpoint URI lookup for RabbitMQ Connection
{{- if empty .Values.conf.airflow.celery.broker_url -}} {{- 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 -}} {{- end -}}
--- ---

View File

@ -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 -}}

View File

@ -24,5 +24,5 @@ metadata:
name: {{ $secretName }} name: {{ $secretName }}
type: Opaque type: Opaque
data: data:
RABBITMQ_CONNECTION: {{ tuple "oslo_messaging" "internal" "user" "amqp" $envAll | include "helm-toolkit.endpoints.authenticated_endpoint_uri_lookup" | b64enc }} RABBITMQ_CONNECTION: {{ tuple "oslo_messaging" "internal" "user" "amqp" $envAll | include "helm-toolkit.endpoints.authenticated_transport_endpoint_uri_lookup" | b64enc }}
{{- end }} {{- end }}

View File

@ -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 -}}

View File

@ -279,6 +279,9 @@ endpoints:
host_fqdn_override: host_fqdn_override:
default: null default: null
oslo_messaging: oslo_messaging:
statefulset:
replicas: 1
name: rabbitmq-rabbitmq
auth: auth:
user: user:
username: airflow username: airflow