little-angry-clouds / kubernetes-binaries-managers

Kubernetes related binaries manager.
GNU General Public License v3.0
101 stars 11 forks source link

kubectl automatic version detection fails if there is trailing version information #37

Open TyBrown opened 1 year ago

TyBrown commented 1 year ago

The kubectl wrapper has been having difficulties detecting the correct version of certain Kubernetes clusters, particularly those built with EKS or Okteto.

Examples of versions that are causing problems:

Server Version: version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.14-eks-fb459a0", GitCommit:"b07006b2e59857b13fe5057a956e86225f0e82b7", GitTreeState:"clean", BuildDate:"2022-10-24T20:32:54Z", GoVersion:"go1.16.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.11-gke.300", GitCommit:"c350c382e45991555b91385de867af07ec551a3e", GitTreeState:"clean", BuildDate:"2022-09-17T18:32:27Z", GoVersion:"go1.17.13b7", Compiler:"gc", Platform:"linux/amd64"}

Errors:

$ kubectl version
fork/exec /Users/ty/.bin/kubectl-v1.21.14-eks-fb459a0: no such file or directory
fork/exec /Users/ty/.bin/kubectl-v1.23.11-gke.300: no such file or directory

So far, I've been able to work around these problems by manually symlinking the requested versions to the correct (although manually installed versions).

I believe that this line could be reworked a bit to basically trim any extraneous version information from the auto-detected Version. (I think we'd probably want to NOT trim the extra version info if it starts with -alpha, -beta, or -rc, since those are valid versions available via kbenv to download/install)

I'll start working on a draft PR for this... but I figured I'd start the conversation as an issue in case there's disagreement or additional context here that I'm missing before I get too far into it.

Cheers, Ty