ahmetb / kubectx

Faster way to switch between clusters and namespaces in kubectl
https://kubectx.dev
Apache License 2.0
17.31k stars 1.24k forks source link

`kubens` fails with `invalid apiVersion "client.authentication.k8s.io/v1"` but `kubectl` works normally #391

Closed felipecrs closed 1 year ago

felipecrs commented 1 year ago

As the title says, kubens doesn't work but kubectl does. I wonder what's wrong.

❯ kubens --version
0.9.4
❯ kubens default
error: failed to query if namespace exists (is cluster accessible?): failed to initialize k8s REST client: exec plugin: invalid apiVersion "client.authentication.k8s.io/v1"
❯ kubectl version --short
Client Version: v1.27.3
Kustomize Version: v5.0.1
Server Version: v1.25.3
❯ kubectl get namespaces
NAME                          STATUS   AGE
cattle-fleet-system           Active   146d
cattle-impersonation-system   Active   146d
cattle-system                 Active   146d
cis-operator-system           Active   146d
cluster-crds                  Active   50d
default                       Active   146d
gatekeeper-system             Active   146d
ingress-nginx                 Active   146d
kube-node-lease               Active   146d
kube-public                   Active   146d
kube-system                   Active   146d
local                         Active   146d

Here is how my kubeconfig looks like:

apiVersion: v1
kind: Config
users:
  - name: user # redacted
    user:
      exec:
        command: "internal-authentation-binary" # redacted
        apiVersion: "client.authentication.k8s.io/v1"
        args:
          - "kubeconfig"
          - "auth"
        interactiveMode: IfAvailable
clusters:
  - name: cluster-name # redacted
    cluster:
      server: cluster-url # redacted
      certificate-authority-data: "" # redacted
contexts:
  - name: cluster-name # redacted
    context:
      cluster: cluster-name # redacted
      user: user # redacted
current-context: cluster-name # redacted
ahmetb commented 1 year ago

Thanks for reporting. I see the same error across other repos using Kubernetes Go client. I think the authentication scheme of exec plugins has changed in a backwards incompatible way and we need to bump the k8s.io/client-go module to fix this. It should be fairly easy, I'll try to get to it soon.

felipecrs commented 1 year ago

Thanks a ton, @ahmetb, the new version works nice!