Andrew.Stump
Andrew.Stump

Reputation: 151

Get regional cluster in GCP with Python SDK

I am working on a cloud function to interact with clusters inside my GKE, and as part of that function I need to get the relevant cluster. When the cluster is zonal I do not have an issue getting it with

import google.cloud.container

container_client = google.cloud.container.ClusterManagerClient()
response = container_client.get_cluster(
    project_id={project_id},
    cluster_id={cluster_id},
    zone={cluster_zone} # eg europe-west3-a
)
print(response)

However, if I try and get a regional cluster, e.g."europe-west4", I get the error:

google.api_core.exceptions.InvalidArgument: 400 'zone' field cannot be used to access GKE regional clusters. Use 'name' or 'parent' fields instead.

I had tried multiple variations of variables for the get_cluster function including replacing the zone arg with name/parent but then i get the error:

google.api_core.exceptions.InvalidArgument: 400 Location "" does not exist.

So it seems it is just not configured to get regional clusters. Is there another method I can use to get it, or is there something I am missing with get_cluster?

Upvotes: 2

Views: 1070

Answers (1)

Andrew.Stump
Andrew.Stump

Reputation: 151

after reading through the docs, the request has to be made in the form:

response = container_client.get_cluster(name=f"projects/{PROJECT_ID}/locations/{LOCATION}/clusters/{CLUSTER_ID}")

Upvotes: 8

Related Questions