From 499adebaa1cacc3b29515ac156e4eb9019ea763f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Svantesson?= Date: Wed, 5 Jun 2024 12:34:46 +0200 Subject: [PATCH] chore: upgrade to go 1.22.3 also fixing linting related to jenkins-x/jx#8670 --- Makefile | 5 ++--- cmd/jenkins/main.go | 1 - cmd/poller/main.go | 3 +++ go.mod | 2 +- go.sum | 13 +++++++++++ hack/linter.sh | 8 +++---- hack/tools.go | 1 + .../v1alpha1/zz_generated.deepcopy.go | 1 + .../clientset/versioned/fake/register.go | 14 ++++++------ .../clientset/versioned/scheme/register.go | 14 ++++++------ pkg/clients/clients.go | 8 +++---- pkg/config/keeper/query_test.go | 1 + pkg/engines/jenkins/client.go | 4 +++- pkg/engines/jenkins/client_test.go | 2 +- pkg/engines/jenkins/controller.go | 3 ++- pkg/foghorn/controller_test.go | 6 ++--- pkg/genfiles/genfiles.go | 22 +++++++++---------- pkg/git/v2/client_factory.go | 6 ++--- pkg/gitattributes/gitattributes.go | 4 +++- pkg/gitattributes/pattern.go | 1 + pkg/jobutil/filter.go | 8 +++---- pkg/jobutil/jobutil_test.go | 2 +- pkg/keeper/keeper.go | 15 +++++++------ pkg/keeper/keeper_test.go | 6 ++--- pkg/keeper/pipelinerun_monitor.go | 3 ++- pkg/keeper/pipelinerun_monitor_test.go | 3 ++- pkg/keeper/status.go | 4 ++-- pkg/logrusutil/stackdriver/formatter_test.go | 15 ++++++------- pkg/plugins/approve/approve.go | 15 +++++++------ pkg/plugins/approve/approvers/owners.go | 16 +++++++------- pkg/plugins/cat/cat_test.go | 6 ++--- pkg/plugins/dog/dog_test.go | 6 ++--- pkg/plugins/help/help_test.go | 2 +- pkg/plugins/label/label_test.go | 2 +- pkg/plugins/lgtm/lgtm_test.go | 4 ++-- pkg/plugins/owners-label/owners-label_test.go | 2 +- pkg/plugins/pony/pony_test.go | 6 ++--- pkg/plugins/sigmention/sigmention_test.go | 2 +- pkg/plugins/trigger/periodic.go | 17 +++++++++----- pkg/plugins/trigger/periodic_test.go | 4 ++-- pkg/plugins/updateconfig/updateconfig_test.go | 2 +- pkg/poller/poller.go | 2 +- pkg/poller/poller_test.go | 2 +- pkg/repoowners/repoowners.go | 4 +++- pkg/repoowners/repoowners_test.go | 4 ++-- pkg/scmprovider/issues.go | 3 --- .../inrepo/load_pipelinerun_test.go | 2 +- pkg/triggerconfig/inrepo/params.go | 3 +-- pkg/triggerconfig/inrepo/uses_resolver.go | 5 +---- pkg/util/go_mod_tidy_hack.go | 1 + pkg/webhook/events.go | 2 +- pkg/webhook/webhook_test.go | 2 +- test/e2e/helpers.go | 4 ++-- test/e2e/tekton/tekton_test.go | 2 +- 54 files changed, 161 insertions(+), 134 deletions(-) diff --git a/Makefile b/Makefile index 3afa3c578..61bcc47ac 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,6 @@ GOTEST := $(GO) test REV := $(shell git rev-parse --short HEAD 2> /dev/null || echo 'unknown') VERSION ?= $(shell echo "$$(git for-each-ref refs/tags/ --count=1 --sort=-version:refname --format='%(refname:short)' 2>/dev/null)-dev+$(REV)" | sed 's/^v//') GO_LDFLAGS := -X $(PROJECT)/pkg/version.Version='$(VERSION)' -GO_DEPENDENCIES := $(call rwildcard,pkg/,*.go) $(call rwildcard,cmd/,*.go) .PHONY: all all: build test check docs ## Default rule, builds all binaries, runs tests and format checks @@ -123,12 +122,12 @@ clean: ## Deletes the generated build directories check: fmt lint sec ## Runs Go format check as well as security checks get-fmt-deps: - $(GO_NOMOD) get golang.org/x/tools/cmd/goimports + $(GO_NOMOD) install golang.org/x/tools/cmd/goimports .PHONY: importfmt importfmt: get-fmt-deps ## Checks the import format of the Go source files @echo "FORMATTING IMPORTS" - @goimports -w $(GO_DEPENDENCIES) + @goimports -w $(call rwildcard,,*.go) .PHONY: fmt ## Checks Go source files are formatted properly fmt: importfmt diff --git a/cmd/jenkins/main.go b/cmd/jenkins/main.go index 654fd9b82..83af0f2a0 100644 --- a/cmd/jenkins/main.go +++ b/cmd/jenkins/main.go @@ -230,7 +230,6 @@ func loadCerts(certFile, keyFile, caCertFile string) (*tls.Config, error) { tlsConfig.RootCAs = caCertPool } - tlsConfig.BuildNameToCertificate() return tlsConfig, nil } diff --git a/cmd/poller/main.go b/cmd/poller/main.go index eff0ba8c0..8db9532c4 100644 --- a/cmd/poller/main.go +++ b/cmd/poller/main.go @@ -297,6 +297,9 @@ func (o *options) notifier(hook *scm.WebhookWrapper) error { } req, err := http.NewRequest("POST", o.hookEndpoint, bytes.NewBuffer(data)) + if err != nil { + return errors.Wrapf(err, "failed to create hook request %#v for %s", data, o.hookEndpoint) + } req.Header.Set("Content-Type", "application/json") if o.hmacToken != "" { diff --git a/go.mod b/go.mod index 00c63e142..6ea5a4cc2 100644 --- a/go.mod +++ b/go.mod @@ -135,4 +135,4 @@ replace ( k8s.io/apimachinery => k8s.io/apimachinery v0.25.9 ) -go 1.19 +go 1.22.3 diff --git a/go.sum b/go.sum index d6c1f7471..dd9216edb 100644 --- a/go.sum +++ b/go.sum @@ -69,6 +69,7 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -93,6 +94,7 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudevents/sdk-go/v2 v2.12.0 h1:p1k+ysVOZtNiXfijnwB3WqZNA3y2cGOiKQygWkUHCEI= +github.com/cloudevents/sdk-go/v2 v2.12.0/go.mod h1:xDmKfzNjM8gBvjaF8ijFjM1VYOVUEeUfapHMUX1T5To= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -132,6 +134,7 @@ github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/zapr v1.2.3 h1:a9vnzlIBPQBBkeaR9IuMUfmVOrQlkoC4YfPoFkX3T7A= +github.com/go-logr/zapr v1.2.3/go.mod h1:eIauM6P8qSvTw5o2ez6UEAfGjQKrxQTl5EoK+Qa2oG4= github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= github.com/go-openapi/jsonreference v0.20.1 h1:FBLnyygC4/IZZr893oiomc9XaghoveYTrLC1F86HID8= @@ -150,6 +153,7 @@ github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQA github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE= +github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -228,6 +232,7 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU github.com/h2non/gock v1.0.9 h1:17gCehSo8ZOgEsFKpQgqHiR7VLyjxdAG3lkhVvO9QZU= github.com/h2non/gock v1.0.9/go.mod h1:CZMcB0Lg5IWnr9bF79pPMg9WeV6WumxQiUJ1UvdO1iE= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw= +github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -260,6 +265,7 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= +github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -269,6 +275,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -305,6 +312,7 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108 github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.1.6 h1:Fx2POJZfKRQcM1pH49qSZiYeu319wji004qX+GDovrU= +github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q= @@ -348,6 +356,7 @@ github.com/prometheus/statsd_exporter v0.21.0/go.mod h1:rbT83sZq2V+p73lHhPZfMc3M github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/shurcooL/githubv4 v0.0.0-20191102174205-af46314aec7b h1:Cocq9/ZZxCoiybhygOR7hX4E3/PkV8eNbd1AEcUvaHM= github.com/shurcooL/githubv4 v0.0.0-20191102174205-af46314aec7b/go.mod h1:hAF0iLZy4td2EX+/8Tw+4nodhlMrwN3HupfaXj3zkGo= github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f h1:tygelZueB1EtXkPI6mQ4o9DQ0+FKW41hTbunoXZCTqk= @@ -394,6 +403,7 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= +go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= @@ -441,6 +451,7 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -613,6 +624,7 @@ golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -718,6 +730,7 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY= +gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5 h1:E846t8CnR+lv5nE+VuiKTDG/v1U2stad0QzddfJC7kY= diff --git a/hack/linter.sh b/hack/linter.sh index cdeceac5f..50f2bb655 100755 --- a/hack/linter.sh +++ b/hack/linter.sh @@ -7,11 +7,11 @@ then exit 0 fi -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +linterVersion="$(golangci-lint --version | awk '{print $4}')" -if ! [ -x "$(command -v golangci-lint)" ]; then - echo "Installing GolangCI-Lint" - ${DIR}/install_golint.sh -b $GOPATH/bin v1.42.1 +if [[ ! "${linterVersion}" =~ ^1\.5[89] ]]; then + echo "Install GolangCI-Lint version 1.58 or 1.59" + exit 1 fi export GO111MODULE=on diff --git a/hack/tools.go b/hack/tools.go index 0a0d04f07..29f0bd155 100644 --- a/hack/tools.go +++ b/hack/tools.go @@ -1,3 +1,4 @@ +//go:build tools // +build tools package tools diff --git a/pkg/apis/lighthouse/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/lighthouse/v1alpha1/zz_generated.deepcopy.go index 9f98fa8cf..570a5a998 100644 --- a/pkg/apis/lighthouse/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/lighthouse/v1alpha1/zz_generated.deepcopy.go @@ -1,3 +1,4 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated // Code generated by deepcopy-gen. DO NOT EDIT. diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index 33d7530ed..eb6f6ebac 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -21,14 +21,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index 0cb39fefa..be53dcc80 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -21,14 +21,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/pkg/clients/clients.go b/pkg/clients/clients.go index f050b0fa4..337ac3bd3 100644 --- a/pkg/clients/clients.go +++ b/pkg/clients/clients.go @@ -45,10 +45,10 @@ func GetAPIClients() (tektonclient.Interface, kubeclient.Interface, clientset.In // GetConfig returns a rest.Config to be used for kubernetes client creation. // It does so in the following order: -// 1. Use the passed kubeconfig/masterURL. -// 2. Fallback to the KUBECONFIG environment variable. -// 3. Fallback to in-cluster config. -// 4. Fallback to the ~/.kube/config. +// 1. Use the passed kubeconfig/masterURL. +// 2. Fallback to the KUBECONFIG environment variable. +// 3. Fallback to in-cluster config. +// 4. Fallback to the ~/.kube/config. func GetConfig(masterURL, kubeconfig string) (*rest.Config, error) { if kubeconfig == "" { kubeconfig = os.Getenv("KUBECONFIG") diff --git a/pkg/config/keeper/query_test.go b/pkg/config/keeper/query_test.go index 55e9b3e48..3d85161b1 100644 --- a/pkg/config/keeper/query_test.go +++ b/pkg/config/keeper/query_test.go @@ -1,3 +1,4 @@ +//go:build unit // +build unit package keeper_test diff --git a/pkg/engines/jenkins/client.go b/pkg/engines/jenkins/client.go index af396cb76..cf3637997 100644 --- a/pkg/engines/jenkins/client.go +++ b/pkg/engines/jenkins/client.go @@ -119,7 +119,9 @@ type BuildQueryParams struct { // dryRun: mutating calls such as starting/aborting a build will be skipped. // tlsConfig: configures client transport if set, may be nil. // authConfig: configures the client to connect to Jenkins via basic auth/bearer token -// and optionally enables csrf protection +// +// and optionally enables csrf protection +// // logger: creates a standard logger if nil. // metrics: gathers prometheus metrics for the Jenkins client if set. func NewClient( diff --git a/pkg/engines/jenkins/client_test.go b/pkg/engines/jenkins/client_test.go index 8cf299fbe..3eb3ce800 100644 --- a/pkg/engines/jenkins/client_test.go +++ b/pkg/engines/jenkins/client_test.go @@ -343,7 +343,7 @@ func TestBuildCreate(t *testing.T) { } w.WriteHeader(testCase.statusCode) - w.Write([]byte(response)) + _, _ = w.Write([]byte(response)) } ts := httptest.NewServer(handler) diff --git a/pkg/engines/jenkins/controller.go b/pkg/engines/jenkins/controller.go index 63aa26cf1..b57ee31fe 100644 --- a/pkg/engines/jenkins/controller.go +++ b/pkg/engines/jenkins/controller.go @@ -20,9 +20,10 @@ import ( "bytes" "context" "fmt" - "k8s.io/utils/clock" "sync" + "k8s.io/utils/clock" + "github.com/jenkins-x/lighthouse/pkg/util" "github.com/pkg/errors" diff --git a/pkg/foghorn/controller_test.go b/pkg/foghorn/controller_test.go index c540ac30f..32fdd9af3 100644 --- a/pkg/foghorn/controller_test.go +++ b/pkg/foghorn/controller_test.go @@ -38,9 +38,9 @@ func TestReconcile(t *testing.T) { assert.NoError(t, err) defer func() { if oldToken != "" { - os.Setenv("GIT_TOKEN", oldToken) + _ = os.Setenv("GIT_TOKEN", oldToken) } else { - os.Unsetenv("GIT_TOKEN") + _ = os.Unsetenv("GIT_TOKEN") } }() configAgent := &config.Agent{} @@ -108,7 +108,7 @@ func TestReconcile(t *testing.T) { scheme := runtime.NewScheme() err = lighthousev1alpha1.AddToScheme(scheme) assert.NoError(t, err) - c := fake.NewFakeClientWithScheme(scheme, observedJob) + c := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(observedJob).Build() reconciler, err := NewLighthouseJobReconcilerWithConfig(c, scheme, ns, cfgMapWatcher, configAgent, pluginAgent) assert.NoError(t, err) diff --git a/pkg/genfiles/genfiles.go b/pkg/genfiles/genfiles.go index 50dd13dab..dee2fe1a9 100644 --- a/pkg/genfiles/genfiles.go +++ b/pkg/genfiles/genfiles.go @@ -21,25 +21,25 @@ limitations under the License. // begin with a `#` are ignored. A statement is a white-space delimited // key-value tuple. // -// statement = key val +// statement = key val // // where whitespace is ignored, and: // -// key = "path" | "file-name" | "path-prefix" | -// "file-prefix" | "paths-from-repo" +// key = "path" | "file-name" | "path-prefix" | +// "file-prefix" | "paths-from-repo" // // For example: // -// # Simple generated files config -// file-prefix zz_generated. -// file-name generated.pb.go +// # Simple generated files config +// file-prefix zz_generated. +// file-name generated.pb.go // // The statement's `key` specifies the type of the corresponding value: -// - "path": exact path to a single file -// - "file-name": exact leaf file name, regardless of path -// - "path-prefix": prefix match on the file path -// - "file-prefix": prefix match of the leaf filename (no path) -// - "paths-from-repo": load file paths from a file in repo +// - "path": exact path to a single file +// - "file-name": exact leaf file name, regardless of path +// - "path-prefix": prefix match on the file path +// - "file-prefix": prefix match of the leaf filename (no path) +// - "paths-from-repo": load file paths from a file in repo package genfiles import ( diff --git a/pkg/git/v2/client_factory.go b/pkg/git/v2/client_factory.go index 03b035375..7e8c669b3 100644 --- a/pkg/git/v2/client_factory.go +++ b/pkg/git/v2/client_factory.go @@ -25,7 +25,7 @@ import ( "time" "github.com/sirupsen/logrus" - utilpointer "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) // ClientFactory knows how to create clientFactory for repos @@ -114,9 +114,9 @@ func defaultClientFactoryOpts(cfo *ClientFactoryOpts) { if cfo.CacheDirBase == nil { switch runtime.GOOS { case "linux": - cfo.CacheDirBase = utilpointer.StringPtr("/var/tmp") + cfo.CacheDirBase = ptr.To("/var/tmp") default: - cfo.CacheDirBase = utilpointer.StringPtr("") + cfo.CacheDirBase = ptr.To("") } } if cfo.Censor == nil { diff --git a/pkg/gitattributes/gitattributes.go b/pkg/gitattributes/gitattributes.go index 1d24ffbce..d7f717f01 100644 --- a/pkg/gitattributes/gitattributes.go +++ b/pkg/gitattributes/gitattributes.go @@ -64,7 +64,9 @@ func NewGroup(gitAttributesContent func() ([]byte, error)) (*Group, error) { // Use load to read a .gitattributes file, and populate g with the commands. // Each line in gitattributes file is of form: -// pattern attr1 attr2 ... +// +// pattern attr1 attr2 ... +// // That is, a pattern followed by an attributes list, separated by whitespaces. func (g *Group) load(r io.Reader) error { s := bufio.NewScanner(r) diff --git a/pkg/gitattributes/pattern.go b/pkg/gitattributes/pattern.go index 39b7ea88c..840021835 100644 --- a/pkg/gitattributes/pattern.go +++ b/pkg/gitattributes/pattern.go @@ -37,6 +37,7 @@ type pattern struct { // The rules by which the pattern matches paths are the same as in .gitignore files (see https://git-scm.com/docs/gitignore), with a few exceptions: // - negative patterns are forbidden // - patterns that match a directory do not recursively match paths inside that directory +// // https://git-scm.com/docs/gitattributes func parsePattern(p string) (Pattern, error) { res := pattern{} diff --git a/pkg/jobutil/filter.go b/pkg/jobutil/filter.go index bbb777567..9ff884da6 100644 --- a/pkg/jobutil/filter.go +++ b/pkg/jobutil/filter.go @@ -35,10 +35,10 @@ var RetestRe = regexp.MustCompile(`(?m)^/(?:lh-)?retest\s*$`) var OkToTestRe = regexp.MustCompile(`(?m)^/(?:lh-)?ok-to-test\s*$`) // Filter digests a presubmit config to determine if: -// - we the presubmit matched the filter -// - we know that the presubmit is forced to run -// - what the default behavior should be if the presubmit -// runs conditionally and does not match trigger conditions +// - we the presubmit matched the filter +// - we know that the presubmit is forced to run +// - what the default behavior should be if the presubmit +// runs conditionally and does not match trigger conditions type Filter func(p job.Presubmit) (shouldRun bool, forcedToRun bool, defaultBehavior bool) // CommandFilter builds a filter for `/test foo` diff --git a/pkg/jobutil/jobutil_test.go b/pkg/jobutil/jobutil_test.go index 63334dd38..049cf2da1 100644 --- a/pkg/jobutil/jobutil_test.go +++ b/pkg/jobutil/jobutil_test.go @@ -499,7 +499,7 @@ func TestNewLighthouseJob(t *testing.T) { } for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { - os.Setenv("GIT_KIND", testCase.gitKind) + _ = os.Setenv("GIT_KIND", testCase.gitKind) pj := NewLighthouseJob(testCase.spec, testCase.labels, testCase.annotations) if actual, expected := pj.Spec, testCase.spec; !equality.Semantic.DeepEqual(actual, expected) { t.Errorf("%s: incorrect PipelineOptionsSpec created: %s", testCase.name, cmp.Diff(actual, expected)) diff --git a/pkg/keeper/keeper.go b/pkg/keeper/keeper.go index bbf22141d..05fc35f4e 100644 --- a/pkg/keeper/keeper.go +++ b/pkg/keeper/keeper.go @@ -119,11 +119,11 @@ type Action string // Constants for various actions the controller might take const ( Wait Action = "WAIT" - Trigger = "TRIGGER" - TriggerBatch = "TRIGGER_BATCH" - Merge = "MERGE" - MergeBatch = "MERGE_BATCH" - PoolBlocked = "BLOCKED" + Trigger Action = "TRIGGER" + TriggerBatch Action = "TRIGGER_BATCH" + Merge Action = "MERGE" + MergeBatch Action = "MERGE_BATCH" + PoolBlocked Action = "BLOCKED" ) // recordableActions is the subset of actions that we keep historical record of. @@ -929,7 +929,7 @@ func (c *DefaultController) pickBatch(sp subpool, cc contextChecker) ([]PullRequ if err != nil { return nil, err } - defer r.Clean() + defer r.Clean() //nolint: errcheck if err := r.Config("user.name", "prow"); err != nil { return nil, err } @@ -1164,8 +1164,9 @@ func tryMerge(mergeFunc func() error) (bool, error) { return false, detailedErr } else if _, ok = err.(scmprovider.UnmergablePRError); ok { return true, detailedErr + } else { + return true, err } - return true, err } // We ran out of retries. Return the last transient error. return true, err diff --git a/pkg/keeper/keeper_test.go b/pkg/keeper/keeper_test.go index 0f70a9995..f2cf98327 100644 --- a/pkg/keeper/keeper_test.go +++ b/pkg/keeper/keeper_test.go @@ -1362,8 +1362,8 @@ func TestTakeAction(t *testing.T) { if err != nil { t.Fatalf("Error making local git: %v", err) } - defer gc.Clean() - defer lg.Clean() + defer gc.Clean() //nolint: errcheck + defer lg.Clean() //nolint: errcheck if err := lg.MakeFakeRepo("o", "r"); err != nil { t.Fatalf("Error making fake repo: %v", err) } @@ -1522,7 +1522,7 @@ func TestServeHTTP(t *testing.T) { if err != nil { t.Errorf("GET error: %v", err) } - defer resp.Body.Close() + defer resp.Body.Close() //nolint: errcheck var pools []Pool if err := json.NewDecoder(resp.Body).Decode(&pools); err != nil { t.Fatalf("JSON decoding error: %v", err) diff --git a/pkg/keeper/pipelinerun_monitor.go b/pkg/keeper/pipelinerun_monitor.go index 56776682c..23e7bcaaf 100644 --- a/pkg/keeper/pipelinerun_monitor.go +++ b/pkg/keeper/pipelinerun_monitor.go @@ -4,10 +4,11 @@ import ( "context" "encoding/json" "fmt" - pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "reflect" "strings" + pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + jsonpatch "github.com/evanphx/json-patch" "github.com/pkg/errors" "github.com/sirupsen/logrus" diff --git a/pkg/keeper/pipelinerun_monitor_test.go b/pkg/keeper/pipelinerun_monitor_test.go index 31faa88db..a7dd671e3 100644 --- a/pkg/keeper/pipelinerun_monitor_test.go +++ b/pkg/keeper/pipelinerun_monitor_test.go @@ -2,10 +2,11 @@ package keeper import ( "context" - pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "strings" "testing" + pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" tektonfake "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/fake" diff --git a/pkg/keeper/status.go b/pkg/keeper/status.go index a058ab963..1a043bdfe 100644 --- a/pkg/keeper/status.go +++ b/pkg/keeper/status.go @@ -39,11 +39,11 @@ import ( const ( statusContext string = "keeper" - statusInPool = "In merge pool" + statusInPool string = "In merge pool" // statusNotInPool is a format string used when a PR is not in a keeper pool. // The '%s' field is populated with the reason why the PR is not in a // keeper pool or the empty string if the reason is unknown. See requirementDiff. - statusNotInPool = "Not mergeable.%s" + statusNotInPool string = "Not mergeable.%s" // StatusContextLabelEnvVar is the environment variable we look to for the overriding status context label. StatusContextLabelEnvVar = "LIGHTHOUSE_KEEPER_STATUS_CONTEXT_LABEL" diff --git a/pkg/logrusutil/stackdriver/formatter_test.go b/pkg/logrusutil/stackdriver/formatter_test.go index e6d8deade..0e3a5fb52 100644 --- a/pkg/logrusutil/stackdriver/formatter_test.go +++ b/pkg/logrusutil/stackdriver/formatter_test.go @@ -4,11 +4,10 @@ import ( "bytes" "encoding/json" "errors" + "testing" "github.com/stretchr/testify/require" - "testing" - "github.com/sirupsen/logrus" ) @@ -70,8 +69,8 @@ var formatterTests = []struct { }, "reportLocation": map[string]interface{}{ "filePath": "github.com/jenkins-x/lighthouse/pkg/logrusutil/stackdriver/formatter_test.go", - "lineNumber": 58.0, - "functionName": "glob..func2", + "lineNumber": 57.0, + "functionName": "init.func2", }, }, }, @@ -96,8 +95,8 @@ var formatterTests = []struct { }, "reportLocation": map[string]interface{}{ "filePath": "github.com/jenkins-x/lighthouse/pkg/logrusutil/stackdriver/formatter_test.go", - "lineNumber": 84.0, - "functionName": "glob..func3", + "lineNumber": 83.0, + "functionName": "init.func3", }, }, }, @@ -129,8 +128,8 @@ var formatterTests = []struct { }, "reportLocation": map[string]interface{}{ "filePath": "github.com/jenkins-x/lighthouse/pkg/logrusutil/stackdriver/formatter_test.go", - "lineNumber": 114.0, - "functionName": "glob..func4", + "lineNumber": 113.0, + "functionName": "init.func4", }, }, }, diff --git a/pkg/plugins/approve/approve.go b/pkg/plugins/approve/approve.go index 0cc05b257..2e16929c0 100644 --- a/pkg/plugins/approve/approve.go +++ b/pkg/plugins/approve/approve.go @@ -354,17 +354,18 @@ func findAssociatedIssue(body, org string) (int, error) { // The algorithm goes as: // - Initially, we build an approverSet // - Go through all comments in order of creation. -// - (Issue/PR comments, PR review comments, and PR review bodies are considered as comments) +// - (Issue/PR comments, PR review comments, and PR review bodies are considered as comments) // - If anyone said "/approve", add them to approverSet. // - If anyone said "/lgtm" AND LgtmActsAsApprove is enabled, add them to approverSet. // - If anyone created an approved review AND ReviewActsAsApprove is enabled, add them to approverSet. +// // - Then, for each file, we see if any approver of this file is in approverSet and keep track of files without approval // - An approver of a file is defined as: -// - Someone listed as an "approver" in an OWNERS file in the files directory OR -// - in one of the file's parent directories -// - Iff all files have been approved, the bot will add the "approved" label. -// - Iff a cancel command is found, that reviewer will be removed from the approverSet -// and the munger will remove the approved label if it has been applied +// - Someone listed as an "approver" in an OWNERS file in the files directory OR +// - in one of the file's parent directories +// - Iff all files have been approved, the bot will add the "approved" label. +// - Iff a cancel command is found, that reviewer will be removed from the approverSet +// and the munger will remove the approved label if it has been applied func handle(log *logrus.Entry, spc scmProviderClient, repo approvers.Repo, baseURL *url.URL, opts *plugins.Approve, pr *state) error { fetchErr := func(context string, err error) error { return fmt.Errorf("failed to get %s for %s/%s#%d: %v", context, pr.org, pr.repo, pr.number, err) @@ -387,7 +388,7 @@ func handle(log *logrus.Entry, spc scmProviderClient, repo approvers.Repo, baseU if strings.EqualFold(label.Name, labels.Approved) { hasApprovedLabel = true } - if opts.IgnoreUpdateBotLabel() && strings.ToLower(label.Name) == strings.ToLower(labels.UpdateBot) { + if opts.IgnoreUpdateBotLabel() && strings.EqualFold(label.Name, labels.UpdateBot) { log.Info("updatebot label found, skipping approval process") return nil } diff --git a/pkg/plugins/approve/approvers/owners.go b/pkg/plugins/approve/approvers/owners.go index 3d6c37e50..c259f272f 100644 --- a/pkg/plugins/approve/approvers/owners.go +++ b/pkg/plugins/approve/approvers/owners.go @@ -507,9 +507,9 @@ func (ap Approvers) AreFilesApproved() bool { // RequirementsMet returns a bool indicating whether the PR has met all approval requirements: // - all OWNERS files associated with the PR have been approved AND // EITHER -// - the munger config is such that an issue is not required to be associated with the PR -// - that there is an associated issue with the PR -// - an OWNER has indicated that the PR is trivial enough that an issue need not be associated with the PR +// - the munger config is such that an issue is not required to be associated with the PR +// - that there is an associated issue with the PR +// - an OWNER has indicated that the PR is trivial enough that an issue need not be associated with the PR func (ap Approvers) RequirementsMet() bool { return ap.AreFilesApproved() && (!ap.RequireIssue || ap.AssociatedIssue != 0 || len(ap.NoIssueApprovers()) != 0) } @@ -619,11 +619,11 @@ func (ap Approvers) GetQuotedCCs(providerType string) []string { // GetMessage returns the comment body that we want the approve plugin to display on PRs // The comment shows: -// - a list of approvers files (and links) needed to get the PR approved -// - a list of approvers files with strikethroughs that already have an approver's approval -// - a suggested list of people from each OWNERS files that can fully approve the PR -// - how an approver can indicate their approval -// - how an approver can cancel their approval +// - a list of approvers files (and links) needed to get the PR approved +// - a list of approvers files with strikethroughs that already have an approver's approval +// - a suggested list of people from each OWNERS files that can fully approve the PR +// - how an approver can indicate their approval +// - how an approver can cancel their approval func GetMessage(ap Approvers, linkURL *url.URL, org, repo, branch string, usePrefix bool, providerType string) *string { if linkURL == nil { return nil diff --git a/pkg/plugins/cat/cat_test.go b/pkg/plugins/cat/cat_test.go index d75918a11..c6dcf96cb 100644 --- a/pkg/plugins/cat/cat_test.go +++ b/pkg/plugins/cat/cat_test.go @@ -258,7 +258,7 @@ func TestHttpResponse(t *testing.T) { if s, ok := contentLength[r.URL.Path]; ok { body := "binary image" w.Header().Set("Content-Length", s) - io.WriteString(w, body) + _, _ = io.WriteString(w, body) } else { t.Errorf("Cannot find content length for %s", r.URL.Path) } @@ -331,9 +331,9 @@ Available variants: w.WriteHeader(code) } if r, ok := pathToResponse[r.URL.Path]; ok { - io.WriteString(w, r) + _, _ = io.WriteString(w, r) } else { - io.WriteString(w, validResponse) + _, _ = io.WriteString(w, validResponse) } })) defer ts.Close() diff --git a/pkg/plugins/dog/dog_test.go b/pkg/plugins/dog/dog_test.go index b3190fd07..8cca45ed5 100644 --- a/pkg/plugins/dog/dog_test.go +++ b/pkg/plugins/dog/dog_test.go @@ -105,7 +105,7 @@ func TestHttpResponse(t *testing.T) { if s, ok := contentLength[r.URL.Path]; ok { body := "binary image" w.Header().Set("Content-Length", s) - io.WriteString(w, body) + _, _ = io.WriteString(w, body) } else { t.Errorf("Cannot find content length for %s", r.URL.Path) } @@ -194,9 +194,9 @@ func TestHttpResponse(t *testing.T) { } ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r, ok := pathToResponse[r.URL.Path]; ok { - io.WriteString(w, r) + _, _ = io.WriteString(w, r) } else { - io.WriteString(w, validResponse) + _, _ = io.WriteString(w, validResponse) } })) defer ts.Close() diff --git a/pkg/plugins/help/help_test.go b/pkg/plugins/help/help_test.go index ce836d546..e73034087 100644 --- a/pkg/plugins/help/help_test.go +++ b/pkg/plugins/help/help_test.go @@ -196,7 +196,7 @@ func TestLabel(t *testing.T) { // Add initial labels for _, label := range tc.issueLabels { - fakeSCMProviderClient.AddLabel("org", "repo", 1, label, false) + _ = fakeSCMProviderClient.AddLabel("org", "repo", 1, label, false) } if len(tc.issueState) == 0 { diff --git a/pkg/plugins/label/label_test.go b/pkg/plugins/label/label_test.go index 4ad9e1a0f..b8aa781f3 100644 --- a/pkg/plugins/label/label_test.go +++ b/pkg/plugins/label/label_test.go @@ -514,7 +514,7 @@ func TestLabel(t *testing.T) { // Add initial labels for _, label := range tc.issueLabels { - fakeClient.AddLabel("org", "repo", 1, label, false) + _ = fakeClient.AddLabel("org", "repo", 1, label, false) } e := &scmprovider.GenericCommentEvent{ Action: scm.ActionCreate, diff --git a/pkg/plugins/lgtm/lgtm_test.go b/pkg/plugins/lgtm/lgtm_test.go index 2fd927556..c36c99e50 100644 --- a/pkg/plugins/lgtm/lgtm_test.go +++ b/pkg/plugins/lgtm/lgtm_test.go @@ -1115,7 +1115,7 @@ func TestAddTreeHashComment(t *testing.T) { commit := &scm.Commit{} commit.Tree.Sha = treeSHA fc.Commits[SHA] = commit - handle(true, pc, &fakeOwnersClient{}, rc, fakeClient, logrus.WithField("plugin", pluginName), &fakePruner{}) + _ = handle(true, pc, &fakeOwnersClient{}, rc, fakeClient, logrus.WithField("plugin", pluginName), &fakePruner{}) found := false for _, body := range fc.PullRequestCommentsAdded { if addLGTMLabelNotificationRe.MatchString(body) { @@ -1171,7 +1171,7 @@ func TestRemoveTreeHashComment(t *testing.T) { SCMProviderClient: fc, PullRequestComments: fc.PullRequestComments[101], } - handle(false, pc, &fakeOwnersClient{}, rc, fakeClient, logrus.WithField("plugin", pluginName), fp) + _ = handle(false, pc, &fakeOwnersClient{}, rc, fakeClient, logrus.WithField("plugin", pluginName), fp) found := false for _, body := range fc.PullRequestCommentsDeleted { if addLGTMLabelNotificationRe.MatchString(body) { diff --git a/pkg/plugins/owners-label/owners-label_test.go b/pkg/plugins/owners-label/owners-label_test.go index 09211d069..d7a5241b5 100644 --- a/pkg/plugins/owners-label/owners-label_test.go +++ b/pkg/plugins/owners-label/owners-label_test.go @@ -185,7 +185,7 @@ func TestHandle(t *testing.T) { // Add initial labels for _, label := range tc.prLabels { - fakeClient.AddLabel(basicPR.Base.Repo.Namespace, basicPR.Base.Repo.Name, basicPR.Number, label, true) + _ = fakeClient.AddLabel(basicPR.Base.Repo.Namespace, basicPR.Base.Repo.Name, basicPR.Number, label, true) } pre := &scm.PullRequestHook{ Action: scm.ActionOpen, diff --git a/pkg/plugins/pony/pony_test.go b/pkg/plugins/pony/pony_test.go index abd9b96fc..452037e4a 100644 --- a/pkg/plugins/pony/pony_test.go +++ b/pkg/plugins/pony/pony_test.go @@ -82,7 +82,7 @@ func TestHttpResponse(t *testing.T) { if s, ok := contentLength[r.URL.Path]; ok { body := "binary image" w.Header().Set("Content-Length", s) - io.WriteString(w, body) + _, _ = io.WriteString(w, body) } else { t.Errorf("Cannot find content length for %s", r.URL.Path) } @@ -193,9 +193,9 @@ func TestHttpResponse(t *testing.T) { if tc.expectNoTag && q != "" { t.Errorf("Expected no tag, but got %q", q) } - io.WriteString(w, tc.response) + _, _ = io.WriteString(w, tc.response) } else { - io.WriteString(w, validResponse) + _, _ = io.WriteString(w, validResponse) } })) defer ts.Close() diff --git a/pkg/plugins/sigmention/sigmention_test.go b/pkg/plugins/sigmention/sigmention_test.go index 3e86d4041..baede0b47 100644 --- a/pkg/plugins/sigmention/sigmention_test.go +++ b/pkg/plugins/sigmention/sigmention_test.go @@ -159,7 +159,7 @@ func TestSigMention(t *testing.T) { } // Add initial labels to issue. for _, label := range tc.issueLabels { - fakeClient.AddLabel("org", "repo", 1, label, false) + _ = fakeClient.AddLabel("org", "repo", 1, label, false) } e := &scmprovider.GenericCommentEvent{ Action: scm.ActionCreate, diff --git a/pkg/plugins/trigger/periodic.go b/pkg/plugins/trigger/periodic.go index 6df82bc06..0c0236654 100644 --- a/pkg/plugins/trigger/periodic.go +++ b/pkg/plugins/trigger/periodic.go @@ -124,6 +124,7 @@ func hasChanges(pe *scm.PushHook, agent plugins.Agent) bool { return false } +// PeriodicsInitialized returns false if somebody else has updated the configmap, so don't initialize periodics now func (pa *PeriodicAgent) PeriodicsInitialized(namespace string, kc kubeclient.Interface) bool { cmInterface := kc.CoreV1().ConfigMaps(namespace) cm, err := cmInterface.Get(context.TODO(), util.ProwConfigMapName, metav1.GetOptions{}) @@ -150,11 +151,7 @@ func (pa *PeriodicAgent) PeriodicsInitialized(namespace string, kc kubeclient.In cmApply.Data[initializedField] = "pending" cm.Data[initStartedField] = strconv.FormatInt(time.Now().Unix(), 10) _, err = cmInterface.Apply(context.TODO(), cmApply, metav1.ApplyOptions{FieldManager: "lighthouse"}) - if err != nil { - // Somebody else has updated the configmap, so don't initialize periodics now - return true - } - return false + return err != nil } func (pa *PeriodicAgent) InitializePeriodics(kc kubeclient.Interface, configAgent *config.Agent, fileBrowsers *filebrowser.FileBrowsers) { @@ -242,11 +239,15 @@ func (pa *PeriodicAgent) InitializePeriodics(kc kubeclient.Interface, configAgen deleteConfigMap(cmInterface, cm) } } - cmInterface.Apply(context.TODO(), + _, err := cmInterface.Apply(context.TODO(), (&applyv1.ConfigMapApplyConfiguration{}). WithName("config"). WithData(map[string]string{initializedField: "true"}), metav1.ApplyOptions{Force: true, FieldManager: "lighthouse"}) + if err != nil { + logrus.WithError(err). + Errorf("Initialisation of periodics is done, but persisting that failed") + } } func deleteConfigMap(cmInterface typedv1.ConfigMapInterface, cm *corev1.ConfigMap) { @@ -309,6 +310,10 @@ func (pa *PeriodicAgent) UpdatePeriodicsForRepo( pj := jobutil.NewLighthouseJob(jobutil.PeriodicSpec(l, p, refs), labels, p.Annotations) lighthouseData, err := json.Marshal(pj) + if err != nil { + l.WithError(err).Errorf("failed to create template lighthousejob for periodic %s in (%s/%s)", p.Name, org, repo) + continue + } // Only apply if any value have changed existingCm := getExistingConfigMap(p) diff --git a/pkg/plugins/trigger/periodic_test.go b/pkg/plugins/trigger/periodic_test.go index 4627d044c..c9eda1877 100644 --- a/pkg/plugins/trigger/periodic_test.go +++ b/pkg/plugins/trigger/periodic_test.go @@ -29,10 +29,10 @@ var kubeClient *kubefake.Clientset // TODO: test more cases func TestUpdatePeriodics(t *testing.T) { namespace, p := setupPeriodicsTest() - fileBrowsers, err := filebrowser.NewFileBrowsers(filebrowser.GitHubURL, fbfake.NewFakeFileBrowser("test_data", true)) + fileBrowsers, _ := filebrowser.NewFileBrowsers(filebrowser.GitHubURL, fbfake.NewFakeFileBrowser("test_data", true)) resolverCache := inrepo.NewResolverCache() fc := filebrowser.NewFetchCache() - cfg, err := inrepo.LoadTriggerConfig(fileBrowsers, fc, resolverCache, "testorg", "myapp", "") + cfg, _ := inrepo.LoadTriggerConfig(fileBrowsers, fc, resolverCache, "testorg", "myapp", "") agent := plugins.Agent{ Config: &config.Config{ diff --git a/pkg/plugins/updateconfig/updateconfig_test.go b/pkg/plugins/updateconfig/updateconfig_test.go index 488d85ab2..39bdbf506 100644 --- a/pkg/plugins/updateconfig/updateconfig_test.go +++ b/pkg/plugins/updateconfig/updateconfig_test.go @@ -1254,7 +1254,7 @@ func TestUpdateConfig(t *testing.T) { }, } if tc.existingComment != "" { - fspc.CreateComment("kubernetes", "kubernetes", basicPR.Number, true, tc.existingComment) + _ = fspc.CreateComment("kubernetes", "kubernetes", basicPR.Number, true, tc.existingComment) } fkc := fake.NewSimpleClientset(tc.existConfigMaps...) diff --git a/pkg/poller/poller.go b/pkg/poller/poller.go index e2272bb37..a540a6d51 100644 --- a/pkg/poller/poller.go +++ b/pkg/poller/poller.go @@ -35,7 +35,7 @@ type pollingController struct { } func (c *pollingController) ServeHTTP(w http.ResponseWriter, r *http.Request) { - w.Write([]byte("hello from lighthouse poller\n")) + _, _ = w.Write([]byte("hello from lighthouse poller\n")) } func NewPollingController(repositoryNames []string, gitServer string, scmClient *scm.Client, contextMatchPatternCompiled *regexp.Regexp, requireReleaseSuccess bool, fb filebrowser.Interface, notifier func(webhook *scm.WebhookWrapper) error) (*pollingController, error) { diff --git a/pkg/poller/poller_test.go b/pkg/poller/poller_test.go index 0fb33a5df..e4a83e05b 100644 --- a/pkg/poller/poller_test.go +++ b/pkg/poller/poller_test.go @@ -1,12 +1,12 @@ package poller_test import ( + "context" "fmt" "os/exec" "regexp" "strings" "testing" - "context" scmfake "github.com/jenkins-x/go-scm/scm/driver/fake" diff --git a/pkg/repoowners/repoowners.go b/pkg/repoowners/repoowners.go index f9c193be7..eab5033e8 100644 --- a/pkg/repoowners/repoowners.go +++ b/pkg/repoowners/repoowners.go @@ -201,6 +201,7 @@ func (c *Client) LoadRepoAliases(org, repo, base string) (RepoAliases, error) { if err != nil { return nil, fmt.Errorf("failed to clone %s: %v", cloneRef, err) } + //nolint:errcheck defer gitRepo.Clean() if err := gitRepo.Checkout(base); err != nil { return nil, err @@ -242,6 +243,7 @@ func (c *Client) LoadRepoOwners(org, repo, base string) (RepoOwner, error) { } else { gitRepo, err = c.git.Clone(cloneRef) if gitRepo != nil { + //nolint:errcheck defer gitRepo.Clean() } } @@ -639,7 +641,7 @@ func (o *RepoOwners) entriesForFile(path string, people map[string]map[*regexp.R if !o.enableMDYAML || !strings.HasSuffix(path, ".md") { // if path is a directory, this will remove the leaf directory, and returns "." for topmost dir d = filepath.Dir(d) - d = canonicalize(path) + d = canonicalize(d) } out := sets.NewString() diff --git a/pkg/repoowners/repoowners_test.go b/pkg/repoowners/repoowners_test.go index 092df7fe1..4969f8578 100644 --- a/pkg/repoowners/repoowners_test.go +++ b/pkg/repoowners/repoowners_test.go @@ -179,8 +179,8 @@ func getTestClient( }, // Clean up function func() { - git.Clean() - localGit.Clean() + _ = git.Clean() + _ = localGit.Clean() }, nil } diff --git a/pkg/scmprovider/issues.go b/pkg/scmprovider/issues.go index d05d7e2b1..f62b64879 100644 --- a/pkg/scmprovider/issues.go +++ b/pkg/scmprovider/issues.go @@ -195,7 +195,6 @@ func (c *Client) ListIssueComments(org, repo string, number int) ([]*scm.Comment func (c *Client) GetIssueLabels(org, repo string, number int, pr bool) ([]*scm.Label, error) { ctx := context.Background() fullName := c.repositoryName(org, repo) - var allLabels []*scm.Label var resp *scm.Response var labels []*scm.Label var err error @@ -213,7 +212,6 @@ func (c *Client) GetIssueLabels(org, repo string, number int, pr bool) ([]*scm.L return nil, fmt.Errorf("fail to list labels: %v, response: %v", err, resp) } firstRun = true - allLabels = append(allLabels, labels...) opts.Page++ } } @@ -223,7 +221,6 @@ func (c *Client) GetIssueLabels(org, repo string, number int, pr bool) ([]*scm.L return nil, fmt.Errorf("fail to list labels: %v, response: %v", err, resp) } firstRun = true - allLabels = append(allLabels, labels...) opts.Page++ } return labels, err diff --git a/pkg/triggerconfig/inrepo/load_pipelinerun_test.go b/pkg/triggerconfig/inrepo/load_pipelinerun_test.go index a4831c65e..11d73d5cd 100644 --- a/pkg/triggerconfig/inrepo/load_pipelinerun_test.go +++ b/pkg/triggerconfig/inrepo/load_pipelinerun_test.go @@ -33,7 +33,7 @@ func TestLoadPipelineRunTest(t *testing.T) { fileBrowser := fbfake.NewFakeFileBrowser("test_data", true) // lets use a custom version stream sha - os.Setenv("LIGHTHOUSE_VERSIONSTREAM_JENKINS_X_JX3_PIPELINE_CATALOG", "myversionstreamref") + _ = os.Setenv("LIGHTHOUSE_VERSIONSTREAM_JENKINS_X_JX3_PIPELINE_CATALOG", "myversionstreamref") require.NoError(t, err, "failed to get cwd") diff --git a/pkg/triggerconfig/inrepo/params.go b/pkg/triggerconfig/inrepo/params.go index 3d1e08fc1..626934f2a 100644 --- a/pkg/triggerconfig/inrepo/params.go +++ b/pkg/triggerconfig/inrepo/params.go @@ -37,7 +37,7 @@ func getParamsFromTasksResults(loc *UseLocation) map[string]bool { } // UseParametersAndResults adds the parameters from the used Task to the PipelineSpec if specified and the PipelineTask -func UseParametersAndResults(ctx context.Context, loc *UseLocation, uses *v1beta1.TaskSpec) error { +func UseParametersAndResults(ctx context.Context, loc *UseLocation, uses *v1beta1.TaskSpec) { parameterSpecs := uses.Params parameters := ToParams(parameterSpecs) results := uses.Results @@ -83,7 +83,6 @@ func UseParametersAndResults(ctx context.Context, loc *UseLocation, uses *v1beta } } } - return nil } // ToDefaultParams converts the param specs to default params diff --git a/pkg/triggerconfig/inrepo/uses_resolver.go b/pkg/triggerconfig/inrepo/uses_resolver.go index 1836c4a7f..d8de27b48 100644 --- a/pkg/triggerconfig/inrepo/uses_resolver.go +++ b/pkg/triggerconfig/inrepo/uses_resolver.go @@ -79,10 +79,7 @@ func (r *UsesResolver) UsesSteps(sourceURI string, taskName string, step tektonv *ts = *useTS ts.Steps = originalSteps - err = UseParametersAndResults(ctx, loc, useTS) - if err != nil { - return steps, errors.Wrapf(err, "failed to resolve parameters and results") - } + UseParametersAndResults(ctx, loc, useTS) return steps, nil } diff --git a/pkg/util/go_mod_tidy_hack.go b/pkg/util/go_mod_tidy_hack.go index c5e8a5fa1..47109342d 100644 --- a/pkg/util/go_mod_tidy_hack.go +++ b/pkg/util/go_mod_tidy_hack.go @@ -1,3 +1,4 @@ +//go:build modhack // +build modhack package util diff --git a/pkg/webhook/events.go b/pkg/webhook/events.go index b290c5c80..ec73c3f99 100644 --- a/pkg/webhook/events.go +++ b/pkg/webhook/events.go @@ -56,7 +56,7 @@ type Server struct { const failedCommentCoerceFmt = "Could not coerce %s event to a GenericCommentEvent. Unknown 'action': %q." -var zeroSha = regexp.MustCompile("\\b0{7,40}\\b") +var zeroSha = regexp.MustCompile(`\b0{7,40}\b`) func (s *Server) getPlugins(org, repo string) map[string]plugins.Plugin { return s.Plugins.GetPlugins(org, repo, s.ClientAgent.SCMProviderClient.Driver.String()) diff --git a/pkg/webhook/webhook_test.go b/pkg/webhook/webhook_test.go index 8cb90e45f..c717d2737 100644 --- a/pkg/webhook/webhook_test.go +++ b/pkg/webhook/webhook_test.go @@ -145,7 +145,7 @@ func (suite *WebhookTestSuite) SetupSuite() { gitClient, err := git.NewClient(serverURL, util.GitKind(configAgent.Config)) assert.NoError(t, err) user := util.GetBotName(configAgent.Config) - token, err := util.GetSCMToken(util.GitKind(configAgent.Config)) + token, _ := util.GetSCMToken(util.GitKind(configAgent.Config)) gitClient.SetCredentials(user, func() []byte { return []byte(token) }) diff --git a/test/e2e/helpers.go b/test/e2e/helpers.go index 3b16c48a8..2561a377b 100644 --- a/test/e2e/helpers.go +++ b/test/e2e/helpers.go @@ -656,9 +656,9 @@ func AttemptToLGTMOwnPullRequest(scmClient *scm.Client, pr *scm.PullRequest) err func AddReviewerToPullRequestWithChatOpsCommand(lhClient scmprovider.SCMClient, pr *scm.PullRequest, reviewer string) error { ginkgo.By(fmt.Sprintf("Adding the '/cc %s' comment and waiting for %s to be a reviewer", reviewer, reviewer)) repo := pr.Repository() - err := lhClient.CreateComment(repo.Namespace, repo.Name, pr.Number, true, fmt.Sprintf("/cc %s", reviewer)) + _ = lhClient.CreateComment(repo.Namespace, repo.Name, pr.Number, true, fmt.Sprintf("/cc %s", reviewer)) - err = ExpectThatPullRequestMatches(lhClient, pr.Number, repo.Namespace, repo.Name, func(request *scm.PullRequest) error { + err := ExpectThatPullRequestMatches(lhClient, pr.Number, repo.Namespace, repo.Name, func(request *scm.PullRequest) error { if len(request.Assignees) == 0 && len(request.Reviewers) == 0 { return fmt.Errorf("expected %s as reviewer, but no reviewers or assignees set on PR", reviewer) } diff --git a/test/e2e/tekton/tekton_test.go b/test/e2e/tekton/tekton_test.go index c980456bc..c536b69b9 100644 --- a/test/e2e/tekton/tekton_test.go +++ b/test/e2e/tekton/tekton_test.go @@ -321,7 +321,7 @@ func applyPipelineAndTask() error { if err != nil { return err } - defer os.RemoveAll(tmpDir) + defer os.RemoveAll(tmpDir) //nolint: errcheck pAndTFile := filepath.Join("test_data", "tekton", "pipelineAndTask.tmpl.yaml") rawPAndT, err := os.ReadFile(pAndTFile)