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
This commit is contained in:
root 2024-09-13 06:47:39 +00:00 committed by Vasyl Saienko
parent ef54c62fd4
commit 4b2d606f1d
3 changed files with 36 additions and 5 deletions

View File

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

View File

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

View File

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