Skip to content

Commit

Permalink
Fix for acceptance tests (#2937) (#2945)
Browse files Browse the repository at this point in the history
* Fix for acceptance tests

* fix accpetance test

* fix spaces

* fix get

* added bats test

* fix test name

* fix bats
  • Loading branch information
absolutelightning authored Sep 12, 2023
1 parent b6dadfc commit 75dabae
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions charts/consul/templates/ingress-gateways-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ spec:
{{- if $root.Values.global.secretsBackend.vault.agentAnnotations }}
{{ tpl $root.Values.global.secretsBackend.vault.agentAnnotations $root | nindent 8 | trim }}
{{- end }}
{{- if (and ($root.Values.global.secretsBackend.vault.vaultNamespace) (not (hasKey (default "" $root.Values.global.secretsBackend.vault.agentAnnotations | fromYaml) "vault.hashicorp.com/namespace")))}}
"vault.hashicorp.com/namespace": "{{ $root.Values.global.secretsBackend.vault.vaultNamespace }}"
{{- end }}
{{- end }}
{{- if (and $root.Values.global.metrics.enabled $root.Values.global.metrics.enableGatewayMetrics) }}
"prometheus.io/scrape": "true"
Expand Down
5 changes: 4 additions & 1 deletion charts/consul/templates/server-acl-init-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ spec:
fieldPath: metadata.name
# Extract the Vault namespace from the Vault agent annotations.
{{- if .Values.global.secretsBackend.vault.enabled }}
{{- if .Values.global.secretsBackend.vault.agentAnnotations }}
{{- if and (.Values.global.secretsBackend.vault.agentAnnotations) (hasKey (default "" .Values.global.secretsBackend.vault.agentAnnotations | fromYaml) "vault.hashicorp.com/namespace") }}
- name: VAULT_NAMESPACE
value: {{ get (tpl .Values.global.secretsBackend.vault.agentAnnotations . | fromYaml) "vault.hashicorp.com/namespace" }}
{{- else if .Values.global.secretsBackend.vault.vaultNamespace }}
- name: VAULT_NAMESPACE
value: {{ .Values.global.secretsBackend.vault.vaultNamespace }}
{{- end }}
{{- end }}
{{- include "consul.consulK8sConsulServerEnvVars" . | nindent 8 }}
Expand Down
3 changes: 3 additions & 0 deletions charts/consul/templates/terminating-gateways-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ spec:
{{- if $root.Values.global.secretsBackend.vault.agentAnnotations }}
{{ tpl $root.Values.global.secretsBackend.vault.agentAnnotations $root | nindent 8 | trim }}
{{- end }}
{{- if (and ($root.Values.global.secretsBackend.vault.vaultNamespace) (not (hasKey (default "" $root.Values.global.secretsBackend.vault.agentAnnotations | fromYaml) "vault.hashicorp.com/namespace")))}}
"vault.hashicorp.com/namespace": "{{ $root.Values.global.secretsBackend.vault.vaultNamespace }}"
{{- end }}
{{- end }}
{{- if (and $root.Values.global.metrics.enabled $root.Values.global.metrics.enableGatewayMetrics) }}
"prometheus.io/scrape": "true"
Expand Down
19 changes: 19 additions & 0 deletions charts/consul/test/unit/ingress-gateways-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,25 @@ key2: value2' \
[ "${actual}" = "bar" ]
}

@test "ingressGateway/Deployment: vault namespace annotations can be set when secretsBackend.vault.vaultNamespace is set and .global.secretsBackend.vault.agentAnnotations is not set." {
cd `chart_dir`
local object=$(helm template \
-s templates/ingress-gateways-deployment.yaml \
--set 'ingressGateways.enabled=true' \
--set 'connectInject.enabled=true' \
--set 'global.tls.enabled=true' \
--set 'global.secretsBackend.vault.enabled=true' \
--set 'global.secretsBackend.vault.consulClientRole=test' \
--set 'global.secretsBackend.vault.consulServerRole=foo' \
--set 'global.tls.caCert.secretName=foo' \
--set 'global.secretsBackend.vault.consulCARole=carole' \
--set 'global.secretsBackend.vault.vaultNamespace=vns' \
. | tee /dev/stderr |
yq -r '.spec.template' | tee /dev/stderr)
local actual=$(echo $object | yq -r '.metadata.annotations."vault.hashicorp.com/namespace"')
[ "${actual}" = "vns" ]
}

#--------------------------------------------------------------------
# terminationGracePeriodSeconds

Expand Down
19 changes: 19 additions & 0 deletions charts/consul/test/unit/terminating-gateways-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,25 @@ key2: value2' \
[ "${actual}" = "bar" ]
}

@test "terminatingGateways/Deployment: vault namespace annotations can be set when secretsBackend.vault.vaultNamespace is set and .global.secretsBackend.vault.agentAnnotations is not set." {
cd `chart_dir`
local object=$(helm template \
-s templates/terminating-gateways-deployment.yaml \
--set 'terminatingGateways.enabled=true' \
--set 'connectInject.enabled=true' \
--set 'global.tls.enabled=true' \
--set 'global.secretsBackend.vault.enabled=true' \
--set 'global.secretsBackend.vault.consulClientRole=test' \
--set 'global.secretsBackend.vault.consulServerRole=foo' \
--set 'global.tls.caCert.secretName=foo' \
--set 'global.secretsBackend.vault.consulCARole=carole' \
--set 'global.secretsBackend.vault.vaultNamespace=vns' \
. | tee /dev/stderr |
yq -r '.spec.template' | tee /dev/stderr)
local actual=$(echo $object | yq -r '.metadata.annotations."vault.hashicorp.com/namespace"')
[ "${actual}" = "vns" ]
}

#--------------------------------------------------------------------
# global.cloud

Expand Down

0 comments on commit 75dabae

Please sign in to comment.