From 4b2d606f1d5826599775a079c995b09feae36507 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 13 Sep 2024 06:47:39 +0000 Subject: [PATCH] Add ability to get multiple hosts endpoint For memcache we should set specify all hosts directly in the config as client do key spreading based on what hosts are alive, when LB address is used memcached can't work effectively. This patch updates endpoint_host_lookup to handle this scenario Change-Id: I8c70f8e9e82bf18d04499a132ef9a016d02cea31 --- helm-toolkit/Chart.yaml | 2 +- .../_host_and_port_endpoint_uri_lookup.tpl | 38 +++++++++++++++++-- releasenotes/notes/helm-toolkit.yaml | 1 + 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/helm-toolkit/Chart.yaml b/helm-toolkit/Chart.yaml index e55b2a585..f2ae8a0fa 100644 --- a/helm-toolkit/Chart.yaml +++ b/helm-toolkit/Chart.yaml @@ -15,7 +15,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Helm-Toolkit name: helm-toolkit -version: 0.2.72 +version: 0.2.73 home: https://docs.openstack.org/openstack-helm icon: https://www.openstack.org/themes/openstack/images/project-mascots/OpenStack-Helm/OpenStack_Project_OpenStackHelm_vertical.png sources: 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 6877b7bfb..728b99435 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 @@ -14,7 +14,8 @@ limitations under the License. {{/* abstract: | - Resolves 'hostname:port' for an endpoint + Resolves 'hostname:port' for an endpoint, or several hostname:port pairs for statefulset e.g + 'hostname1:port1,hostname2:port2,hostname3:port3', examples: - values: | endpoints: @@ -46,6 +47,23 @@ examples: {{ tuple "oslo_db" "internal" "mysql" . | include "helm-toolkit.endpoints.host_and_port_endpoint_uri_lookup" }} return: | 127.0.0.1:3306 + - values: | + endpoints: + oslo_cache: + hosts: + default: memcached + host_fqdn_override: + default: null + statefulset: + name: openstack-memcached-memcached + replicas: 3 + port: + memcache: + default: 11211 + usage: | + {{ tuple "oslo_cache" "internal" "memcache" . | include "helm-toolkit.endpoints.host_and_port_endpoint_uri_lookup" }} + return: | + openstack-memcached-memcached-0:11211,openstack-memcached-memcached-1:11211,openstack-memcached-memcached-2:11211 */}} {{- define "helm-toolkit.endpoints.host_and_port_endpoint_uri_lookup" -}} @@ -53,7 +71,19 @@ examples: {{- $endpoint := index . 1 -}} {{- $port := index . 2 -}} {{- $context := index . 3 -}} -{{- $endpointPort := tuple $type $endpoint $port $context | include "helm-toolkit.endpoints.endpoint_port_lookup" }} -{{- $endpointHostname := tuple $type $endpoint $context | include "helm-toolkit.endpoints.endpoint_host_lookup" }} -{{- printf "%s:%s" $endpointHostname $endpointPort -}} +{{- $ssMap := index $context.Values.endpoints ( $type | replace "-" "_" ) "statefulset" | default false -}} +{{- $local := dict "endpointHosts" list -}} +{{- $endpointPort := tuple $type $endpoint $port $context | include "helm-toolkit.endpoints.endpoint_port_lookup" -}} +{{- if $ssMap -}} +{{- $endpointHostPrefix := $ssMap.name -}} +{{- $endpointHostSuffix := tuple $type $endpoint $context | include "helm-toolkit.endpoints.endpoint_host_lookup" }} +{{- range $podInt := until ( atoi (print $ssMap.replicas ) ) -}} +{{- $endpointHostname := printf "%s-%d.%s:%s" $endpointHostPrefix $podInt $endpointHostSuffix $endpointPort -}} +{{- $_ := set $local "endpointHosts" ( append $local.endpointHosts $endpointHostname ) -}} +{{- end -}} +{{- else -}} +{{- $endpointHostname := tuple $type $endpoint $context | include "helm-toolkit.endpoints.endpoint_host_lookup" -}} +{{- $_ := set $local "endpointHosts" ( append $local.endpointHosts (printf "%s:%s" $endpointHostname $endpointPort) ) -}} +{{- end -}} +{{ include "helm-toolkit.utils.joinListWithComma" $local.endpointHosts }} {{- end -}} diff --git a/releasenotes/notes/helm-toolkit.yaml b/releasenotes/notes/helm-toolkit.yaml index 9e9929909..ffbc0f3b1 100644 --- a/releasenotes/notes/helm-toolkit.yaml +++ b/releasenotes/notes/helm-toolkit.yaml @@ -79,4 +79,5 @@ helm-toolkit: - 0.2.70 Decode url-encoded password for rabbit connection - 0.2.71 Add snippet with service parameters - 0.2.72 Add snippet configmap_oslo_policy + - 0.2.73 Add ability to get multiple hosts endpoint ...