From d5cd4febaa589f8987172f710949f5476eb16c44 Mon Sep 17 00:00:00 2001 From: hc-github-team-consul-core Date: Tue, 16 Apr 2024 09:46:07 -0700 Subject: [PATCH] Backport of Helm: support sync-lb-services-endpoints for sync catalog into release/1.4.x (#3913) * backport of commit dd794d3d395e948185373de7e7b23e5485f52c3e * backport of commit eddf3309bc8b36bcf6bc768fd585f3f24554fe9d * backport of commit 72736841b98ed6d48e966a68ffd070c0951a93be --------- Co-authored-by: jukie <10012479+Jukie@users.noreply.github.com> Co-authored-by: Michael Zalimeni --- .changelog/3905.txt | 3 +++ .../templates/sync-catalog-deployment.yaml | 3 +++ .../test/unit/sync-catalog-deployment.bats | 23 +++++++++++++++++++ charts/consul/values.yaml | 4 ++++ 4 files changed, 33 insertions(+) create mode 100644 .changelog/3905.txt diff --git a/.changelog/3905.txt b/.changelog/3905.txt new file mode 100644 index 0000000000..f5aec57cb1 --- /dev/null +++ b/.changelog/3905.txt @@ -0,0 +1,3 @@ +```release-note:improvement +helm: support sync-lb-services-endpoints flag for syncCatalog +``` \ No newline at end of file diff --git a/charts/consul/templates/sync-catalog-deployment.yaml b/charts/consul/templates/sync-catalog-deployment.yaml index 8bd3e0af61..3851f0a8e2 100644 --- a/charts/consul/templates/sync-catalog-deployment.yaml +++ b/charts/consul/templates/sync-catalog-deployment.yaml @@ -192,6 +192,9 @@ spec: -loadBalancer-ips=true \ {{- end }} {{- end }} + {{- if .Values.syncCatalog.syncLoadBalancerEndpoints }} + -sync-lb-services-endpoints=true \ + {{- end }} livenessProbe: httpGet: path: /health/ready diff --git a/charts/consul/test/unit/sync-catalog-deployment.bats b/charts/consul/test/unit/sync-catalog-deployment.bats index 0c9579df20..b60b030ac0 100755 --- a/charts/consul/test/unit/sync-catalog-deployment.bats +++ b/charts/consul/test/unit/sync-catalog-deployment.bats @@ -413,6 +413,29 @@ load _helpers [ "${actual}" = "true" ] } +#-------------------------------------------------------------------- +# syncLoadBalancerEndpoints + +@test "syncCatalog/Deployment: enable LB endpoints sync flag not passed when disabled" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/sync-catalog-deployment.yaml \ + --set 'syncCatalog.enabled=true' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].command | any(contains("-sync-lb-services-endpoints=true"))' | tee /dev/stderr) + [ "${actual}" = "false" ] +} +@test "syncCatalog/Deployment: enable LB endpoints sync flag passed when enabled" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/sync-catalog-deployment.yaml \ + --set 'syncCatalog.enabled=true' \ + --set 'syncCatalog.syncLoadBalancerEndpoints=true' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].command | any(contains("-sync-lb-services-endpoints=true"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + #-------------------------------------------------------------------- # affinity diff --git a/charts/consul/values.yaml b/charts/consul/values.yaml index a3f5e2b2e6..a95b79822a 100644 --- a/charts/consul/values.yaml +++ b/charts/consul/values.yaml @@ -2193,6 +2193,10 @@ syncCatalog: # Set this to false to skip syncing ClusterIP services. syncClusterIPServices: true + # If true, LoadBalancer service endpoints instead of ingress addresses will be synced to Consul. + # If false, LoadBalancer endpoints are not synced to Consul. + syncLoadBalancerEndpoints: false + ingress: # Syncs the hostname from a Kubernetes Ingress resource to service registrations # when a rule matched a service. Currently only supports host based routing and