Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.
3 changes: 1 addition & 2 deletions .buildkite/integration-restricted-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ export DEPLOY_SOURCEGRAPH_ROOT=$(pwd)
export TEST_GCP_PROJECT=sourcegraph-server
export TEST_GCP_ZONE=us-central1-a
export TEST_GCP_USERNAME=buildkite@sourcegraph-dev.iam.gserviceaccount.com
export BUILD_CREATOR=${BUILDKITE_BUILD_CREATOR_EMAIL//[@.]/-}
export BUILD_CREATOR=`echo ${BUILDKITE_BUILD_CREATOR} | tr '[:upper:]' '[:lower:]' | sed -e 's/[[:blank:]]//g'`
export BUILD_UUID=$BUILDKITE_BUILD_ID
export BUILD_BRANCH=${BUILDKITE_BRANCH//./-}

${DEPLOY_SOURCEGRAPH_ROOT}/tests/integration/restricted/test.sh

23 changes: 19 additions & 4 deletions tests/integration/restricted/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ CLUSTER_NAME_SUFFIX=`echo ${BUILD_UUID} | head -c 8`

CLUSTER_NAME="ds-test-restricted-${CLUSTER_NAME_SUFFIX}"

function finish {
gcloud container clusters delete ${CLUSTER_NAME} --zone ${TEST_GCP_ZONE} --project ${TEST_GCP_PROJECT} --quiet
}
trap finish EXIT

cd $(dirname "${BASH_SOURCE[0]}")

# set up the cluster, set up the fake user and restricted policy and then deploy the non-privileged overlay as that user
Expand All @@ -32,7 +37,7 @@ kubectl create rolebinding -n ns-sourcegraph fake-user:nonroot:unprivileged --ro

kubectl --as=system:serviceaccount:ns-sourcegraph:fake-user -n ns-sourcegraph apply -k ${DEPLOY_SOURCEGRAPH_ROOT}/overlays/non-privileged-create-cluster

kubectl -n ns-sourcegraph expose deployment sourcegraph-frontend --type=NodePort --name sourcegraph --type=LoadBalancer
kubectl -n ns-sourcegraph expose deployment sourcegraph-frontend --type=NodePort --name sourcegraph --type=LoadBalancer --port=3080 --target-port=3080

# wait for it all to finish (we list out the ones with persistent volume claim because they take longer)

Expand All @@ -48,9 +53,19 @@ kubectl -n ns-sourcegraph rollout status -w deployment/sourcegraph-frontend

SOURCEGRAPH_IP=`kubectl -n ns-sourcegraph describe service sourcegraph | grep "LoadBalancer Ingress:" | cut -d ":" -f 2 | tr -d " "`

curl -m 60 http://${SOURCEGRAPH_IP}:3080
attempt_counter=0
max_attempts=6

# delete cluster
status_code=$(curl -o /dev/null -s -w "%{http_code}\n" http://${SOURCEGRAPH_IP}:3080)

gcloud container clusters delete ${CLUSTER_NAME} --zone ${TEST_GCP_ZONE} --project ${TEST_GCP_PROJECT} --quiet
while [ ${status_code} -ge 400 ]
do
if [ ${attempt_counter} -eq ${max_attempts} ];then
echo "Max attempts reached"
exit 1
fi

status_code=$(curl -o /dev/null -s -w "%{http_code}\n" http://${SOURCEGRAPH_IP}:3080)
attempt_counter=$(($attempt_counter+1))
sleep 10
done