upbound / up

The @upbound CLI
Apache License 2.0
52 stars 41 forks source link

Check validity of kubeconfig before applying it #330

Closed jastang closed 1 year ago

jastang commented 1 year ago

Description of your changes

Use a client to verify connectivity before applying a kubeconfig and setting it as the current context. Will not change the current context on a failure.

Fixes #323

I have:

How has this code been tested

Bad token:

➜  bin ./up ctp kubeconfig get --token="fake token" my-ctp
up: error: the server has asked for the client to provide credentials

Good token, non-existent target:

./up ctp kubeconfig get --token=`cat my-token` does-not-exist
up: error: the server could not find the requested resource

Oops, wrong Upbound organization:

./up ctp kubeconfig get --token=`cat my-token` my-ctp     
up: error: the server could not find the requested resource

That's the one!

➜  bin ./up ctp kubeconfig get --token=`cat my-token` my-ctp -a upbound
Current context set to upbound-upbound-my-ctp
AlainRoy commented 1 year ago

I love what you've done! I have one nit I don't feel strongly about (name of the function), and one suggestion: I'm not sure you want the last check you've got. I'm open to discussion about it though.