Skip to content

Commit

Permalink
Revert "Revert "Provide server stateful set DNS names to the ACL init…
Browse files Browse the repository at this point in the history
… job (hashicorp#401)" (hashicorp#424)"

This reverts commit 409f95b.
  • Loading branch information
ishustava committed Apr 16, 2020
1 parent 409f95b commit f89be18
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
9 changes: 6 additions & 3 deletions templates/server-acl-init-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,18 @@ spec:
- "/bin/sh"
- "-ec"
- |
CONSUL_FULLNAME="{{template "consul.fullname" . }}"
consul-k8s server-acl-init \
-server-label-selector=component=server,app={{ template "consul.name" . }},release={{ .Release.Name }} \
{{- range $index := until (.Values.server.replicas | int) }}
-server-address="${CONSUL_FULLNAME}-server-{{ $index }}.${CONSUL_FULLNAME}-server.${NAMESPACE}.svc" \
{{- end }}
-resource-prefix={{ template "consul.fullname" . }} \
-k8s-namespace={{ .Release.Namespace }} \
{{- if .Values.global.tls.enabled }}
-use-https \
-consul-ca-cert=/consul/tls/ca/tls.crt \
-consul-tls-server-name=server.{{ .Values.global.datacenter }}.{{ .Values.global.domain }} \
-server-port=8501 \
{{- end }}
{{- if .Values.syncCatalog.enabled }}
-create-sync-token=true \
Expand Down Expand Up @@ -147,7 +151,6 @@ spec:
{{- end }}
{{- end }}
{{- end }}
-expected-replicas={{ .Values.server.replicas }}
{{- end }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion test/unit/helpers.bats
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ load _helpers
cd `chart_dir`
# Grep for uses of .Release.Name that aren't using it as a label.
local actual=$(grep -r '{{ .Release.Name }}' templates/*.yaml | grep -v 'release: ' | tee /dev/stderr )
[ "${actual}" = 'templates/server-acl-init-job.yaml: -server-label-selector=component=server,app={{ template "consul.name" . }},release={{ .Release.Name }} \' ]
[ "${actual}" = '' ]
}

#--------------------------------------------------------------------
Expand Down
23 changes: 21 additions & 2 deletions test/unit/server-acl-init-job.bats
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ load _helpers
[ "${actual}" = "true" ]
}

@test "serverACLInit/Job: server address is set to the DNS names of the server stateful set" {
cd `chart_dir`
local command=$(helm template \
-x templates/server-acl-init-job.yaml \
--set 'global.acls.manageSystemACLs=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command' | tee /dev/stderr)

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

actual=$(echo $command | jq -r '. | any(contains("-server-address=\"${CONSUL_FULLNAME}-server-1.${CONSUL_FULLNAME}-server.${NAMESPACE}.svc\""))' | tee /dev/stderr)
[ "${actual}" = "true" ]

actual=$(echo $command | jq -r '. | any(contains("-server-address=\"${CONSUL_FULLNAME}-server-2.${CONSUL_FULLNAME}-server.${NAMESPACE}.svc\""))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# dns

Expand Down Expand Up @@ -230,8 +249,8 @@ load _helpers
actual=$(echo $command | jq -r '. | any(contains("-consul-ca-cert=/consul/tls/ca/tls.crt"))' | tee /dev/stderr)
[ "${actual}" = "true" ]

actual=$(echo $command | jq -r '. | any(contains("-consul-tls-server-name=server.dc1.consul"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
actual=$(echo $command | jq -r '. | any(contains("-server-port=8501"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "serverACLInit/Job: can overwrite CA secret with the provided one" {
Expand Down
2 changes: 1 addition & 1 deletion values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ global:

# If true, the Helm chart will automatically manage ACL tokens and policies
# for all Consul and consul-k8s components. This requires servers to be running inside Kubernetes.
# Additionally, requires Consul >= 1.4 and consul-k8s >= 0.10.1.
# Additionally, requires Consul >= 1.4 and consul-k8s >= 0.14.0.
manageSystemACLs: false

# If true, an ACL token will be created that can be used in secondary
Expand Down

0 comments on commit f89be18

Please sign in to comment.