From 367156f60bc1715373cae95674f2b7cacce9350f Mon Sep 17 00:00:00 2001 From: Ved Ratan <82467006+VedRatan@users.noreply.github.com> Date: Mon, 3 Apr 2023 17:10:47 +0530 Subject: [PATCH] [Chore] Bump to Go 1.20 (#6683) * changed go version 1.19->1.20 Signed-off-by: Ved Ratan * updated go version in actions Signed-off-by: Ved Ratan * bumped golangci-lint Signed-off-by: Ved Ratan * fix Signed-off-by: Ved Ratan * fix conflicts Signed-off-by: Ved Ratan * fix Signed-off-by: Ved Ratan * fixed some linter issues Signed-off-by: Ved Ratan * fixed some linter issues Signed-off-by: Ved Ratan * possible fix Signed-off-by: Ved Ratan * fix Signed-off-by: Ved Ratan * small fix Signed-off-by: Ved Ratan * fix Signed-off-by: Ved Ratan --------- Signed-off-by: Ved Ratan Signed-off-by: Ved Ratan <82467006+VedRatan@users.noreply.github.com> --- .github/actions/setup-build-env/action.yaml | 2 +- .github/workflows/tests.yaml | 2 +- Makefile | 2 +- go.mod | 2 +- litmuschaos/pod_cpu_hog/pod_cpu_hog_test.go | 3 +-- pkg/clients/dclient/discovery_test.go | 3 +-- pkg/controllers/webhook/utils_test.go | 1 - pkg/engine/apicall/apiCall_test.go | 1 - pkg/engine/jmespath/functions.go | 11 ++++++++--- pkg/engine/variables/operator/allnotin_test.go | 1 - pkg/utils/jsonpointer/pointer.go | 4 ++-- pkg/webhooks/resource/handlers_test.go | 3 +-- 12 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.github/actions/setup-build-env/action.yaml b/.github/actions/setup-build-env/action.yaml index a9b7f0b7a0..858275085f 100644 --- a/.github/actions/setup-build-env/action.yaml +++ b/.github/actions/setup-build-env/action.yaml @@ -18,7 +18,7 @@ runs: git fetch --prune --unshallow - uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0 with: - go-version: ~1.19.4 + go-version: ~1.20.2 - uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d # v3.2.2 with: path: ~/go/pkg/mod diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index c45c7b2250..19217730ce 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -29,7 +29,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5 # v3.4.0 with: - version: v1.48 + version: v1.52.2 skip-cache: true - name: go fmt check run: make fmt-check diff --git a/Makefile b/Makefile index 5b8b0bca3d..d650a1a5bd 100644 --- a/Makefile +++ b/Makefile @@ -660,7 +660,7 @@ test: test-clean test-unit ## Clean tests cache then run unit tests .PHONY: test-clean test-clean: ## Clean tests cache @echo Clean test cache... >&2 - @go clean -testcache ./... + @go clean -testcache .PHONY: test-unit test-unit: test-clean $(GO_ACC) ## Run unit tests diff --git a/go.mod b/go.mod index fe1a8fb792..2eb129c57b 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/kyverno/kyverno -go 1.19 +go 1.20 require ( github.com/IGLOU-EU/go-wildcard v1.0.3 diff --git a/litmuschaos/pod_cpu_hog/pod_cpu_hog_test.go b/litmuschaos/pod_cpu_hog/pod_cpu_hog_test.go index 1d0895a047..898663ffa6 100644 --- a/litmuschaos/pod_cpu_hog/pod_cpu_hog_test.go +++ b/litmuschaos/pod_cpu_hog/pod_cpu_hog_test.go @@ -7,10 +7,9 @@ import ( "testing" "time" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) var ( diff --git a/pkg/clients/dclient/discovery_test.go b/pkg/clients/dclient/discovery_test.go index 31a29ba913..87cbbf8520 100644 --- a/pkg/clients/dclient/discovery_test.go +++ b/pkg/clients/dclient/discovery_test.go @@ -3,10 +3,9 @@ package dclient import ( "testing" - "k8s.io/apimachinery/pkg/runtime/schema" - "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" ) var ( diff --git a/pkg/controllers/webhook/utils_test.go b/pkg/controllers/webhook/utils_test.go index 8fef7300b9..571c1a69eb 100644 --- a/pkg/controllers/webhook/utils_test.go +++ b/pkg/controllers/webhook/utils_test.go @@ -6,7 +6,6 @@ import ( kyverno "github.com/kyverno/kyverno/api/kyverno/v1" "github.com/kyverno/kyverno/pkg/autogen" - "gotest.tools/assert" admissionregistrationv1 "k8s.io/api/admissionregistration/v1" "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/pkg/engine/apicall/apiCall_test.go b/pkg/engine/apicall/apiCall_test.go index 232769fa5e..47021176f5 100644 --- a/pkg/engine/apicall/apiCall_test.go +++ b/pkg/engine/apicall/apiCall_test.go @@ -11,7 +11,6 @@ import ( kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1" enginecontext "github.com/kyverno/kyverno/pkg/engine/context" "gotest.tools/assert" - apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" ) diff --git a/pkg/engine/jmespath/functions.go b/pkg/engine/jmespath/functions.go index 578861e962..7762c14ec8 100644 --- a/pkg/engine/jmespath/functions.go +++ b/pkg/engine/jmespath/functions.go @@ -2,6 +2,7 @@ package jmespath import ( "bytes" + "crypto/rand" "crypto/x509" "encoding/asn1" "encoding/base64" @@ -9,14 +10,12 @@ import ( "encoding/pem" "errors" "fmt" - "math/rand" "path/filepath" "reflect" "regexp" "sort" "strconv" "strings" - "time" trunc "github.com/aquilax/truncate" "github.com/blang/semver/v4" @@ -1033,7 +1032,13 @@ func jpRandom(arguments []interface{}) (interface{}, error) { if pattern == "" { return "", errors.New("no pattern provided") } - rand.Seed(time.Now().UnixNano()) + + b := make([]byte, 8) + _, err := rand.Read(b) + if err != nil { + return nil, err + } + ans, err := regen.Generate(pattern) if err != nil { return nil, err diff --git a/pkg/engine/variables/operator/allnotin_test.go b/pkg/engine/variables/operator/allnotin_test.go index 0c3aeb20cf..bd58bf808c 100644 --- a/pkg/engine/variables/operator/allnotin_test.go +++ b/pkg/engine/variables/operator/allnotin_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/go-logr/logr" - "github.com/kyverno/kyverno/pkg/engine/context" ) diff --git a/pkg/utils/jsonpointer/pointer.go b/pkg/utils/jsonpointer/pointer.go index 99e53e18ac..1916f6701c 100644 --- a/pkg/utils/jsonpointer/pointer.go +++ b/pkg/utils/jsonpointer/pointer.go @@ -97,10 +97,10 @@ func ParsePath(rawPath string) Pointer { sb.Reset() } - var pos int + var pos, width int var escaped, quoted bool - for i, width := 0, 0; i <= len(rawPath); i += width { + for i := 0; i <= len(rawPath); i += width { var r rune r, width = utf8.DecodeRuneInString(rawPath[i:]) if r == utf8.RuneError && width == 1 { diff --git a/pkg/webhooks/resource/handlers_test.go b/pkg/webhooks/resource/handlers_test.go index d264279434..969f234206 100644 --- a/pkg/webhooks/resource/handlers_test.go +++ b/pkg/webhooks/resource/handlers_test.go @@ -11,9 +11,8 @@ import ( "github.com/kyverno/kyverno/pkg/policycache" "gotest.tools/assert" v1 "k8s.io/api/admission/v1" - "k8s.io/apimachinery/pkg/runtime" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" ) var policyCheckLabel = `{