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 b5730b3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 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
4 changes: 3 additions & 1 deletion charts/consul/templates/api-gateway-gatewayclassconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ metadata:
component: api-gateway
spec:
consul:
{{- if .Values.externalServers.enabled }}
{{- if and .Values.externalServers.enabled (not .Values.client.enabled) }}
address: {{ first .Values.externalServers.hosts }}
{{- else if and (not .Values.externalServers.enabled) .Values.client.enabled }}
address: $(HOST_IP)
{{- else }}
address: {{ template "consul.fullname" . }}-server
{{- end }}
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
16 changes: 14 additions & 2 deletions charts/consul/test/unit/api-gateway-gatewayclassconfig.bats
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ load _helpers
#--------------------------------------------------------------------
# Consul server address

@test "apiGateway/GatewayClassConfig: Consul server address set when using external servers." {
@test "apiGateway/GatewayClassConfig: Consul server address set with external servers." {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-gatewayclassconfig.yaml \
Expand All @@ -84,7 +84,7 @@ load _helpers
[ "${actual}" = "true" ]
}

@test "apiGateway/GatewayClassConfig: Consul server address set when not using external servers." {
@test "apiGateway/GatewayClassConfig: Consul server address set with local servers and no clients." {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-gatewayclassconfig.yaml \
Expand All @@ -95,6 +95,18 @@ load _helpers
[ "${actual}" = "true" ]
}

@test "apiGateway/GatewayClassConfig: Consul server address set with local servers and clients." {
cd `chart_dir`
local actual=$(helm template \
-s templates/api-gateway-gatewayclassconfig.yaml \
--set 'apiGateway.enabled=true' \
--set 'apiGateway.image=foo' \
--set 'client.enabled=true' \
. | tee /dev/stderr |
yq '.spec.consul.address == "$(HOST_IP)"' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# externalServers ports

Expand Down

0 comments on commit b5730b3

Please sign in to comment.