Skip to content

Commit

Permalink
upgrade go to 1.21 (#82) (#299)
Browse files Browse the repository at this point in the history
Signed-off-by: Xiangjing Li <[email protected]>
  • Loading branch information
xiangjingli authored Apr 23, 2024
1 parent 5a5a18b commit 26b27fa
Show file tree
Hide file tree
Showing 24 changed files with 424 additions and 629 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
RUN_ON: github
strategy:
matrix:
go: [ '1.20' ]
go: [ '1.21' ]
name: KinD tests
steps:
# Checks out a copy of your repository on the ubuntu-latest machine
Expand All @@ -34,7 +34,7 @@ jobs:
- name: Set up go version
uses: actions/setup-go@v3
with:
go-version: '~1.20' # The Go version to download (if necessary) and use.
go-version: '~1.21' # The Go version to download (if necessary) and use.
- run: go version

- name: Run e2e test on KinD cluster
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.ci.openshift.org/stolostron/builder:go1.20-linux AS builder
FROM registry.ci.openshift.org/stolostron/builder:go1.21-linux AS builder

WORKDIR go/src/open-cluster-management.io/multicloud-operators-channel
COPY . .
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile.prow
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.ci.openshift.org/stolostron/builder:go1.20-linux AS builder
FROM registry.ci.openshift.org/stolostron/builder:go1.21-linux AS builder

WORKDIR /go/src/github.com/stolostron/multicluster-operators-channel
COPY . .
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile.rhtap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:rhel_8_1.20 AS builder
FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:rhel_8_1.21 AS builder

WORKDIR go/src/open-cluster-management.io/multicloud-operators-channel
COPY . .
Expand Down
2 changes: 1 addition & 1 deletion build/run-code-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ gem install mdl
gem install awesome_bot

# Install golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(go env GOPATH)"/bin v1.51.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(go env GOPATH)"/bin v1.57.2

# Start lint task
make -f Makefile.prow lint-all
20 changes: 14 additions & 6 deletions cmd/manager/exec/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package exec

import (
"crypto/tls"
"errors"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -51,14 +52,14 @@ import (
"open-cluster-management.io/multicloud-operators-channel/pkg/controller"
"open-cluster-management.io/multicloud-operators-channel/pkg/utils"
chWebhook "open-cluster-management.io/multicloud-operators-channel/pkg/webhook"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
k8swebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
)

// Change below variables to serve metrics on different host or port.
var (
metricsHost = "0.0.0.0"
metricsPort = 8384
operatorMetricsPort = 8687
metricsHost = "0.0.0.0"
metricsPort = 8384
)

const (
Expand Down Expand Up @@ -136,17 +137,24 @@ func RunManager() {
"renewDeadline", options.LeaderElectionRenewDeadline,
"retryPeriod", options.LeaderElectionRetryPeriod)

webhookOption := k8swebhook.Options{}
webhookOption.TLSOpts = append(webhookOption.TLSOpts, func(config *tls.Config) {
config.MinVersion = chv1.TLSMinVersionInt
})
webhookServer := k8swebhook.NewServer(webhookOption)

// Create a new Cmd to provide shared dependencies and start components
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
Port: operatorMetricsPort,
Metrics: metricsserver.Options{
BindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
},
LeaderElection: enableLeaderElection,
LeaderElectionID: "multicloud-operators-channel-leader.open-cluster-management.io",
LeaderElectionNamespace: "kube-system",
LeaseDuration: &options.LeaderElectionLeaseDuration,
RenewDeadline: &options.LeaderElectionRenewDeadline,
RetryPeriod: &options.LeaderElectionRetryPeriod,
WebhookServer: &k8swebhook.Server{TLSMinVersion: chv1.TLSMinVersionString},
WebhookServer: webhookServer,
})

if err != nil {
Expand Down
57 changes: 36 additions & 21 deletions common/config/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
service:
# When updating this, also update the version stored in docker/build-tools/Dockerfile in the multicloudlab/tools repo.
golangci-lint-version: 1.51.x # use the fixed version to not introduce new linters unexpectedly
golangci-lint-version: 1.57.x # use the fixed version to not introduce new linters unexpectedly
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 20m
timeout: 20m

# which dirs to skip: they won't be analyzed;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but next dirs are always skipped independently
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs:
- genfiles$
- vendor$
- vbh

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files:
- ".*\\.pb\\.go"
- ".*\\.gen\\.go"
- vbh

linters:
enable-all: true
disable:
Expand Down Expand Up @@ -58,17 +39,22 @@ linters:
- gosec
- ifshort
- ineffassign
- interfacebloat
- interfacer
- ireturn
- loggercheck
- maintidx
- maligned
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nosnakecase
- nonamedreturns
- nosnakecase
- paralleltest
- prealloc
- predeclared
Expand All @@ -81,13 +67,30 @@ linters:
- tenv
- testpackage
- thelper
- usestdlibvars
- varcheck
- varnamelen
- wastedassign
- wrapcheck
- inamedparam
- revive
- mirror
- godox
fast: false

linters-settings:
testifylint:
disable:
- require-error
- expected-actual
perfsprint:
errorf: false
sprintf1: false
strconcat: false
wsl:
allow-assign-and-anything: true
strict-append: false

errcheck:
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
Expand All @@ -108,7 +111,7 @@ linters-settings:
min-confidence: 0.0
gocognit:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 80
min-complexity: 200
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
Expand Down Expand Up @@ -210,6 +213,7 @@ linters-settings:
# - unnamedResult
# - wrapperFunc


issues:
# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
Expand All @@ -225,6 +229,17 @@ issues:
- errcheck
- maligned

skip-dirs:
- genfiles$
- vendor$
- vbh

skip-files:
- ".*\\.pb\\.go"
- ".*\\.gen\\.go"
- ".*.helmrelease.*\\.go"
- ".*.ansiblejob.*\\.go"

# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
# excluded by default patterns execute `golangci-lint run --help`.
Expand Down
2 changes: 1 addition & 1 deletion common/scripts/lint_go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.51.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.57.2

export GOLANGCI_LINT_CACHE=/tmp/golangci-cache
rm -rf $GOLANGCI_LINT_CACHE
Expand Down
Loading

0 comments on commit 26b27fa

Please sign in to comment.