Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

gsctl: Ensure that certificate paths get updated with config dir migration #63

Merged
merged 4 commits into from
May 26, 2017

Conversation

marians
Copy link
Member

@marians marians commented May 26, 2017

Fixes https://github.com/giantswarm/gsctl/issues/59

In #55 a migration of the configuration directory has been introduced. Unfortunately I forgot to take care of a user's kubectl config file.

This PR here makes the migration also maintain the paths. It does it simply by replacing occurrences of the old path with the new path in the config, not trying to be any more clever than that.

@marians marians requested a review from rossf7 May 26, 2017 09:23
@codecov-io
Copy link

codecov-io commented May 26, 2017

Codecov Report

Merging #63 into master will increase coverage by 0.45%.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #63      +/-   ##
==========================================
+ Coverage   39.11%   39.56%   +0.45%     
==========================================
  Files          23       23              
  Lines         854      867      +13     
==========================================
+ Hits          334      343       +9     
- Misses        478      479       +1     
- Partials       42       45       +3
Impacted Files Coverage Δ
config/config.go 69.49% <57.14%> (-0.04%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b858fe...f0f7e42. Read the comment docs.

if confReadErr != nil {
t.Error(confReadErr)
}
t.Log(string(newConf))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this logged to check manually? If so should it be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be output if the user starts tests in verbose mode (which btw Atom with go-plus does by default), so I still see a use for it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool that's fine then. I just wanted to check. BTW I'm currently trying out VS Code and liking it a lot.

config/config.go Outdated
// adapt certificate paths in kubeconfig
if len(KubeConfigPaths) > 0 {
// we only adapt the first file found (on purpose)
if stat, err := os.Stat(KubeConfigPaths[0]); err == nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the KubeConfigPaths[0] I'm not sure what this is and makes the code hard to read. I'd also prefer to see a variable as its used multiple times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understood that as you meant it. Changed it. Better?

Copy link

@rossf7 rossf7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marians thanks for changing the kube config paths. I like it much more this way. <3

This LGTM the only thing I'm not sure on is theKubeConfigPath var name. The "the" prefix reads a bit strange but feel free to leave as is.

@marians marians requested review from kopiczko and removed request for JosephSalisbury May 26, 2017 10:13
@marians
Copy link
Member Author

marians commented May 26, 2017

@rossf7 I see what you mean, but I couldn't come up with a better alternative. What I'm trying to say is: Of all the possible kubectl configuration paths, this is the f***ing single one I want to deal with here.

Copy link
Member

@kopiczko kopiczko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite comment LGTM

config/config.go Outdated
// write back
writeErr := ioutil.WriteFile(theKubeConfigPath, []byte(newConfig), stat.Mode())
if writeErr != nil {
return fmt.Errorf("Could not overwrite kubectl config file. %s", writeErr.Error())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually go errors doesn't start with capital letter and terminate with full stop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I'll change that. Tim would also have demanded that. :)

for golang style consistency
@marians
Copy link
Member Author

marians commented May 26, 2017

Thanks for the reviews!

config/config.go Outdated
@@ -299,7 +299,7 @@ func migrateConfigDir() error {
// write back
writeErr := ioutil.WriteFile(theKubeConfigPath, []byte(newConfig), stat.Mode())
if writeErr != nil {
return fmt.Errorf("Could not overwrite kubectl config file. %s", writeErr.Error())
return errors.New("could not overwrite kubectl config file")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say do it like return fmt.Errorf("could not overwrite kubectl config file: %s", writeErr.Error()), unless you don't care about writeErr message.

BTW in almost all cases error variable is called err and reused.

@marians marians merged commit 556abe6 into master May 26, 2017
@marians marians deleted the config-migration-kubectl branch May 26, 2017 10:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants