Skip to content
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

Re-enable golangci-lint #26

Merged
merged 1 commit into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,8 @@ sub-tag-images-%:
###############################################################################
## Perform static checks on the code.
.PHONY: static-checks

# TODO: re-enable these linters !
LINT_ARGS := --disable typecheck,errcheck,ineffassign,gosimple,staticcheck

static-checks:
$(DOCKER_RUN) $(CALICO_BUILD) golangci-lint run --deadline 5m $(LINT_ARGS)
$(DOCKER_RUN) $(CALICO_BUILD) golangci-lint run --deadline 5m

.PHONY: fix
## Fix static checks
Expand Down
1 change: 0 additions & 1 deletion binder/creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (s *workloadStore) delete(uid string) {
s.mu.Lock()
defer s.mu.Unlock()
delete(s.creds, uid)
return
}

func (s *workloadStore) store(uid string, w workload) {
Expand Down
49 changes: 33 additions & 16 deletions flexvol/flexvoldriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,14 @@ func doMount(destinationDir string, ninputs *creds.Credentials, workloadPath str
err = os.MkdirAll(newDestianationDir, 0777)
if err != nil {
cmd := exec.Command("/bin/unmount", destinationDir)
cmd.Run()
os.RemoveAll(newDir)
e := cmd.Run()
if e != nil {
_ = logWriter.Warning(fmt.Sprintf("failed to unmount %s\n", destinationDir))
}
e = os.RemoveAll(newDir)
if e != nil {
_ = logWriter.Warning(fmt.Sprintf("failed to clear %s\n", newDir))
}
return err
}

Expand All @@ -238,8 +244,14 @@ func doMount(destinationDir string, ninputs *creds.Credentials, workloadPath str
err = cmd.Run()
if err != nil {
cmd = exec.Command("/bin/umount", destinationDir)
cmd.Run()
os.RemoveAll(newDir)
e := cmd.Run()
if e != nil {
_ = logWriter.Warning(fmt.Sprintf("failed to unmount %s\n", destinationDir))
}
e = os.RemoveAll(newDir)
if e != nil {
_ = logWriter.Warning(fmt.Sprintf("failed to clear %s\n", newDir))
}
return err
}

Expand All @@ -262,7 +274,7 @@ func mount(dir, opts string) error {
inp := strings.Join([]string{dir, opts}, "|")

ninputs, workloadPath, s := checkValidMountOpts(opts)
if s == false {
if !s {
return failure("mount", inp, "Incomplete inputs")
}

Expand Down Expand Up @@ -300,12 +312,18 @@ func unmount(dir string) error {
}

// unmount the bind mount
doUnmount(dir + "/nodeagent")
err := doUnmount(dir + "/nodeagent")
if err != nil {
_ = logWriter.Warning(fmt.Sprintf("failed to unmount %s/nodeagent\n", dir))
}
// unmount the tmpfs
doUnmount(dir)
err = doUnmount(dir)
if err != nil {
_ = logWriter.Warning(fmt.Sprintf("failed to unmount %s\n", dir))
}
// delete the directory that was created.
delDir := strings.Join([]string{configuration.NodeAgentWorkloadHomeDir, uid}, "/")
err := os.Remove(delDir)
err = os.Remove(delDir)
if err != nil {
emsgs = append(emsgs, fmt.Sprintf("unmount del failure %s: %s", delDir, err.Error()))
// go head and return ok.
Expand Down Expand Up @@ -365,17 +383,16 @@ func logToSys(caller, inp, opts string) {

opt := strings.Join([]string{caller, inp, opts}, "|")
if configuration.LogLevel == LOG_LEVEL_WARN {
logWriter.Warning(opt)
_ = logWriter.Warning(opt)
} else {
logWriter.Info(opt)
_ = logWriter.Info(opt)
}
}

// addCredentialFile is used to create a credential file when a workload with the flex-volume volume mounted is created.
func addCredentialFile(ninputs *creds.Credentials) error {
//Make the directory and then write the ninputs as json to it.
var err error
err = os.MkdirAll(configuration.NodeAgentCredentialsHomeDir, 0755)
err := os.MkdirAll(configuration.NodeAgentCredentialsHomeDir, 0755)
if err != nil {
return err
}
Expand All @@ -387,7 +404,7 @@ func addCredentialFile(ninputs *creds.Credentials) error {
}

credsFileTmp := strings.Join([]string{configuration.NodeAgentManagementHomeDir, ninputs.UID + ".json"}, "/")
err = ioutil.WriteFile(credsFileTmp, attrs, 0644)
_ = ioutil.WriteFile(credsFileTmp, attrs, 0644)

// Move it to the right location now.
credsFile := strings.Join([]string{configuration.NodeAgentCredentialsHomeDir, ninputs.UID + ".json"}, "/")
Expand All @@ -412,14 +429,14 @@ func initConfiguration() {

bytes, err := ioutil.ReadFile(CONFIG_FILE)
if err != nil {
logWriter.Warning(fmt.Sprintf("Not able to read %s: %s\n", CONFIG_FILE, err.Error()))
_ = logWriter.Warning(fmt.Sprintf("Not able to read %s: %s\n", CONFIG_FILE, err.Error()))
return
}

var config ConfigurationOptions
err = json.Unmarshal(bytes, &config)
if err != nil {
logWriter.Warning(fmt.Sprintf("Not able to parst %s: %s\n", CONFIG_FILE, err.Error()))
_ = logWriter.Warning(fmt.Sprintf("Not able to parst %s: %s\n", CONFIG_FILE, err.Error()))
return
}

Expand Down Expand Up @@ -478,6 +495,6 @@ func main() {
initConfiguration()

if err = rootCmd.Execute(); err != nil {
genericUnsupported("not supported", "", err.Error())
_ = genericUnsupported("not supported", "", err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

Should we handle this error explicitly? I think probably should at least log it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a bit hesitant to log this since whoever's calling a command that isn't supported might be doing it periodically, and logging it would lead to large log files (similar to https://github.com/projectcalico/pod2daemon/issues/20). Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...but this is in main() and not one of the other similar calls, so ok :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...and genericUnsupported() already logs it

}
}