Skip to content

Commit 661cea9

Browse files
authored
Merge pull request #282 from hantaowang/script-updates
Update scripts to be compatible with project ids that include the org…
2 parents ebd0c0f + 718e34c commit 661cea9

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

deploy/kubernetes/deploy-driver.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ function check_service_account()
5050
# Using bash magic to parse JSON for IAM
5151
# Grepping for a line with client email returning anything quoted after the colon
5252
readonly IAM_NAME=$(grep -Po '"client_email": *\K"[^"]*"' ${GCE_PD_SA_DIR}/cloud-sa.json | tr -d '"')
53-
# Grepping anything after the @ tell the first . as the project name
54-
readonly PROJECT=$(grep -Po '.*@\K[^.]+'<<<${IAM_NAME})
53+
readonly PROJECT=$(grep -Po '"project_id": *\K"[^"]*"' ${GCE_PD_SA_DIR}/cloud-sa.json | tr -d '"')
5554
readonly GOTTEN_BIND_ROLES=$(gcloud projects get-iam-policy ${PROJECT} --flatten="bindings[].members" --format='table(bindings.role)' --filter="bindings.members:${IAM_NAME}")
5655
readonly BIND_ROLES=$(get_needed_roles)
5756
MISSING_ROLES=false

deploy/setup-project.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,19 @@ ensure_var PROJECT
2525
ensure_var GCE_PD_SA_NAME
2626
ensure_var GCE_PD_SA_DIR
2727

28+
# If the project id includes the org name in the format "org-name:project", the
29+
# gCloud api will format the project part of the iam email domain as
30+
# "project.org-name"
31+
if [[ $PROJECT == *":"* ]]; then
32+
IFS=':' read -ra SPLIT <<< "$PROJECT"
33+
readonly IAM_PROJECT="${SPLIT[1]}.${SPLIT[0]}"
34+
else
35+
readonly IAM_PROJECT="${PROJECT}"
36+
fi
37+
2838
readonly KUBEDEPLOY="${PKGDIR}/deploy/kubernetes"
2939
readonly BIND_ROLES=$(get_needed_roles)
30-
readonly IAM_NAME="${GCE_PD_SA_NAME}@${PROJECT}.iam.gserviceaccount.com"
40+
readonly IAM_NAME="${GCE_PD_SA_NAME}@${IAM_PROJECT}.iam.gserviceaccount.com"
3141

3242
# Check if SA exists
3343
CREATE_SA=true

0 commit comments

Comments
 (0)