Skip to content

Commit

Permalink
support static addrs
Browse files Browse the repository at this point in the history
  • Loading branch information
ndhanushkodi committed Aug 1, 2022
1 parent c1dcf43 commit cab492f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
5 changes: 5 additions & 0 deletions charts/consul/templates/connect-inject-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- if (eq .Values.global.peering.tokenGeneration.serverAddresses.source "static") }}
{{- range $addr := .Values.global.peering.tokenGeneration.serverAddresses.static }}
-server-address="{{ $addr }}" \
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.global.openshift.enabled }}
-enable-openshift \
Expand Down
42 changes: 42 additions & 0 deletions charts/consul/test/unit/connect-inject-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,48 @@ EOF
[ "${actual}" = "true" ]
}

@test "connectInject/Deployment: when peering token generation source is static passes in -server-address flags with static addresses" {
cd `chart_dir`
local command=$(helm template \
-s templates/connect-inject-deployment.yaml \
--set 'global.peering.tokenGeneration.serverAddresses.source=static' \
--set 'global.peering.tokenGeneration.serverAddresses.static[0]=1.2.3.4:1234' \
--set 'global.peering.tokenGeneration.serverAddresses.static[1]=2.2.3.4:2234' \
--set 'connectInject.enabled=true' \
--set 'global.peering.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command')

local actual=$(echo $command | jq -r ' . | any(contains("-server-address=\"1.2.3.4:1234\""))' | tee /dev/stderr)
[ "${actual}" = "true" ]

local actual=$(echo $command | jq -r ' . | any(contains("-server-address=\"2.2.3.4:2234\""))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "connectInject/Deployment: when peering token generation source is static and externalHosts are set, passes in -server-address flags with static addresses, not externalServers.hosts" {
cd `chart_dir`
local command=$(helm template \
-s templates/connect-inject-deployment.yaml \
--set 'server.enabled=false' \
--set 'global.peering.tokenGeneration.serverAddresses.source=static' \
--set 'global.peering.tokenGeneration.serverAddresses.static[0]=1.2.3.4:1234' \
--set 'global.peering.tokenGeneration.serverAddresses.static[1]=2.2.3.4:2234' \
--set 'externalServers.enabled=true' \
--set 'externalServers.hosts[0]=1.1.1.1' \
--set 'externalServers.hosts[1]=2.2.2.2' \
--set 'connectInject.enabled=true' \
--set 'global.peering.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command')

local actual=$(echo $command | jq -r ' . | any(contains("-server-address=\"1.2.3.4:1234\""))' | tee /dev/stderr)
[ "${actual}" = "true" ]

local actual=$(echo $command | jq -r ' . | any(contains("-server-address=\"2.2.3.4:2234\""))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# openshift

Expand Down
8 changes: 6 additions & 2 deletions charts/consul/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ global:
enabled: false
tokenGeneration:
serverAddresses:
# Source can be set to "" or "consul".
# Source can be set to "","consul" or "static".
#
# "" is the default source. If servers are enabled, it will check if server.exposeService is enabled, and read
# "" is the default source. If servers are enabled, it will check if `server.exposeService` is enabled, and read
# the addresses from that service to use as the peering token server addresses.
#
# "consul" will use the Consul advertise addresses in the peering token.
#
# "static" will use the addresses specified in `global.peering.tokenGeneration.serverAddresses.static`.
source: ""
# Static addresses must be formatted "hostname|ip:port".
static: []

# [Enterprise Only] Enabling `adminPartitions` allows creation of Admin Partitions in Kubernetes clusters.
# It additionally indicates that you are running Consul Enterprise v1.11+ with a valid Consul Enterprise
Expand Down

0 comments on commit cab492f

Please sign in to comment.