Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Check for errors when trying to create the auth token file #447

Merged
merged 3 commits into from
Mar 24, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/controlplane/config/token_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@ func ReadOrEncryptAuthTokens(dirname string, encryptor CachedEncryptor) (*Encryp

// Auto-creates the auth token file, useful for those coming from previous versions of kube-aws
if _, err := os.Stat(authTokenPath); os.IsNotExist(err) {
_, err := os.OpenFile(authTokenPath, os.O_RDONLY|os.O_CREATE, 0600)
file, err := os.OpenFile(authTokenPath, os.O_RDONLY|os.O_CREATE, 0600)
if err != nil {
return nil, err
}
defer file.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

you never use file, why defer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@redbaron I just wanted to make sure all handles were closed properly. Is this unnecessary in this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

defer delays file.Close() until function exits. you don't use file anywhere, so close it right there, without defer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@redbaron done! Thanks for your feedback.

}

if _, err := ReadRawAuthTokens(dirname); err != nil {
Expand Down