Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Fix golangci issues on master branch #78

Merged
merged 5 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ issues:
# (fill in the rest as needed)
exclude-rules:
- linters: [errcheck]
text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked"
text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv|Errorf|viper.BindPFlag). is not checked"
linters:
disable-all: true
enable:
Expand All @@ -27,7 +27,6 @@ linters:
- unparam
- ineffassign
- nakedret
- interfacer
- gocyclo
- dupl
- goimports
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
Expand Down Expand Up @@ -314,6 +315,7 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand Down
5 changes: 4 additions & 1 deletion pkg/ctxlog/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ func (ev Event) debugJSON(ctx context.Context, objectInfo interface{}) {

// treat JSON data as a string map and extract message
var result map[string]string
json.Unmarshal([]byte(jsonData), &result)
if err := json.Unmarshal([]byte(jsonData), &result); err != nil {
return
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would be helpful to print the error to debug if it fails?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it was silent for a reason, but then a few lines done it does print a debug msg. So why not here, too.

}

if msg, ok := result["message"]; ok {
log := ExtractLoggerWithOptions(ctx, zap.AddCallerSkip(1))
log.Debug(msg)
Expand Down
6 changes: 5 additions & 1 deletion pkg/kubeconfig/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ var _ = Describe("Checker", func() {
"Check method",
func(c checkCase) {
logger := zap.NewNop()
defer logger.Sync()
defer func() {
serr := logger.Sync()
Expect(serr).To(BeNil())
}()

c.checker.log = logger.Sugar()

actualErr := c.checker.Check(c.cfg)
Expand Down
6 changes: 5 additions & 1 deletion pkg/kubeconfig/getter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ var _ = Describe("Getter", func() {
"Get method",
func(c getCase) {
logger := zap.NewNop()
defer logger.Sync()
defer func() {
serr := logger.Sync()
Expect(serr).To(BeNil())
}()

c.getter.log = logger.Sugar()

actualConfig, actualErr := c.getter.Get(c.configPath)
Expand Down
4 changes: 3 additions & 1 deletion pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func newLogger(level string, options ...zap.Option) *zap.Logger {
}

l := zap.DebugLevel
l.Set(level)
if err := l.Set(level); err != nil {
golog.Fatalf("cannot sets the level for ZAP logger: %v", err)
}

cfg := zap.NewDevelopmentConfig()
cfg.Development = false
Expand Down
8 changes: 6 additions & 2 deletions pkg/webhook/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ func (f *Config) CreateValidationWebhookServerConfig(ctx context.Context, webhoo
}
}
ctxlog.Debugf(ctx, "Creating validation webhook config '%s'", config.Name)
f.client.Delete(ctx, config)
if err := f.client.Delete(ctx, config); err != nil && !apierrors.IsNotFound(err) {
ctxlog.Debugf(ctx, "Trying to deleting existing validatingWebhookConfiguration %s: %s", config.Name, err.Error())
}
return f.client.Create(ctx, config)
}

Expand Down Expand Up @@ -251,7 +253,9 @@ func (f *Config) CreateMutationWebhookServerConfig(ctx context.Context, webhooks
}

ctxlog.Debugf(ctx, "Creating mutating webhook config '%s'", config.Name)
f.client.Delete(ctx, &config)
if err := f.client.Delete(ctx, &config); err != nil && !apierrors.IsNotFound(err) {
ctxlog.Debugf(ctx, "Trying to deleting existing mutatingWebhookConfiguration %s: %s", config.Name, err.Error())
}
return f.client.Create(ctx, &config)
}

Expand Down