Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Commit

Permalink
make sync-catalog work with clients disabled (#570)
Browse files Browse the repository at this point in the history
* make sync-catalog work with clients disable

Currently the sync-catalog won't work when the clients are disable
because of the use of `HOST_IP` to connect to the service. I propose
that when clients are disable, the synccatalog falls back to the consul
server service.

When `client.enabled=true` the syncCatalog should make use of the
HOST_IP to connect with consul. When `client.enabled=false`
the syncCatalog should fall back to the consul server service.
  • Loading branch information
fbegyn committed Aug 13, 2020
1 parent 6b16630 commit 0b382a2
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
10 changes: 10 additions & 0 deletions templates/sync-catalog-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,23 @@ spec:
key: "token"
{{- end}}
{{- if .Values.global.tls.enabled }}
{{- if .Values.client.enabled }}
- name: CONSUL_HTTP_ADDR
value: https://$(HOST_IP):8501
{{- else }}
- name: CONSUL_HTTP_ADDR
value: https://{{ template "consul.fullname" . }}-server:8501
{{- end }}
- name: CONSUL_CACERT
value: /consul/tls/ca/tls.crt
{{- else }}
{{- if .Values.client.enabled }}
- name: CONSUL_HTTP_ADDR
value: http://$(HOST_IP):8500
{{- else }}
- name: CONSUL_HTTP_ADDR
value: http://{{ template "consul.fullname" . }}-server:8500
{{- end }}
{{- end }}
{{- if .Values.global.tls.enabled }}
volumeMounts:
Expand Down
69 changes: 69 additions & 0 deletions test/unit/sync-catalog-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -762,3 +762,72 @@ load _helpers
yq -rc '.spec.template.spec.containers[0].resources' | tee /dev/stderr)
[ "${actual}" = '{"limits":{"cpu":"200m","memory":"200Mi"},"requests":{"cpu":"100m","memory":"100Mi"}}' ]
}
#--------------------------------------------------------------------
# clients.enabled
@test "syncCatalog/Deployment: HOST_IP is used when client.enabled=true" {
cd `chart_dir`
local env=$(helm template \
-s templates/sync-catalog-deployment.yaml \
--set 'syncCatalog.enabled=true' \
--set 'client.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].env[]' | tee /dev/stderr)
local actual
actual=$(echo $env | jq -r '. | select(.name == "CONSUL_HTTP_ADDR") | .value' | tee /dev/stderr)
[ "${actual}" = 'http://$(HOST_IP):8500' ]
}
@test "syncCatalog/Deployment: HOST_IP is used when client.enabled=true and global.tls.enabled=true" {
cd `chart_dir`
local env=$(helm template \
-s templates/sync-catalog-deployment.yaml \
--set 'syncCatalog.enabled=true' \
--set 'global.tls.enabled=true' \
--set 'client.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].env[]' | tee /dev/stderr)
local actual
actual=$(echo $env | jq -r '. | select(.name == "CONSUL_HTTP_ADDR") | .value' | tee /dev/stderr)
[ "${actual}" = 'https://$(HOST_IP):8501' ]
actual=$(echo $env | jq -r '. | select(.name == "CONSUL_CACERT") | .value' | tee /dev/stderr)
[ "${actual}" = "/consul/tls/ca/tls.crt" ]
}
@test "syncCatalog/Deployment: consul service is used when client.enabled=false" {
cd `chart_dir`
local env=$(helm template \
-s templates/sync-catalog-deployment.yaml \
--set 'syncCatalog.enabled=true' \
--set 'client.enabled=false' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].env[]' | tee /dev/stderr)
local actual
actual=$(echo $env | jq -r '. | select(.name == "CONSUL_HTTP_ADDR") | .value' | tee /dev/stderr)
[ "${actual}" = 'http://release-name-consul-server:8500' ]
}
@test "syncCatalog/Deployment: consul service is used when client.enabled=false and global.tls.enabled=true" {
cd `chart_dir`
local env=$(helm template \
-s templates/sync-catalog-deployment.yaml \
--set 'syncCatalog.enabled=true' \
--set 'global.tls.enabled=true' \
--set 'client.enabled=false' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].env[]' | tee /dev/stderr)
local actual
actual=$(echo $env | jq -r '. | select(.name == "CONSUL_HTTP_ADDR") | .value' | tee /dev/stderr)
[ "${actual}" = 'https://release-name-consul-server:8501' ]
actual=$(echo $env | jq -r '. | select(.name == "CONSUL_CACERT") | .value' | tee /dev/stderr)
[ "${actual}" = "/consul/tls/ca/tls.crt" ]
}

0 comments on commit 0b382a2

Please sign in to comment.