Skip to content

Commit

Permalink
Handle connecting to clients when they are present
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Eckert committed Nov 10, 2022
1 parent 630e1e1 commit f8e1898
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,19 @@ spec:
value: "/consul/login/acl-token"
{{- end }}
- name: CONSUL_HTTP_ADDR
{{- if .Values.externalServers.enabled }}
{{- if and .Values.externalServers.enabled (not .Values.client.enabled) }}
{{- if .Values.global.tls.enabled }}
value: {{ first .Values.externalServers.hosts }}:{{ .Values.externalServers.httpsPort }}
{{- else }}
value: {{ first .Values.externalServers.hosts }}:{{ .Values.externalServers.httpPort }}
{{- end }}
{{- else if and (not .Values.externalServers.enabled) .Values.client.enabled }}
{{- if .Values.global.tls.enabled }}
value: $(HOST_IP):8501
{{- else }}
value: $(HOST_IP):8500
{{- end }}
{{- else }} # Internal servers, no clients
{{- if .Values.global.tls.enabled }}
value: {{ template "consul.fullname" . }}-server:8501
{{- else }}
Expand Down
38 changes: 34 additions & 4 deletions charts/consul/test/unit/api-gateway-controller-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ load _helpers
#--------------------------------------------------------------------
# CONSUL_HTTP_ADDR

@test "apiGateway/Deployment: CONSUL_HTTP_ADDR set correctly when using external servers and TLS." {
@test "apiGateway/Deployment: CONSUL_HTTP_ADDR set correctly with external servers, TLS, and no clients." {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-controller-deployment.yaml \
Expand All @@ -1173,12 +1173,13 @@ load _helpers
--set 'externalServers.hosts[0]=external-consul.host' \
--set 'externalServers.httpsPort=8501' \
--set 'server.enabled=false' \
--set 'client.enabled=false' \
. | tee /dev/stderr |
yq '[.spec.template.spec.containers[0].env[2].value] | any(contains("external-consul.host:8501"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "apiGateway/Deployment: CONSUL_HTTP_ADDR set correctly when using external servers and no-TLS." {
@test "apiGateway/Deployment: CONSUL_HTTP_ADDR set correctly with external servers, no TLS, and no clients" {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-controller-deployment.yaml \
Expand All @@ -1189,30 +1190,59 @@ load _helpers
--set 'externalServers.hosts[0]=external-consul.host' \
--set 'externalServers.httpPort=8500' \
--set 'server.enabled=false' \
--set 'client.enabled=false' \
. | tee /dev/stderr |
yq '[.spec.template.spec.containers[0].env[1].value] | any(contains("external-consul.host:8500"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "apiGateway/Deployment: CONSUL_HTTP_ADDR set correctly when not using external servers and using TLS." {
@test "apiGateway/Deployment: CONSUL_HTTP_ADDR set correctly with local servers, TLS, and clients" {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-controller-deployment.yaml \
--set 'apiGateway.enabled=true' \
--set 'apiGateway.image=bar' \
--set 'global.tls.enabled=true' \
--set 'client.enabled=true' \
. | tee /dev/stderr |
yq '[.spec.template.spec.containers[0].env[2].value] | any(contains("$(HOST_IP):8501"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "apiGateway/Deployment: CONSUL_HTTP_ADDR set correctly with local servers, no TLS, and clients" {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-controller-deployment.yaml \
--set 'apiGateway.enabled=true' \
--set 'apiGateway.image=bar' \
--set 'global.tls.enabled=false' \
--set 'client.enabled=true' \
. | tee /dev/stderr |
yq '[.spec.template.spec.containers[0].env[1].value] | any(contains("$(HOST_IP):8500"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "apiGateway/Deployment: CONSUL_HTTP_ADDR set correctly with local servers, TLS, and no clients" {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-controller-deployment.yaml \
--set 'apiGateway.enabled=true' \
--set 'apiGateway.image=bar' \
--set 'global.tls.enabled=true' \
--set 'client.enabled=false' \
. | tee /dev/stderr |
yq '[.spec.template.spec.containers[0].env[2].value] | any(contains("release-name-consul-server:8501"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "apiGateway/Deployment: CONSUL_HTTP_ADDR set correctly when not using external servers or TLS." {
@test "apiGateway/Deployment: CONSUL_HTTP_ADDR set correctly with local servers, no TLS, and no clients" {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-controller-deployment.yaml \
--set 'apiGateway.enabled=true' \
--set 'apiGateway.image=bar' \
--set 'global.tls.enabled=false' \
--set 'client.enabled=false' \
. | tee /dev/stderr |
yq '[.spec.template.spec.containers[0].env[1].value] | any(contains("release-name-consul-server:8500"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
Expand Down

0 comments on commit f8e1898

Please sign in to comment.