Skip to content

Commit 347037a

Browse files
e2e test of gcp-provider.
1 parent 194c31d commit 347037a

File tree

2 files changed

+109
-2
lines changed

2 files changed

+109
-2
lines changed

test/bats/gcp.bats

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ PROVIDER_NAMESPACE=kube-system
1010
PROVIDER_YAML=https://raw.githubusercontent.com/GoogleCloudPlatform/secrets-store-csi-driver-provider-gcp/main/deploy/provider-gcp-plugin.yaml
1111
BASE64_FLAGS="-w 0"
1212

13-
export RESOURCE_NAME=${RESOURCE_NAME:-"projects/735463103342/secrets/test-secret-a/versions/latest"}
13+
export RESOURCE_NAME=${SECRET_URI}
1414
export FILE_NAME=${FILE_NAME:-"secret"}
15-
export SECRET_VALUE=${SECRET_VALUE:-"aHVudGVyMg=="}
1615

1716
@test "install gcp provider" {
1817
run kubectl apply -f $PROVIDER_YAML --namespace $PROVIDER_NAMESPACE
@@ -43,8 +42,21 @@ export SECRET_VALUE=${SECRET_VALUE:-"aHVudGVyMg=="}
4342
}
4443

4544
@test "CSI inline volume test with pod portability - read gcp kv secret from pod" {
45+
archive_info
4646
result=$(kubectl exec secrets-store-inline-crd --namespace=$NAMESPACE -- cat /mnt/secrets-store/$FILE_NAME)
4747
[[ "${result//$'\r'}" == "${SECRET_VALUE}" ]]
48+
49+
}
50+
51+
@test "CSI inline volume test with rotation - read gcp kv secret from pod" {
52+
echo -n "secret-b" | gcloud secrets versions add ${SECRET_ID} --data-file=-
53+
54+
# wait for secret rotation
55+
sleep 30
56+
archive_info
57+
result=$(kubectl exec secrets-store-inline-crd --namespace=$NAMESPACE -- cat /mnt/secrets-store/$FILE_NAME)
58+
[[ "${result//$'\r'}" == "secret-b" ]]
59+
4860
}
4961

5062
@test "CSI inline volume test with pod portability - unmount succeeds" {

test/scripts/run-e2e-gcp.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
: "${GOOGLE_APPLICATION_CREDENTIALS:?Environment variable empty or not defined.}"
22+
23+
function boskosctlwrapper() {
24+
boskosctl --server-url http://"${BOSKOS_HOST}" --owner-name "secret-store-provider-gcp" "${@}"
25+
}
26+
27+
cleanup() {
28+
gcloud beta secrets delete "${SECRET_ID}" --quiet
29+
# stop boskos heartbeat
30+
if [ -n "${BOSKOS_HOST:-}" ]; then
31+
boskosctlwrapper release --name "${GCP_PROJECT}" --target-state dirty
32+
fi
33+
}
34+
trap cleanup EXIT
35+
36+
37+
38+
main() {
39+
echo "starting the secret store csi driver test for gcp provider"
40+
41+
# install boskosctl
42+
if [[ -z "$(command -v boskosctl)" ]]; then
43+
echo "installing boskosctl"
44+
GO111MODULE=on go install sigs.k8s.io/boskos/cmd/boskosctl@master
45+
echo "'boskosctl' has been installed to $GOPATH/bin, make sure this directory is in your \$PATH"
46+
fi
47+
48+
echo "testing boskosctl"
49+
boskosctl --help
50+
51+
# Acquire a project from boskos pool, test will use secret created on this acquired project
52+
if [ -n "${BOSKOS_HOST:-}" ]; then
53+
echo "Boskos acquire - ${BOSKOS_HOST}"
54+
BOSKOS_RESOURCE="$( boskosctlwrapper acquire --type gce-project --state free --target-state busy --timeout 1h )"
55+
export BOSKOS_RESOURCE
56+
GCP_PROJECT=$(echo "$BOSKOS_RESOURCE" | jq -r ".name")
57+
export GCP_PROJECT
58+
59+
# send a heartbeat in the background to keep the lease while using the resource
60+
echo "Starting Boskos HeartBeat"
61+
boskosctlwrapper heartbeat --resource "${BOSKOS_RESOURCE}" &
62+
fi
63+
64+
echo "Using project ${GCP_PROJECT}"
65+
gcloud config set project "${GCP_PROJECT}"
66+
67+
# create a secret in the aquired project
68+
SECRET_ID="test-secret-$(openssl rand -hex 4)"
69+
export SECRET_ID
70+
export SECRET_VALUE="secret-a"
71+
echo -n ${SECRET_VALUE} | gcloud beta secrets create "${SECRET_ID}" --data-file=- --ttl=1800s --quiet
72+
73+
SECRET_PROJECT_ID="$(gcloud config get project)"
74+
export SECRET_PROJECT_ID
75+
SECRET_PROJECT_NUMBER="$(gcloud projects describe "$SECRET_PROJECT_ID" --format='value(projectNumber)')"
76+
export SECRET_PROJECT_NUMBER
77+
78+
export SECRET_URI="projects/${SECRET_PROJECT_NUMBER}/secrets/${SECRET_ID}/versions/latest"
79+
80+
# Prow jobs are executed by `k8s-infra-prow-build.svc.id.goog` in test-pods namespace, so grant the access to the secret
81+
gcloud secrets add-iam-policy-binding "${SECRET_ID}" \
82+
--role=roles/secretmanager.secretAccessor \
83+
--member=principalSet://iam.googleapis.com/projects/773781448124/locations/global/workloadIdentityPools/k8s-infra-prow-build.svc.id.goog/namespace/test-pods
84+
85+
# wait for permissions to propagate
86+
sleep 60
87+
88+
if [[ ${RELEASE:-} == "true" ]]; then
89+
make e2e-bootstrap e2e-helm-deploy-release e2e-gcp
90+
else
91+
make e2e-bootstrap e2e-helm-deploy e2e-gcp
92+
fi
93+
}
94+
95+
main

0 commit comments

Comments
 (0)