danielfoehrKn / kubeswitch

The kubectx for operators.
https://danielfoehrkn.medium.com/the-case-of-kubeswitch-aff4b6a04ae7
Apache License 2.0
832 stars 80 forks source link

GKE store: no projects found in Google Cloud #63

Closed Zebradil closed 6 months ago

Zebradil commented 1 year ago

Prerequisites:

# ~/.kube/switch-config.yaml
kind: SwitchConfig
version: "v1alpha1"
kubeconfigStores:
  - kind: gke
    id: gke
    config:
      authentication:
        authenticationType: gcloud
      # optionally limit to certain projects in account
      # projectIDs: []

Steps to reproduce:

  1. Run switch (Google Cloud Authorization opens in a web browser)
  2. Allow access
  3. Wait a little bit, then exit from switch

Result:

$ switch
WARN[0021] Supressed warnings during the search: 1 error occurred:
        * store "gke.gke" returned an error during the search: failed to initialize store: no projects found in Google Cloud. Unable to discover GKE clusters

Error: abort

Expected

A list of GKE clusters. There are definitely some projects:

$ gcloud projects list | wc -l
5

And some GKE clusters:

$ gcloud container clusters list | wc -l
2

Additional information

Kubeswitch version info:

Switch:
        version     : v0.7.2
        build date  : 2022-09-20
        go version  : go1.19
        go compiler : gc
        platform    : linux/amd64

Gcloud version info:

Google Cloud SDK 404.0.0
alpha 2022.09.23
beta 2022.09.23
bq 2.0.78
bundled-python3-unix 3.9.12
core 2022.09.23
gcloud-crc32c 1.0.0
gke-gcloud-auth-plugin 0.4.0
gsutil 5.14
dfineSvenFlock commented 1 year ago

Did you get it to work? I have the same issues

dfineSvenFlock commented 1 year ago

I also have to authenicate every time against Google when calling switch.

dfineSvenFlock commented 1 year ago

And I have no idea what a gcp store is and what ID is meant by that description: id: id-only-required-if-there-are-more-than-one-store

dfineSvenFlock commented 1 year ago

Ok, got it to working. Specific API has not been enabled. You can trigger this by executing

gcloud projects list
API [cloudresourcemanager.googleapis.com] not enabled on project. Would you like to enable and retry (this will take a few minutes)? (y/N)?  y

After that, it just works :-)

danielfoehrKn commented 6 months ago

Closed as seems to be a user issue.

Zebradil commented 5 months ago

@danielfoehrKn it is not a user issue. The issue @dfineSvenFlock had was something different. The original problem is still reproducible.

RiRa12621 commented 2 months ago

@Zebradil do you use multiple gcloud configurations and is gke enabled / are there gke clusters in your default config?

RiRa12621 commented 2 months ago

had the same, solved this by setting my default gcloud profile to a project that has a gke cluster. Wouldn't really call it a bug, but a "nice to be documented" or improvement kind of thing

Zebradil commented 2 months ago

@Zebradil do you use multiple gcloud configurations and is gke enabled / are there gke clusters in your default config?

No, I always used a single account. I'm not sure what you mean by "gke clusters in the default config", but there is nothing apart from my account email. Setting a default project is not an option, as I don't have one that can be set as a default.

My solution to this issue was to stop using the gke store completely. Instead I use another tool to generate kubeconfigs for all GKE clusters I have access to and use kubeswitch just to switch contexts from the filesystem store.

PixiBixi commented 1 week ago

On my side, i've faced to the same issue without knowing why, i've did this trick on my .zshrc

export CLOUDSDK_CORE_PROJECT=my-project-with-gke-cluster

This variable is used by gcloud CLI to know i which project the gcloud CLI should process the command ;)