Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Fix authentication for test clusters
Browse files Browse the repository at this point in the history
Instead of relying on default options, use basic authentication for test cluster.

Also make `acquire_cluster_admin_role()` handle auth through certificates, since it's used also on deployment.

Backport of knative/test-infra#115.
  • Loading branch information
adrcunha committed Oct 11, 2018
1 parent 791a91d commit ddf8152
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ if [[ -z $1 ]]; then
header "Creating test cluster"
# Smallest cluster required to run the end-to-end-tests
CLUSTER_CREATION_ARGS=(
--gke-create-args="--enable-autoscaling --min-nodes=1 --max-nodes=${E2E_CLUSTER_NODES} --scopes=cloud-platform"
--gke-create-args="--enable-autoscaling --min-nodes=1 --max-nodes=${E2E_CLUSTER_NODES} --scopes=cloud-platform --enable-basic-auth --no-issue-client-certificate"
--gke-shape={\"default\":{\"Nodes\":${E2E_CLUSTER_NODES}\,\"MachineType\":\"${E2E_CLUSTER_MACHINE}\"}}
--provider=gke
--deployment=gke
Expand Down
23 changes: 21 additions & 2 deletions test/library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,29 @@ function acquire_cluster_admin_role() {
# might not have the necessary permission.
local password=$(gcloud --format="value(masterAuth.password)" \
container clusters describe $2 --zone=$3)
kubectl --username=admin --password=$password \
create clusterrolebinding cluster-admin-binding \
if [[ -n "${password}" ]]; then
# Cluster created with basic authentication
kubectl config set-credentials cluster-admin \
--username=admin --password=${password}
else
local cert=$(mktemp)
local key=$(mktemp)
echo "Certificate in ${cert}, key in ${key}"
gcloud --format="value(masterAuth.clientCertificate)" \
container clusters describe $2 --zone=$3 | base64 -d > ${cert}
gcloud --format="value(masterAuth.clientKey)" \
container clusters describe $2 --zone=$3 | base64 -d > ${key}
kubectl config set-credentials cluster-admin \
--client-certificate=${cert} --client-key=${key}
fi
kubectl config set-context $(kubectl config current-context) \
--user=cluster-admin
kubectl create clusterrolebinding cluster-admin-binding \
--clusterrole=cluster-admin \
--user=$1
# Reset back to the default account
gcloud container clusters get-credentials \
$2 --zone=$3 --project $(gcloud config get-value project)
}

# Authenticates the current user to GCR in the current project.
Expand Down

0 comments on commit ddf8152

Please sign in to comment.