MarkEdmondson1234 / googleCloudRunner

Easy R scripts on Google Cloud Platform via Cloud Run, Cloud Build and Cloud Scheduler
https://code.markedmondson.me/googleCloudRunner/
Other
82 stars 26 forks source link

Submit Build to Private Worker Pool #210

Open joranE opened 12 months ago

joranE commented 12 months ago

I apologize for asking here, but I've simply hit a wall trying to figure this out from Google's documentation.

I'm trying to submit a build using googleCloudRunner to a private worker pool. I'm doing this by passing the argument:

options = list("pool" = list("name" = "projects/{projectid}/locations/{region}/workerPools/{worker pool name}")))

to cr_build. I've checked an double checked that the service account submitting the build has the WorkerPool User role. But I just get a 404 workerpool not found error every time.

I feel like I've done all the steps in the Google documentation, but clearly I'm missing something. Again, I realize this isn't a problem with your package, I just feel out of other options at this point.

joranE commented 12 months ago

I figured it out, and it turns out I actually did ask in the right place, sort of. It turns out the cr_build() is submitting the request to an API endpoint that is incompatible with private worker pools. The breadcrumb I found eventually is a comment at the bottom here.

Instead of passing the request to this endpoint:

https://cloudbuild.googleapis.com/v1/projects/{projectId}/builds

...you have to pass it to this one:

https://cloudbuild.googleapis.com/v1/{parent=projects/*/locations/*}/builds

...and specify a location that matches the location of your private worker pool. I can trick cr_build() into using this second endpoint by passing projectId = "{projectId}/locations/{location}"

I am SO happy I figured this out. I'd be happy to work on a pull request to adjust cr_build() to accommodate private worker pools more transparently. It might take some alteration to the function signature, so if you have strong opinions on how to approach it I'll abide by whatever you suggest.

MarkEdmondson1234 commented 12 months ago

I'm sorry I've not done this myself before so can't say for sure. The options looks correct - have you need to precreate a worker node pool for the jobs perhaps? (Kubernetes cluster I guess, but a managed one)

MarkEdmondson1234 commented 12 months ago

Ah you figured it out, great :) yes a pull request would be much appreciated.

joranE commented 12 months ago

I'll explore possible changes, but looking at it with fresh eyes today, I think making the entire package work with builds on private worker pools might involve deeper changes than I originally thought. That base API endpoint URL is baked into functions all over the place. For instance, I had to go through quite a few more contortions to get cr_schedule_http() to utilize the right API endpoint to schedule a build that was built on a private worker pool. I'll think about it and see if I can come up with something relatively clean.

MarkEdmondson1234 commented 12 months ago

A function to make the URL then find/replace the hardcoded strings maybe. I had a similar pattern for using beta versions of the API