Skip to content

Commit

Permalink
Fix method of obtaining service account token (#3199)
Browse files Browse the repository at this point in the history
  • Loading branch information
liggitt authored May 20, 2022
1 parent 68a1452 commit d76d6c3
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions e2e/live/end-to-end-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1187,16 +1187,11 @@ wait 2
# Setup: use the service account just created. It does not have permissions
# on the default namespace, so it will give a permissions error on apply
# for anything attempted to apply to the default namespace.
echo "kubectl get sa user -ojsonpath='{.secrets[0].name}'"
SECRET_NAME="$(kubectl get sa user -ojsonpath='{.secrets[0].name}')"
if [[ -z "${SECRET_NAME}" ]]; then
# K8s 1.24+ doesn't auto-generate service account secrets any more.
echo "kubectl apply -f e2e/live/testdata/rbac-error-step-2"
kubectl apply -f e2e/live/testdata/rbac-error-step-2 2>&1 | tee $OUTPUT_DIR/status
assertContains "secret/user-credentials created"
wait 2
SECRET_NAME="user-credentials"
fi
echo "kubectl apply -f e2e/live/testdata/rbac-error-step-2"
kubectl apply -f e2e/live/testdata/rbac-error-step-2 2>&1 | tee $OUTPUT_DIR/status
assertContains "secret/user-credentials created"
wait 2
SECRET_NAME="user-credentials"
echo "kubectl get secrets -ojsonpath='{.data.token}' "${SECRET_NAME}" | base64 -d"
SECRET_TOKEN="$(kubectl get secrets -ojsonpath='{.data.token}' "${SECRET_NAME}" | base64 -d)"
echo "kubectl config set-credentials user --token \"<REDACTED>\""
Expand Down Expand Up @@ -1446,16 +1441,11 @@ wait 2
# Setup: use the service account just created. It does not have permissions
# on the default namespace, so it will give a permissions error on apply
# for anything attempted to apply to the default namespace.
echo "kubectl get sa user -ojsonpath='{.secrets[0].name}'"
SECRET_NAME="$(kubectl get sa user -ojsonpath='{.secrets[0].name}')"
if [[ -z "${SECRET_NAME}" ]]; then
# K8s 1.24+ doesn't auto-generate service account secrets any more.
echo "kubectl apply -f e2e/live/testdata/rbac-error-step-2"
kubectl apply -f e2e/live/testdata/rbac-error-step-2 2>&1 | tee $OUTPUT_DIR/status
assertContains "secret/user-credentials created"
wait 2
SECRET_NAME="user-credentials"
fi
echo "kubectl apply -f e2e/live/testdata/rbac-error-step-2"
kubectl apply -f e2e/live/testdata/rbac-error-step-2 2>&1 | tee $OUTPUT_DIR/status
assertContains "secret/user-credentials created"
wait 2
SECRET_NAME="user-credentials"
echo "kubectl get secrets -ojsonpath='{.data.token}' "${SECRET_NAME}" | base64 -d"
SECRET_TOKEN="$(kubectl get secrets -ojsonpath='{.data.token}' "${SECRET_NAME}" | base64 -d)"
echo "kubectl config set-credentials user --token \"<REDACTED>\""
Expand Down

0 comments on commit d76d6c3

Please sign in to comment.