-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kubeconfig command features update #255
base: master
Are you sure you want to change the base?
Conversation
@xetys @mavimo can you take a look. |
To perform merge i'm going to use same approach as for sanitization of config (client-go, they have all required api for this), stole this way from official kubectl part, just a bit light weight for our needs. before EOW planing to add merge here. |
@mavimo @xetys added merge, tested multiple time with my local setup. it is safe to use. |
@md2k JM2C: we should not overwrite a context, we should communicate the failure to the user that can rename/delete the context before retry to pull it. Adding a flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor changes suggested.
@md2k I really like to introduce some tests to this feature, should be easy to test and at the same time since the serialisation/deserialisation can be have different scenario I suppose we should "complicate" the logics behind it on time and without appropriate test-coverage should be hard to evolve it.
PS: I really like this feature, thx for time you spent on this contribution!!
|
||
// Dump is handy dumps of structure as json (almost any structures) | ||
func Dump(cls interface{}) { | ||
data, err := json.MarshalIndent(cls, "", " ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can replace it with
fmt.Println(Sdump(cli))
Since I suppose this is a debug utils, I'm not sure we should keep it in our codebase :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is debug tools, so can be removed before merge. :)
) | ||
|
||
const ( | ||
defaultContext = "kubernetes-admin@kubernetes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure on why we are defining this defaultContext
, maybe context should be "cluster specific", like kubernetes-admin@{CLUSTER_NAME}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not what we going to set, this is what we looking to rename. regardless cluster, this context set by default during kubebootstrap, so all our configs with this context. maybe i should change name to default_pattern
then.
log.Fatalln("aborted") | ||
} | ||
} | ||
if save, _ := cmd.Flags().GetBool("save"); save { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignored error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, if they are defined, no error should occur
|
||
ioutil.WriteFile(kubeconfigPath, []byte(kubeConfigContent), 0755) | ||
targetPath := fmt.Sprintf("%s/.kube/%s.yaml", GetHome(), provider.GetCluster().Name) | ||
if target, _ := cmd.Flags().GetString("target"); target != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignored error
}, | ||
} | ||
|
||
// Write kubeConfig to destination | ||
func doConfigWrite(dst string, kubeConfig string) (err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func doConfigWrite(dst string, kubeConfig string) (err error) { | |
func doConfigWrite(dst string, kubeConfig string) error { |
} | ||
|
||
// Create backup of current kubeCongig | ||
func doConfigCopyBackUp(src string) (err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func doConfigCopyBackUp(src string) (err error) { | |
func doConfigCopyBackUp(src string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this done to not assign error directly with :=
for example if you going to use:
if source, err := os.Open(src); err != nil {
return
}
source
will available only inside condition, and we want have access to it outside of condition.
if source
declared, then use of :=
will rise error.
if to remove declaration of err
from function then i need also use condition differently as:
source, err := os.Open(src)
if err != nil {
return
}
While both variants completely good, first variant probably looks bit nicer.
But here this is how i do usually. also no need do return
with exact parameters :)
If still want me to use your suggestion, let me know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JM2C: the first variant is a bit concise, but make code more hard to understand. We can declare err
just before the usage (as we do for source
) and return the error (eventually decorated with extra info), like:
var source, destination *os.File
var err error
if source, err = os.Open(src); err != nil {
return fmt.Errorf("unable to get source file: %v", err)
}
or use the second proposal:
source, err := os.Open(src)
if err != nil {
return fmt.Errorf("unable to get source file: %v", err)
}
IMHO the second variant is more comprehensible when someone look the code for the first time (new contributors, ppl that try to investigate an issue, the user that write the code after few weeks that write the code..).
Off course is my opinion, maybe a 3rd opinion should be useful ;) cc/ @xetys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the second more, as I'm not a fan of C style declaring variables in the header and than doing the code later. The second one is far better to read and understand, and an actual goal of go to make it looking like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it depends, as i said, all variants is valid in go. but i can agree , i'm always judging from my 5+ experience in go, and for me personally read some-one code in this scope absolutely transparent. but if majority vote for
if err != nil {
return err
}
not a problem :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mavimo, we can cover it with tests for sure, only i'm not sure it is truly necessary at this part (but it is my vision). My idea to cover next scenario:
Another way, is implement basic functionality to manage config by this tool.
so we can manage kubeconfig(s), but i really do not want do that, because this is out of scope of this tool and all this functionality already built-in to |
Other suggestions i'll fix today evening. |
heh, weekend was busy. i'll try to finalize today-tomorrow this PR |
found few bugs in current merge logic, so yeah, need to do more complex logic i think. by some reason it not always merge it in right direction. going to dive into a bit more |
nvm here, just a rebase from master and fix for conflicts. |
Hey, I'm up to release 0.5 soon and would like to merge this PR. I see the following two ways:
Decide which is better for you, how much time you can spend on this right now. |
hey, what's up here? I would love to see this PR ready for merge |
This PR about
hetzner-kube cluster kubeconfig my-cluster
What added:
~/.kube/my-cluster.yaml