Skip to content

Commit d7efbe5

Browse files
Move code to access bucket iam role to backend
1 parent 1203353 commit d7efbe5

File tree

4 files changed

+55
-15
lines changed

4 files changed

+55
-15
lines changed

perfmetrics/scripts/testing_on_gke/examples/dlio/run_tests.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
# local imports from other directories
3232
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'utils'))
33-
from run_tests_common import escape_commas_in_string, parse_args, run_command
33+
from run_tests_common import escape_commas_in_string, parse_args, run_command, add_iam_role_for_buckets
3434

3535
# local imports from same directory
3636
import dlio_workload
@@ -79,6 +79,16 @@ def main(args) -> None:
7979
args.instance_id,
8080
args.machine_type,
8181
)
82+
buckets = [dlioWorkload.bucket for dlioWorkload in dlioWorkloads]
83+
role = 'roles/storage.objectUser'
84+
add_iam_role_for_buckets(
85+
buckets,
86+
role,
87+
args.project_id,
88+
args.project_number,
89+
args.namespace,
90+
args.ksa,
91+
)
8292
for helmInstallCommand in helmInstallCommands:
8393
print(f'{helmInstallCommand}')
8494
if not args.dry_run:

perfmetrics/scripts/testing_on_gke/examples/fio/run_tests.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# local imports from other directories
3131
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'utils'))
32-
from run_tests_common import escape_commas_in_string, parse_args, run_command
32+
from run_tests_common import escape_commas_in_string, parse_args, run_command, add_iam_role_for_buckets
3333

3434
# local imports from same directory
3535
import fio_workload
@@ -80,6 +80,16 @@ def main(args) -> None:
8080
args.instance_id,
8181
args.machine_type,
8282
)
83+
buckets = (fioWorkload.bucket for fioWorkload in fioWorkloads)
84+
role = 'roles/storage.objectUser'
85+
add_iam_role_for_buckets(
86+
buckets,
87+
role,
88+
args.project_id,
89+
args.project_number,
90+
args.namespace,
91+
args.ksa,
92+
)
8393
for helmInstallCommand in helmInstallCommands:
8494
print(f'{helmInstallCommand}')
8595
if not args.dry_run:
@@ -88,4 +98,4 @@ def main(args) -> None:
8898

8999
if __name__ == '__main__':
90100
args = parse_args()
91-
main(args)
101+
main(args)

perfmetrics/scripts/testing_on_gke/examples/run-gke-tests.sh

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,6 @@ function createKubernetesServiceAccountForCluster() {
435435
kubectl config view --minify | grep namespace:
436436
}
437437
438-
function addGCSAccessPermissions() {
439-
test -f "${workload_config}"
440-
grep -wh '\"bucket\"' "${workload_config}" | cut -d: -f2 | cut -d, -f1 | cut -d \" -f2 | sort | uniq | grep -v ' ' | while read workload_bucket; do
441-
gcloud storage buckets add-iam-policy-binding gs://${workload_bucket} \
442-
--member "principal://iam.googleapis.com/projects/${project_number}/locations/global/workloadIdentityPools/${project_id}.svc.id.goog/subject/ns/${appnamespace}/sa/${ksa}" \
443-
--role "roles/storage.objectUser"
444-
done
445-
}
446-
447438
function ensureGcsfuseCode() {
448439
echo "Ensuring we have gcsfuse code ..."
449440
# clone gcsfuse code if needed
@@ -521,12 +512,12 @@ function deleteAllPods() {
521512
522513
function deployAllFioHelmCharts() {
523514
echo "Deploying all fio helm charts ..."
524-
cd "${gke_testing_dir}"/examples/fio && python3 ./run_tests.py --workload-config "${workload_config}" --instance-id ${instance_id} --machine-type="${machine_type}" && cd -
515+
cd "${gke_testing_dir}"/examples/fio && python3 ./run_tests.py --workload-config "${workload_config}" --instance-id ${instance_id} --machine-type="${machine_type}" --project-id=${project_id} --project-number=${project_number} --namespace=${appnamespace} --ksa=${ksa} && cd -
525516
}
526517
527518
function deployAllDlioHelmCharts() {
528519
echo "Deploying all dlio helm charts ..."
529-
cd "${gke_testing_dir}"/examples/dlio && python3 ./run_tests.py --workload-config "${workload_config}" --instance-id ${instance_id} --machine-type="${machine_type}" && cd -
520+
cd "${gke_testing_dir}"/examples/dlio && python3 ./run_tests.py --workload-config "${workload_config}" --instance-id ${instance_id} --machine-type="${machine_type}" --project-id=${project_id} --project-number=${project_number} --namespace=${appnamespace} --ksa=${ksa} && cd -
530521
}
531522
532523
function listAllHelmCharts() {
@@ -622,7 +613,6 @@ createKubernetesServiceAccountForCluster
622613
ensureGcsfuseCode
623614

624615
# GCP/GKE configuration dependent on GCSFuse/CSI driver source code
625-
addGCSAccessPermissions
626616
createCustomCsiDriverIfNeeded
627617

628618
# Run latest workload configuration

perfmetrics/scripts/testing_on_gke/examples/utils/run_tests_common.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,33 @@ def parse_args():
9898
help='Machine-type of the GCE VM or GKE cluster node e.g. n2-standard-32',
9999
required=True,
100100
)
101+
parser.add_argument(
102+
'--project-id',
103+
metavar='project-id of the user gke cluster',
104+
help='project-id of the user gke cluster e.g. gcs-fuse-test',
105+
required=True,
106+
)
107+
parser.add_argument(
108+
'--project-number',
109+
metavar='project-number of the user gke cluster',
110+
help='project-number of the user gke cluster e.g. 927584127901',
111+
required=True,
112+
type=int,
113+
)
114+
parser.add_argument(
115+
'--namespace',
116+
metavar='kubectl namespace of the user',
117+
help='kubectl namespace of the user e.g. default',
118+
required=False,
119+
default='default',
120+
)
121+
parser.add_argument(
122+
'--ksa',
123+
metavar='kubernetes service account of the user',
124+
help='kubernetest service account of the user e.g. default',
125+
required=False,
126+
default='default',
127+
)
101128
parser.add_argument(
102129
'-n',
103130
'--dry-run',
@@ -112,6 +139,9 @@ def parse_args():
112139
for argument in [
113140
'instance_id',
114141
'machine_type',
142+
'project_id',
143+
'namespace',
144+
'ksa',
115145
]:
116146
value = getattr(args, argument)
117147
if len(value) == 0 or str.isspace(value):

0 commit comments

Comments
 (0)