google-github-actions / get-gke-credentials

A GitHub Action that configure authentication to a GKE cluster.
https://cloud.google.com/gke
Apache License 2.0
105 stars 41 forks source link

google-github-actions/get-gke-credentials failed with: not found: projects/***/zones/us-central1-a/clusters/autopilot-cluster-1. #253

Closed avisatna closed 1 year ago

avisatna commented 1 year ago

TL;DR

get-gke-credentials are failing with below error message,

google-github-actions/get-gke-credentials failed with: not found: projects/***/zones/us-central1-a/clusters/autopilot-cluster-1.

github action link: https://github.com/avisatna/ProductAPI/actions/runs/3505258773/jobs/5871453330

Expected behavior

No response

Observed behavior

No response

Action YAML

github action link: https://github.com/avisatna/ProductAPI/actions/runs/3505258773/jobs/5871453330

Log output

No response

Additional information

No response

sethvargo commented 1 year ago

Hi @avisatna - does that cluster exist? Are you sure that's the correct Project ID? There's not enough information to debug this as-is. Please enable debugging logging and run the workload again.

avisatna commented 1 year ago

@sethvargo yes, cluster is exists & project id also is correct. enabled debugging & logging, below is the job link & logs

yml file link: https://github.com/avisatna/ProductAPI/blob/master/.github/workflows/google.yml

job link: https://github.com/avisatna/ProductAPI/actions/runs/3505258773/jobs/5874040757

Run google-github-actions/get-gke-credentials@v0 with: cluster_name: autopilot-cluster-1 location: us-central1-a project_id: use_auth_provider: false use_internal_ip: false use_connect_gateway: false env: PROJECT_ID: GAR_LOCATION: us-central1 GKE_CLUSTER: autopilot-cluster-1 GKE_ZONE: us-central1-a DEPLOYMENT_NAME: gke-test REPOSITORY: samples IMAGE: static-site CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE: /home/runner/work/ProductAPI/ProductAPI/gha-creds-bab7b11357526cbc.json GOOGLE_APPLICATION_CREDENTIALS: /home/runner/work/ProductAPI/ProductAPI/gha-creds-bab7b11357526cbc.json GOOGLE_GHA_CREDS_PATH: /home/runner/work/ProductAPI/ProductAPI/gha-creds-bab7b11357526cbc.json CLOUDSDK_CORE_PROJECT: CLOUDSDK_PROJECT: GCLOUD_PROJECT: GCP_PROJECT: GOOGLE_CLOUD_PROJECT: ***

sethvargo commented 1 year ago

Hi @avisatna

My gut feeling is that the PROJECT_ID isn't being injected properly, or it refers to the wrong project. Can you try removing the project ID as a secret and injecting it directly into the workflow instead?

andrewralon commented 4 months ago

This is still an issue today on version 2.1.0 ....

Error: google-github-actions/get-gke-credentials failed with: not found: projects/<project-id>/zones/<location>/clusters/<cluster-id>.

When? It happens when:

  1. Inputs are cluster_name and location
  2. The GKE cluster's Location type is Regional (not Zonal)
  3. location is given a zone value instead of a region value

Why? It fails if location is given a zone value and the cluster's location type is regional. Something assumes the location type as zone or region based on the value given. So it fails.... most likely on this line of main.ts:

BEFORE - This fails when location is given zone but needs a region:

      - name: Get GKE credentials
        uses: google-github-actions/get-gke-credentials@v2.1.0
        with:
          cluster_name: my-cluster
          location: us-east1-b  # zone given, but needs to be a region, such as "us-east1"

Solution 1 - Use cluster's full name (format: projects/*/locations/*/clusters/*) and exclude location

      - name: Get GKE credentials
        uses: google-github-actions/get-gke-credentials@v2.1.0
        with:
          cluster_name: projects/123456789012/locations/us-east1/clusters/my-cluster

Solution 2 - Set location to a valid region (instead of a valid zone)

      - name: Get GKE credentials
        uses: google-github-actions/get-gke-credentials@v2.1.0
        with:
          cluster_name: my-cluster
          location: us-east1

Suggestions:

  1. Provide the expected format projects/*/locations/*/clusters/* for the full resource name of cluster_name in the README, since it does NOT match the format //container.googleapis.com/projects/PROJECT_ID/clusters/CLUSTER_ID given here: https://cloud.google.com/iam/docs/full-resource-names
  2. Try both location types, regardless of the location value given....
  3. Update the error message to be more helpful. Consider appending a statement like this: Confirm the cluster's location type and the correct zone or region value.