Skip to content

Commit 2d42085

Browse files
authored
Update the default vault agent image to come from the hashicorp docker organization. (#567)
* Default to hashicorp/vault for vault agent image. * Add support for running acceptance tests against a kind cluster * make the injector-leader-elector a bit more reliable when run locally
1 parent f5ef752 commit 2d42085

File tree

5 files changed

+65
-7
lines changed

5 files changed

+65
-7
lines changed

Makefile

+29-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ ACCEPTANCE_TESTS?=acceptance
77
# filter bats unit tests to run.
88
UNIT_TESTS_FILTER?='.*'
99

10+
# set to 'true' to run acceptance tests locally in a kind cluster
11+
LOCAL_ACCEPTANCE_TESTS?=false
12+
13+
# kind cluster name
14+
KIND_CLUSTER_NAME?=vault-helm
15+
16+
# kind k8s version
17+
KIND_K8S_VERSION?=v1.20.2
18+
1019
# Generate json schema for chart values. See test/README.md for more details.
1120
values-schema:
1221
helm schema-gen values.yaml > values.schema.json
@@ -24,14 +33,18 @@ test: test-image test-bats
2433
# run acceptance tests on GKE
2534
# set google project/credential vars above
2635
test-acceptance:
36+
ifeq ($(LOCAL_ACCEPTANCE_TESTS),true)
37+
make setup-kind acceptance
38+
else
2739
@docker run -it -v ${PWD}:/helm-test \
2840
-e GOOGLE_CREDENTIALS=${GOOGLE_CREDENTIALS} \
2941
-e CLOUDSDK_CORE_PROJECT=${CLOUDSDK_CORE_PROJECT} \
3042
-e KUBECONFIG=/helm-test/.kube/config \
3143
-w /helm-test \
3244
$(TEST_IMAGE) \
3345
make acceptance
34-
46+
endif
47+
3548
# destroy GKE cluster using terraform
3649
test-destroy:
3750
@docker run -it -v ${PWD}:/helm-test \
@@ -54,7 +67,9 @@ test-provision:
5467
# this target is for running the acceptance tests
5568
# it is run in the docker container above when the test-acceptance target is invoked
5669
acceptance:
70+
ifneq ($(LOCAL_ACCEPTANCE_TESTS),true)
5771
gcloud auth activate-service-account --key-file=${GOOGLE_CREDENTIALS}
72+
endif
5873
bats test/${ACCEPTANCE_TESTS}
5974

6075
# this target is for provisioning the GKE cluster
@@ -69,4 +84,17 @@ provision-cluster:
6984
destroy-cluster:
7085
terraform destroy -auto-approve
7186

87+
# create a kind cluster for running the acceptance tests locally
88+
setup-kind:
89+
kind get clusters | grep -q "^${KIND_CLUSTER_NAME}$$" || \
90+
kind create cluster \
91+
--image kindest/node:${KIND_K8S_VERSION} \
92+
--name ${KIND_CLUSTER_NAME} \
93+
--config $(CURDIR)/test/kind/config.yaml
94+
kubectl config use-context kind-${KIND_CLUSTER_NAME}
95+
96+
# delete the kind cluster
97+
delete-kind:
98+
kind delete cluster --name ${KIND_CLUSTER_NAME} || :
99+
72100
.PHONY: values-schema test-image test-unit test-bats test test-acceptance test-destroy test-provision acceptance provision-cluster destroy-cluster

test/README.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,27 @@
22

33
## Running Vault Helm Acceptance tests
44

5-
The Makefile at the top level of this repo contains a few target that should help with running acceptance tests in your own GKE instance.
5+
The Makefile at the top level of this repo contains a few target that should help with running acceptance tests in your own GKE instance or in a kind cluster.
66

7-
* Set the GOOGLE_CREDENTIALS and CLOUDSDK_CORE_PROJECT variables at the top of the file. GOOGLE_CREDENTIALS should contain the local path to your Google Cloud Platform account credentials in JSON format. CLOUDSDK_CORE_PROJECT should be set to the ID of your GCP project.
7+
### Running in a GKE cluster
8+
9+
* Set the `GOOGLE_CREDENTIALS` and `CLOUDSDK_CORE_PROJECT` variables at the top of the file. `GOOGLE_CREDENTIALS` should contain the local path to your Google Cloud Platform account credentials in JSON format. `CLOUDSDK_CORE_PROJECT` should be set to the ID of your GCP project.
810
* Run `make test-image` to create the docker image (with dependencies installed) that will be re-used in the below steps.
911
* Run `make test-provision` to provision the GKE cluster using terraform.
1012
* Run `make test-acceptance` to run the acceptance tests in this already provisioned cluster.
1113
* You can choose to only run certain tests by setting the ACCEPTANCE_TESTS variable and re-running the above target.
1214
* Run `make test-destroy` when you have finished testing and want to tear-down and remove the cluster.
1315

16+
### Running in a kind cluster
17+
18+
* Run `make test-acceptance LOCAL_ACCEPTANCE_TESTS=true`
19+
* You can choose to only run certain tests by setting the `ACCEPTANCE_TESTS` variable and re-running the above target.
20+
* Run `make delete-kind` when you have finished testing and want to tear-down and remove the cluster.
21+
* You can set an alternate kind cluster name by specifying the `KIND_CLUSTER_NAME` variable for any of the above targets.
22+
* You can set an alternate K8S version by specifying the `KIND_K8S_VERSION` variable for any of the above targets.
23+
24+
See [kind-quick-start](https://kind.sigs.k8s.io/docs/user/quick-start/) if you don't have kind installed on your system.
25+
1426
## Running chart verification tests
1527

1628
If [chart-verifier](https://github.com/redhat-certification/chart-verifier) is built and available in your PATH, run:

test/acceptance/injector-leader-elector.bats

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,30 @@ load _helpers
44

55
@test "injector: testing leader elector" {
66
cd `chart_dir`
7-
7+
88
kubectl delete namespace acceptance --ignore-not-found=true
99
kubectl create namespace acceptance
1010
kubectl config set-context --current --namespace=acceptance
1111

1212
helm install "$(name_prefix)" \
13+
--wait \
14+
--timeout=5m \
1315
--set="injector.replicas=3" .
1416
kubectl wait --for condition=Ready pod -l app.kubernetes.io/name=vault-agent-injector --timeout=5m
1517

1618
pods=($(kubectl get pods -l app.kubernetes.io/name=vault-agent-injector -o json | jq -r '.items[] | .metadata.name'))
1719
[ "${#pods[@]}" == 3 ]
1820

19-
leader="$(echo "$(kubectl exec ${pods[0]} -c sidecar-injector -- wget --quiet --output-document - localhost:4040)" | jq -r .name)"
21+
leader=''
22+
tries=0
23+
until [ $tries -ge 60 ]
24+
do
25+
leader="$(echo "$(kubectl exec ${pods[0]} -c sidecar-injector -- wget --quiet --output-document - localhost:4040)" | jq -r .name)"
26+
[ -n "${leader}" ] && break
27+
((tries++))
28+
sleep .5
29+
done
30+
2031
# Check the leader name is valid - i.e. one of the 3 pods
2132
[[ " ${pods[@]} " =~ " ${leader} " ]]
2233

test/kind/config.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
nodes:
4+
- role: control-plane
5+
- role: worker
6+
- role: worker
7+
- role: worker

values.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ injector:
5959
# containers. This should be set to the official Vault image. Vault 1.3.1+ is
6060
# required.
6161
agentImage:
62-
repository: "vault"
62+
repository: "hashicorp/vault"
6363
tag: "1.7.3"
6464

6565
# The default values for the injected Vault Agent containers.
@@ -218,7 +218,7 @@ server:
218218
# By default no direct resource request is made.
219219

220220
image:
221-
repository: "vault"
221+
repository: "hashicorp/vault"
222222
tag: "1.7.3"
223223
# Overrides the default Image Pull Policy
224224
pullPolicy: IfNotPresent

0 commit comments

Comments
 (0)