tczekajlo / kube-consul-register

a tool to register Kubernetes PODs as Consul Services
Apache License 2.0
105 stars 50 forks source link

Fix all linter errors #37

Closed arunvelsriram closed 5 years ago

arunvelsriram commented 5 years ago

This PR modifies gometalinter installation step and fixes all the linter warnings.

Details:

  1. gometalinter --install is deprecated. So install gometalinter using binaries as mentioned here

    gometalinter -h
    ...
    -i, --install       Attempt to install all known linters (DEPRECATED - use binary packages).
    ...
  2. Fixed various warnings that made make check fail:

    1. config/config.go:162: Warning call has possible formatting directive %s

      • Use glog.Wargingf instead of glog.Warning.
    2. config.go:60:14:warning: clientset.Core is deprecated: Core retrieves the default version of CoreClient. Please explicitly pick a version. (SA1019) (megacheck)

      • Cherry pick the fix from #33
    3. warnings in endpoints controller:

      ...
      ?       github.com/tczekajlo/kube-consul-register/controller/endpoints  [no test files]
      cd /Users/arunvelsriram/go/src/github.com/tczekajlo/kube-consul-register/controller/endpoints; gometalinter --deadline  720s --vendor -D gotype -D dupl -D gocyclo -D gas -D errcheck
      controller.go:197::warning: Errors unhandled.,LOW,HIGH (gosec)
      controller.go:223::warning: Errors unhandled.,LOW,HIGH (gosec)
      controller.go:235::warning: Errors unhandled.,LOW,HIGH (gosec)
      controller.go:33:2:warning: var addedServices is unused (U1000) (megacheck)
      controller.go:34:2:warning: var addedConsulServices is unused (U1000) (megacheck)
      make: *** [github.com/tczekajlo/kube-consul-register/controller/endpoints] Error 1
    • Add error handlers
    • Removed unused variables
    1. warnings in pods controller:
      ...
      go test -race github.com/tczekajlo/kube-consul-register/controller/pods
      ok      github.com/tczekajlo/kube-consul-register/controller/pods       (cached)
      cd /Users/arunvelsriram/go/src/github.com/tczekajlo/kube-consul-register/controller/pods; gometalinter --deadline  720s --vendor -D gotype -D dupl -D gocyclo -D gas -D errcheck
      controller.go:222::warning: Errors unhandled.,LOW,HIGH (gosec)
      controller.go:259::warning: Errors unhandled.,LOW,HIGH (gosec)
      controller.go:272::warning: Errors unhandled.,LOW,HIGH (gosec)
      controller.go:154:25:warning: this result of append is never used, except maybe in other appends (SA4010) (megacheck)
      make: *** [github.com/tczekajlo/kube-consul-register/controller/pods] Error 1
    • Add error handlers
    • Ignore megacheck linter as it was reporting a false positive
    1. warnings in services controller:
      ...
      go test -race github.com/tczekajlo/kube-consul-register/controller/services
      ?       github.com/tczekajlo/kube-consul-register/controller/services   [no test files]
      cd /Users/arunvelsriram/go/src/github.com/tczekajlo/kube-consul-register/controller/services; gometalinter --deadline  720s --vendor -D gotype -D dupl -D gocyclo -D gas -D errcheck
      controller.go:295::warning: Errors unhandled.,LOW,HIGH (gosec)
      controller.go:327::warning: Errors unhandled.,LOW,HIGH (gosec)
      controller.go:338::warning: Errors unhandled.,LOW,HIGH (gosec)
      controller.go:347::warning: Errors unhandled.,LOW,HIGH (gosec)
      controller.go:351::warning: Errors unhandled.,LOW,HIGH (gosec)
      controller.go:33:2:warning: var addedServices is unused (U1000) (megacheck)
      controller.go:560:22:warning: func (*Controller).getPod is unused (U1000) (megacheck)
      make: *** [github.com/tczekajlo/kube-consul-register/controller/services] Error 1
    • Add error handlers
    • Remove unused varable and method
    1. warnings in controller factory:
    go test -race github.com/tczekajlo/kube-consul-register/metrics
    ?       github.com/tczekajlo/kube-consul-register/metrics       [no test files]
    cd /Users/arunvelsriram/go/src/github.com/tczekajlo/kube-consul-register/metrics; gometalinter --deadline  720s --vendor -D gotype -D dupl -D gocyclo -D gas -D errcheck
    controller.go:15:2:warning: comment on exported var PodSuccess should be of the form "PodSuccess ..." (golint)
    make: *** [github.com/tczekajlo/kube-consul-register/metrics] Error 1
    • Fix typo in comment
arunvelsriram commented 5 years ago

The build is failing for master version of go. It might be because of the go 1.11 module support https://github.com/alecthomas/gometalinter/issues/521