googleapis / nodejs-cloudbuild

This repository is deprecated. All of its content and history has been moved to googleapis/google-cloud-node.
https://cloud.google.com/cloud-build/docs/
Apache License 2.0
38 stars 13 forks source link

Unable to create build with custom pool #300

Closed michaeleekk closed 2 years ago

michaeleekk commented 2 years ago

I used the sample code to try triggering a cloud build from a config file. Things worked when without the worker pool parameter. I got a worker pool not found error. I could send build to the worker pool with cli but just not nodejs. I actually tried the REST API and Python SDK but also didn't work.

(node:631727) UnhandledPromiseRejectionWarning: Error: 5 NOT_FOUND: workerpool not found: "projects/<project id>/workerPools/<worker pool name>"
    at Object.callErrorFromStatus (/home/michael/project1/node_modules/@grpc/grpc-js/build/src/call.js:31:26)
    at Object.onReceiveStatus (/home/michael/project1/node_modules/@grpc/grpc-js/build/src/client.js:180:52)
    at Object.onReceiveStatus (/home/michael/project1/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:365:141)
    at Object.onReceiveStatus (/home/michael/project1/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:328:181)
    at /home/michael/project1/node_modules/@grpc/grpc-js/build/src/call-stream.js:182:78
    at processTicksAndRejections (internal/process/task_queues.js:79:11)

Environment details

Steps to reproduce

import json

import google.auth
from google.cloud.devtools import cloudbuild_v1

def quickstart():
    """Create and execute a simple Google Cloud Build configuration,
    print the in-progress status and print the completed status."""

    # Authorize the client with Google defaults
    credentials, project_id = google.auth.default()
    client = cloudbuild_v1.services.cloud_build.CloudBuildClient()

    build = cloudbuild_v1.Build()

    # The following build steps will output "hello world"
    # For more information on build configuration, see
    # https://cloud.google.com/build/docs/configuring-builds/create-basic-configuration
    j = json.loads(open('cloudbuild.json').read())
    build.steps = j['steps']
    build.substitutions = j['substitutions']
    build.images = j['images']
    build.options = {"pool": {"name":j['workerPool']}}
    # build.timeout = 3000 # j['timeout']

    operation = client.create_build(project_id='<project id>', build=build)
    # Print the in-progress operation
    print("IN PROGRESS:")
    print(operation.metadata)

    result = operation.result()
    # Print the completed status
    print("RESULT:", result.status)
# [END cloudbuild_quickstart]

if __name__ == "__main__":
    quickstart()
ace-n commented 2 years ago

Hi @michaeleekk and thanks for the issue. I tried to reproduce this myself but was unable to.

Can you paste a copy of your cloudbuild.json file here so we can reproduce this? (If there are secrets there, please replace them with dummy values in your paste.)

Thanks!

mpmartinez-etsy commented 2 years ago

good morning @ace-n - i actually have an open support case about this exact issue. Can i provide an example JS file that in my experience replicates this issue? I can replicate this with the following:

#!/usr/bin/env node
"use strict";

const CloudBuild = require("@google-cloud/cloudbuild");

const projectId = "<an-existent-project>";
const client = new CloudBuild.CloudBuildClient();
const privatePool = "<an-existent-private-pool>";
const build = {
    options: {
        pool: {
            name: privatePool,
        },
    },
    steps: [
        {
            args: ["/bin/echo", "hello"],
            id: "example",
            name: "ubuntu",
        },],};

client.createBuild({ build, projectId });

I can provide the specific case number so that you can see the exact project name and resource name if that's necessary, please let me know.

To provide more context, when I comment out the following block:

        pool: {
            name: privatePool,
        },

I can create a cloudbuild job successfully (in the global region). When I specify an existent private pool and uncomment that same block, I get the following complaint:

Error: 5 NOT_FOUND: workerpool not found: "<an-existent-private-pool>"
    at Object.callErrorFromStatus (<path>/node_modules/@grpc/grpc-js/build/src/call.js:31:26)
    at Object.onReceiveStatus (<path>/node_modules/@grpc/grpc-js/build/src/client.js:180:52)
    at Object.onReceiveStatus (<path>/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:365:141)
    at Object.onReceiveStatus (<path>/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:328:181)
    at /<path>/node_modules/@grpc/grpc-js/build/src/call-stream.js:182:78

Please advise if we need to be passing additional options to enable this behavior.

Thanks! Matt

ok-devalias commented 2 years ago

The client libraries are hitting the global api endpoint by default, so for regional resources like this, you'll need to provide additional clientOptions when building the client.

NodeJS

// To build the client, use region + service path as an override api endpoint.
const opts = {apiEndpoint: "us-central1-cloudbuild.googleapis.com"}
const client = new CloudBuild.CloudBuildClient(opts);

Python

... previous imports
from google.api_core.client_options import ClientOptions

client_options = ClientOptions(api_endpoint="us-central1-cloudbuild.googleapis.com")
client = cloudbuild_v1.services.cloud_build.CloudBuildClient(client_options=client_options)

These types of options are described in the gax-nodejs README: https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#service-options

mpmartinez-etsy commented 2 years ago

for anyone else who stumbles across this, this 100% solves my problem - thank you @ok-devalias !