This is an automated email from the ASF dual-hosted git repository.

wilfreds pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git


The following commit(s) were added to refs/heads/master by this push:
     new fdd33d22 [YUNIKORN-3074] Upgrade Golangci-lint to version 2.1.6 (#1020)
fdd33d22 is described below

commit fdd33d229f76db683d4718ae3881969130bc2132
Author: Dennis Huang <[email protected]>
AuthorDate: Tue Jul 22 13:31:11 2025 +1000

    [YUNIKORN-3074] Upgrade Golangci-lint to version 2.1.6 (#1020)
    
    - Update Golangci-lint version in makefile
    - Migrate config to v2
    - Fix Golangci-lint run errors
    
    Closes: #1020
    
    Signed-off-by: Wilfred Spiegelenburg <[email protected]>
---
 .golangci.yml                              | 105 ++++++++++++++---------------
 Makefile                                   |   2 +-
 pkg/common/configs/configs_test.go         |   2 +-
 pkg/common/configs/configvalidator.go      |   2 +-
 pkg/common/configs/configvalidator_test.go |   4 +-
 pkg/common/errors.go                       |   2 +-
 pkg/examples/simple_example.go             |  10 +++
 pkg/metrics/init.go                        |   1 +
 pkg/scheduler/objects/utilities_test.go    |   5 +-
 pkg/scheduler/partition_test.go            |   1 +
 pkg/scheduler/placement/placement.go       |   6 +-
 pkg/scheduler/placement/placement_test.go  |   6 +-
 pkg/scheduler/tests/smoke_test.go          |   1 +
 pkg/webservice/handlers_test.go            |   6 +-
 14 files changed, 82 insertions(+), 71 deletions(-)

diff --git a/.golangci.yml b/.golangci.yml
index 5ebc8f00..b328aec0 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -17,52 +17,52 @@
 # under the License.
 
 # options for analysis running
+version: "2"
 run:
   issues-exit-code: 1
   modules-download-mode: readonly
-  timeout: 5m
-
-# settings of specific linters
-linters-settings:
-  errcheck:
-    check-type-assertions: true
-    check-blank: true
-  revive:
-    confidence: 0.8
-  gofmt:
-    simplify: true
-  goimports:
-    local-prefixes: github.com/apache/yunikorn
-  govet:
-    shadow: true
-  funlen:
-    lines: 120
-    statements: 80
-  depguard:
-    rules:
-      main:
-        files:
-          - $all
-        deny:
-          - pkg: "github.com/sirupsen/logrus"
-            desc: "logging is standardised via yunikorn logger and zap"
-          - pkg: "github.com/stretchr/testify"
-            desc: "test assertions must use gotest.tools/v3/assert"
-
-# linters to use
 linters:
-  disable-all: true
-  fast: false
+  settings:
+    errcheck:
+      check-type-assertions: true
+      check-blank: true
+    revive:
+      confidence: 0.8
+    govet:
+      enable:
+        - shadow
+    funlen:
+      lines: 120
+      statements: 80
+    depguard:
+      rules:
+        main:
+          files:
+            - $all
+          deny:
+            - pkg: github.com/sirupsen/logrus
+              desc: logging is standardised via yunikorn logger and zap
+            - pkg: github.com/stretchr/testify
+              desc: test assertions must use gotest.tools/v3/assert
+  exclusions:
+    generated: lax
+    presets:
+      - comments
+      - common-false-positives
+      - legacy
+      - std-error-handling
+    paths:
+      - third_party$
+      - builtin$
+      - examples$
+  default: none
   enable:
     - errcheck
     - unused
     - staticcheck
-    - gosimple
     - ineffassign
     - funlen
     - revive
-    - gofmt
-    - goimports
     - govet
     - goconst
     - depguard
@@ -72,26 +72,23 @@ linters:
     - gosec
     - dogsled
     - whitespace
-
 issues:
-  exclude-use-default: true
-
-  # Maximum issues count per one linter. Set to 0 to disable. Default is 50.
   max-issues-per-linter: 0
-
-  # Maximum count of issues with the same text. Set to 0 to disable. Default 
is 3.
   max-same-issues: 0
-
-  # Show only new issues: if there are unstaged changes or untracked files,
-  # only those changes are analyzed, else only changes in HEAD~ are analyzed.
-  # It's a super-useful option for integration of golangci-lint into existing
-  # large codebase. It's not practical to fix all existing issues at the moment
-  # of integration: much better don't allow issues in new code.
-  # Default is false.
   new: false
-
-  # Show only new issues created after git revision `REV`
-  # new-from-rev: REV
-
-  # Show only new issues created in git patch with set file path.
-  # new-from-patch: path/to/patch/file
+formatters:
+  enable:
+    - gofmt
+    - goimports
+  settings:
+    gofmt:
+      simplify: true
+    goimports:
+      local-prefixes:
+        - github.com/apache/yunikorn
+  exclusions:
+    generated: lax
+    paths:
+      - third_party$
+      - builtin$
+      - examples$
diff --git a/Makefile b/Makefile
index 8031f7c5..80a57f0b 100644
--- a/Makefile
+++ b/Makefile
@@ -98,7 +98,7 @@ endif
 endif
 
 # golangci-lint
-GOLANGCI_LINT_VERSION=1.63.4
+GOLANGCI_LINT_VERSION=2.1.6
 GOLANGCI_LINT_PATH=$(TOOLS_DIR)/golangci-lint-v$(GOLANGCI_LINT_VERSION)
 GOLANGCI_LINT_BIN=$(GOLANGCI_LINT_PATH)/golangci-lint
 
GOLANGCI_LINT_ARCHIVE=golangci-lint-$(GOLANGCI_LINT_VERSION)-$(OS)-$(EXEC_ARCH).tar.gz
diff --git a/pkg/common/configs/configs_test.go 
b/pkg/common/configs/configs_test.go
index 3b688f57..ba49c3c1 100644
--- a/pkg/common/configs/configs_test.go
+++ b/pkg/common/configs/configs_test.go
@@ -42,7 +42,7 @@ func TestConfigMap(t *testing.T) {
 func TestCallback(t *testing.T) {
        defer RemoveConfigMapCallback("test-callback")
 
-       var callbackReceived bool = false
+       var callbackReceived bool
        AddConfigMapCallback("test-callback", func() {
                callbackReceived = true
        })
diff --git a/pkg/common/configs/configvalidator.go 
b/pkg/common/configs/configvalidator.go
index 7718436a..76b537f7 100644
--- a/pkg/common/configs/configvalidator.go
+++ b/pkg/common/configs/configvalidator.go
@@ -677,7 +677,7 @@ func checkQueues(queue *QueueConfig, level int) error {
 
 func IsQueueNameValid(queueName string) error {
        if !QueueNameRegExp.MatchString(queueName) {
-               return common.InvalidQueueName
+               return common.ErrorInvalidQueueName
        }
        return nil
 }
diff --git a/pkg/common/configs/configvalidator_test.go 
b/pkg/common/configs/configvalidator_test.go
index f584090a..4d0c6495 100644
--- a/pkg/common/configs/configvalidator_test.go
+++ b/pkg/common/configs/configvalidator_test.go
@@ -2296,7 +2296,7 @@ func TestCheckQueues(t *testing.T) { //nolint:funlen
                                },
                        },
                        level:            0,
-                       expectedErrorMsg: common.InvalidQueueName.Error(),
+                       expectedErrorMsg: common.ErrorInvalidQueueName.Error(),
                },
                {
                        name: "Invalid Child Queue Name With Special Character",
@@ -2309,7 +2309,7 @@ func TestCheckQueues(t *testing.T) { //nolint:funlen
                                },
                        },
                        level:            0,
-                       expectedErrorMsg: common.InvalidQueueName.Error(),
+                       expectedErrorMsg: common.ErrorInvalidQueueName.Error(),
                },
                {
                        name: "Valid Multiple Queues",
diff --git a/pkg/common/errors.go b/pkg/common/errors.go
index 7e28426b..c54daa7c 100644
--- a/pkg/common/errors.go
+++ b/pkg/common/errors.go
@@ -22,7 +22,7 @@ import "errors"
 
 var (
        // InvalidQueueName returned when queue name is invalid
-       InvalidQueueName = errors.New("invalid queue name, max 64 characters 
consisting of alphanumeric characters and '-', '_', '#', '@', '/', ':' allowed")
+       ErrorInvalidQueueName = errors.New("invalid queue name, max 64 
characters consisting of alphanumeric characters and '-', '_', '#', '@', '/', 
':' allowed")
        // ErrorReservingAlloc returned when an ask that is allocated tries to 
reserve a node.
        ErrorReservingAlloc = errors.New("ask already allocated, no reservation 
allowed")
        // ErrorDuplicateReserve returned when the same reservation already 
exists on the application
diff --git a/pkg/examples/simple_example.go b/pkg/examples/simple_example.go
index 0ca1cd4b..8e9c90dd 100644
--- a/pkg/examples/simple_example.go
+++ b/pkg/examples/simple_example.go
@@ -25,6 +25,7 @@ import (
        "github.com/apache/yunikorn-scheduler-interface/lib/go/si"
 )
 
+// nolint:unused
 type exampleRMCallback struct {
        mock.ResourceManagerCallback
        acceptedApplications map[string]bool
@@ -37,6 +38,7 @@ type exampleRMCallback struct {
        locking.RWMutex
 }
 
+// nolint:unused
 func (m *exampleRMCallback) UpdateAllocation(response *si.AllocationResponse) 
error {
        m.Lock()
        defer m.Unlock()
@@ -58,6 +60,7 @@ func (m *exampleRMCallback) UpdateAllocation(response 
*si.AllocationResponse) er
        return nil
 }
 
+// nolint:unused
 func (m *exampleRMCallback) UpdateApplication(response 
*si.ApplicationResponse) error {
        m.Lock()
        defer m.Unlock()
@@ -73,6 +76,7 @@ func (m *exampleRMCallback) UpdateApplication(response 
*si.ApplicationResponse)
        return nil
 }
 
+// nolint:unused
 func (m *exampleRMCallback) UpdateNode(response *si.NodeResponse) error {
        m.Lock()
        defer m.Unlock()
@@ -88,6 +92,7 @@ func (m *exampleRMCallback) UpdateNode(response 
*si.NodeResponse) error {
        return nil
 }
 
+// nolint:unused
 func newExampleRMCallback() *exampleRMCallback {
        return &exampleRMCallback{
                acceptedApplications: make(map[string]bool),
@@ -99,6 +104,7 @@ func newExampleRMCallback() *exampleRMCallback {
        }
 }
 
+//nolint:unused
 func exampleOfRunYourOwnRM() {
        // Start all tests
        serviceContext := entrypoint.StartAllServices()
@@ -223,4 +229,8 @@ partitions:
                },
                RmID: "rm:123",
        })
+
+       if err != nil {
+               panic(err)
+       }
 }
diff --git a/pkg/metrics/init.go b/pkg/metrics/init.go
index ec370abf..18b4a2e4 100644
--- a/pkg/metrics/init.go
+++ b/pkg/metrics/init.go
@@ -110,6 +110,7 @@ func formatMetricName(metricName string) string {
        newBytes := make([]byte, len(metricName))
        for i := 0; i < len(metricName); i++ {
                b := metricName[i]
+               // nolint: staticcheck
                if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == 
'_' || b == ':' || (b >= '0' && b <= '9')) {
                        newBytes[i] = MetricNameInvalidByteReplacement
                } else {
diff --git a/pkg/scheduler/objects/utilities_test.go 
b/pkg/scheduler/objects/utilities_test.go
index 6d91a0b3..2df468c8 100644
--- a/pkg/scheduler/objects/utilities_test.go
+++ b/pkg/scheduler/objects/utilities_test.go
@@ -315,9 +315,10 @@ func assertAllocationLog(t *testing.T, ask *Allocation) {
        preemptionPreconditionsFailed := false
        PreemptionDoesNotHelp := false
        for _, l := range log {
-               if l.Message == common.PreemptionPreconditionsFailed {
+               switch l.Message {
+               case common.PreemptionPreconditionsFailed:
                        preemptionPreconditionsFailed = true
-               } else if l.Message == common.PreemptionDoesNotHelp {
+               case common.PreemptionDoesNotHelp:
                        PreemptionDoesNotHelp = true
                }
        }
diff --git a/pkg/scheduler/partition_test.go b/pkg/scheduler/partition_test.go
index a01d4599..fd734c2f 100644
--- a/pkg/scheduler/partition_test.go
+++ b/pkg/scheduler/partition_test.go
@@ -1689,6 +1689,7 @@ func TestRequiredNodeReservation(t *testing.T) {
        assert.Equal(t, len(reservations), 2, "node should have two 
reservations")
        _, _, resAsk = reservations[0].GetObjects()
        _, _, resAsk2 := reservations[1].GetObjects()
+       // nolint: staticcheck
        if !((resAsk.GetAllocationKey() == allocKey3 && 
resAsk2.GetAllocationKey() == allocKey2) ||
                (resAsk2.GetAllocationKey() == allocKey3 && 
resAsk.GetAllocationKey() == allocKey2)) {
                t.Fatal("missing reservation on the node")
diff --git a/pkg/scheduler/placement/placement.go 
b/pkg/scheduler/placement/placement.go
index c6c6d420..dd18b29f 100644
--- a/pkg/scheduler/placement/placement.go
+++ b/pkg/scheduler/placement/placement.go
@@ -33,8 +33,8 @@ import (
        "github.com/apache/yunikorn-core/pkg/webservice/dao"
 )
 
-// RejectedError is the standard error returned if placement has failed
-var RejectedError = errors.New("application rejected: no placement rule 
matched")
+// ErrorRejected is the standard error returned if placement has failed
+var ErrorRejected = errors.New("application rejected: no placement rule 
matched")
 
 type AppPlacementManager struct {
        rules   []rule
@@ -209,7 +209,7 @@ func (m *AppPlacementManager) PlaceApplication(app 
*objects.Application) error {
        // no more rules to check no queueName found reject placement
        if queueName == "" {
                app.SetQueuePath("")
-               return RejectedError
+               return ErrorRejected
        }
        // Add the queue into the application, overriding what was submitted
        app.SetQueuePath(queueName)
diff --git a/pkg/scheduler/placement/placement_test.go 
b/pkg/scheduler/placement/placement_test.go
index 0d488d68..e627220f 100644
--- a/pkg/scheduler/placement/placement_test.go
+++ b/pkg/scheduler/placement/placement_test.go
@@ -413,7 +413,7 @@ partitions:
                        app := newApplication("app1", "default", tt.queue, 
tt.user, tt.tags, nil, "")
                        err = man.PlaceApplication(app)
                        if tt.placed == "" {
-                               assert.Assert(t, errors.Is(err, RejectedError), 
"unexpected error or no error returned")
+                               assert.Assert(t, errors.Is(err, ErrorRejected), 
"unexpected error or no error returned")
                        } else {
                                assert.NilError(t, err, "unexpected placement 
failure")
                                assert.Equal(t, tt.placed, app.GetQueuePath(), 
"incorrect queue set")
@@ -471,7 +471,7 @@ partitions:
                        app := newApplication("app1", "default", tt.queue, 
tt.user, tt.tags, nil, "")
                        err = man.PlaceApplication(app)
                        if tt.placed == "" {
-                               assert.Assert(t, errors.Is(err, RejectedError), 
"unexpected error or no error returned")
+                               assert.Assert(t, errors.Is(err, ErrorRejected), 
"unexpected error or no error returned")
                        } else {
                                assert.NilError(t, err, "unexpected placement 
failure")
                                assert.Equal(t, tt.placed, app.GetQueuePath(), 
"incorrect queue set")
@@ -540,7 +540,7 @@ partitions:
                        app := newApplication("app1", "default", tt.queue, 
tt.user, tt.tags, nil, "")
                        err = man1.PlaceApplication(app)
                        if tt.placed == "" {
-                               assert.Assert(t, errors.Is(err, RejectedError), 
"unexpected error or no error returned")
+                               assert.Assert(t, errors.Is(err, ErrorRejected), 
"unexpected error or no error returned")
                        } else {
                                assert.NilError(t, err, "unexpected placement 
failure")
                                assert.Equal(t, tt.placed, app.GetQueuePath(), 
"incorrect queue set")
diff --git a/pkg/scheduler/tests/smoke_test.go 
b/pkg/scheduler/tests/smoke_test.go
index 97f6a713..e5660e67 100644
--- a/pkg/scheduler/tests/smoke_test.go
+++ b/pkg/scheduler/tests/smoke_test.go
@@ -1170,6 +1170,7 @@ partitions:
        node2Alloc := 
ms.scheduler.GetClusterContext().GetPartition(partition).GetNode("node-2:1234").GetAllocatedResource().Resources[siCommon.Memory]
        // we do not know which node was chosen so we need to check:
        // node1 == 90 && node2 == 0  || node1 == 0 && node2 == 90
+       // nolint: staticcheck
        if !(node1Alloc == 90000000 && node2Alloc == 0) && !(node1Alloc == 0 && 
node2Alloc == 90000000) {
                t.Errorf("allocation not contained on one: node1 = %d, node2 = 
%d", node1Alloc, node2Alloc)
        }
diff --git a/pkg/webservice/handlers_test.go b/pkg/webservice/handlers_test.go
index 7702dea7..ccca1fe6 100644
--- a/pkg/webservice/handlers_test.go
+++ b/pkg/webservice/handlers_test.go
@@ -1999,7 +1999,7 @@ func assertQueueInvalid(t *testing.T, resp 
*MockResponseWriter, invalidQueuePath
        err := json.Unmarshal(resp.outputBytes, &errInfo)
        assert.NilError(t, err, unmarshalError)
        assert.Equal(t, http.StatusBadRequest, resp.statusCode, statusCodeError)
-       assert.Equal(t, errInfo.Message, common.InvalidQueueName.Error(), 
jsonMessageError)
+       assert.Equal(t, errInfo.Message, common.ErrorInvalidQueueName.Error(), 
jsonMessageError)
        assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
 }
 
@@ -2086,7 +2086,7 @@ func TestValidateQueue(t *testing.T) {
 
        invalidQueuePath := "root.test.test123!"
        err1 := validateQueue(invalidQueuePath)
-       assert.Error(t, err1, common.InvalidQueueName.Error())
+       assert.Error(t, err1, common.ErrorInvalidQueueName.Error())
 
        err2 := validateQueue("root")
        assert.NilError(t, err2, "Queue path is correct but still throwing 
error.")
@@ -2833,7 +2833,7 @@ func verifyStateDumpJSON(t *testing.T, aggregated 
*AggregatedStateInfo, partitio
        assert.Check(t, len(aggregated.ClusterInfo) > 0)
        assert.Check(t, len(aggregated.Queues) == 1, "should only have root 
queue")
        assert.Check(t, len(aggregated.LogLevel) > 0)
-       assert.Check(t, len(aggregated.Config.SchedulerConfig.Partitions) == 
partitionCount, "incorrect partition count")
+       assert.Check(t, len(aggregated.Config.Partitions) == partitionCount, 
"incorrect partition count")
        assert.Check(t, len(aggregated.Config.Extra) > 0)
        assert.Check(t, aggregated.RMDiagnostics["empty"] != nil, "expected no 
RM registered for diagnostics")
        assert.Check(t, len(aggregated.PlacementRules) == partitionCount, 
"incorrect partition count")


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to