This is an automated email from the ASF dual-hosted git repository. ccondit pushed a commit to branch branch-1.6 in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git
The following commit(s) were added to refs/heads/branch-1.6 by this push: new a5638656 [YUNIKORN-3029] update golangci-lint for go 1.23 (#1013) a5638656 is described below commit a56386569554c46e8e919c6c69a23b99e06e41f6 Author: kaichiachen <kaichia...@gmail.com> AuthorDate: Fri Feb 21 15:59:35 2025 -0600 [YUNIKORN-3029] update golangci-lint for go 1.23 (#1013) Closes: #1013 Signed-off-by: Craig Condit <ccon...@apache.org> (cherry picked from commit 621c1849190b72fb622417967d61b082ce6a34dc) --- .go_version | 2 +- .golangci.yml | 1 - Makefile | 2 +- go.mod | 2 +- pkg/common/configs/configvalidator.go | 2 +- pkg/common/resources/resources.go | 3 ++- pkg/log/logger.go | 12 +++++++----- pkg/log/logger_test.go | 3 +++ pkg/scheduler/objects/application_state_test.go | 2 +- pkg/scheduler/objects/node_collection_test.go | 6 +++++- pkg/scheduler/objects/node_iterator.go | 8 +++++--- pkg/scheduler/objects/preemption.go | 2 +- pkg/scheduler/objects/queue.go | 4 ++-- pkg/scheduler/ugm/manager_test.go | 9 +++++---- pkg/scheduler/ugm/queue_tracker.go | 2 +- pkg/scheduler/utilities_test.go | 16 ++++++++++++---- 16 files changed, 48 insertions(+), 28 deletions(-) diff --git a/.go_version b/.go_version index e342dea0..193d1403 100644 --- a/.go_version +++ b/.go_version @@ -1 +1 @@ -1.22 \ No newline at end of file +1.23 \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 07bc5b29..5ebc8f00 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,7 +19,6 @@ # options for analysis running run: issues-exit-code: 1 - skip-dirs-use-default: true modules-download-mode: readonly timeout: 5m diff --git a/Makefile b/Makefile index b8dce40d..8031f7c5 100644 --- a/Makefile +++ b/Makefile @@ -98,7 +98,7 @@ endif endif # golangci-lint -GOLANGCI_LINT_VERSION=1.57.2 +GOLANGCI_LINT_VERSION=1.63.4 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/go.mod b/go.mod index a5ab9d5f..0091b816 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ module github.com/apache/yunikorn-core -go 1.21 +go 1.23 require ( github.com/apache/yunikorn-scheduler-interface v1.6.1-1 diff --git a/pkg/common/configs/configvalidator.go b/pkg/common/configs/configvalidator.go index c80ec026..7718436a 100644 --- a/pkg/common/configs/configvalidator.go +++ b/pkg/common/configs/configvalidator.go @@ -316,7 +316,7 @@ func checkResourceConfig(cur QueueConfig) (*resources.Resource, *resources.Resou // Check the placement rules for correctness func checkPlacementRules(partition *PartitionConfig) error { // return if nothing defined - if partition.PlacementRules == nil || len(partition.PlacementRules) == 0 { + if len(partition.PlacementRules) == 0 { return nil } diff --git a/pkg/common/resources/resources.go b/pkg/common/resources/resources.go index 685d9f27..04a956c1 100644 --- a/pkg/common/resources/resources.go +++ b/pkg/common/resources/resources.go @@ -20,6 +20,7 @@ package resources import ( "encoding/json" + "errors" "fmt" "math" "sort" @@ -407,7 +408,7 @@ func SubErrorNegative(left, right *Resource) (*Resource, error) { res, message := subNonNegative(left, right) var err error if message != "" { - err = fmt.Errorf(message) + err = errors.New(message) } return res, err } diff --git a/pkg/log/logger.go b/pkg/log/logger.go index 8802fc9d..b902556d 100644 --- a/pkg/log/logger.go +++ b/pkg/log/logger.go @@ -306,14 +306,16 @@ func parseLevel(level string) *zapcore.Level { } // parse numeric - levelNum, err := strconv.ParseInt(level, 10, 31) + levelNum, err := strconv.ParseInt(level, 10, 8) if err == nil { - zapLevel = zapcore.Level(levelNum) - if zapLevel < zapcore.DebugLevel { + // Validate levelNum is within valid zapcore.Level range before conversion + switch { + case levelNum < int64(zapcore.DebugLevel): zapLevel = zapcore.DebugLevel - } - if zapLevel >= zapcore.InvalidLevel { + case levelNum >= int64(zapcore.InvalidLevel): zapLevel = zapcore.InvalidLevel - 1 + default: + zapLevel = zapcore.Level(levelNum) } return &zapLevel } diff --git a/pkg/log/logger_test.go b/pkg/log/logger_test.go index 48160d05..da12e51c 100644 --- a/pkg/log/logger_test.go +++ b/pkg/log/logger_test.go @@ -232,6 +232,9 @@ func TestParseLevel(t *testing.T) { assert.Equal(t, zapcore.PanicLevel, *parseLevel("PAnIC")) assert.Equal(t, zapcore.FatalLevel, *parseLevel("faTal")) assert.Assert(t, parseLevel("x") == nil, "parse error") + + assert.Assert(t, parseLevel("-129") == nil, "Values outside int8 range (-128 to 127)") + assert.Assert(t, parseLevel("128") == nil, "Values outside int8 range (-128 to 127)") } func TestParentLogger(t *testing.T) { diff --git a/pkg/scheduler/objects/application_state_test.go b/pkg/scheduler/objects/application_state_test.go index 33c218ff..7b8f44f0 100644 --- a/pkg/scheduler/objects/application_state_test.go +++ b/pkg/scheduler/objects/application_state_test.go @@ -521,7 +521,7 @@ func assertTotalAppsRejectedMetrics(t testing.TB, expected int) { func assertQueueRunningApps(t testing.TB, app *Application, expected int) { t.Helper() runningApps := app.queue.runningApps - assert.Equal(t, runningApps, uint64(expected), "total running application in queue is not as expected.") + assert.Equal(t, runningApps, uint64(expected), "total running application in queue is not as expected.") //nolint:gosec } func assertQueueApplicationsAcceptedMetrics(t testing.TB, app *Application, expected int) { diff --git a/pkg/scheduler/objects/node_collection_test.go b/pkg/scheduler/objects/node_collection_test.go index a43c49cb..6b2db5ca 100644 --- a/pkg/scheduler/objects/node_collection_test.go +++ b/pkg/scheduler/objects/node_collection_test.go @@ -43,7 +43,11 @@ func TestNewNodeCollection(t *testing.T) { } func initBaseCollection() *baseNodeCollection { - return NewNodeCollection("test").(*baseNodeCollection) + collection, ok := NewNodeCollection("test").(*baseNodeCollection) + if !ok { + return nil + } + return collection } func initNode(name string) *Node { diff --git a/pkg/scheduler/objects/node_iterator.go b/pkg/scheduler/objects/node_iterator.go index d68f0853..1bb7b361 100644 --- a/pkg/scheduler/objects/node_iterator.go +++ b/pkg/scheduler/objects/node_iterator.go @@ -37,9 +37,11 @@ type treeIterator struct { // The accept() function checks if the node should be a candidate or not. func (ti *treeIterator) ForEachNode(f func(*Node) bool) { ti.getTree().Ascend(func(item btree.Item) bool { - node := item.(nodeRef).node - if ti.accept(node) { - return f(node) + if ref, ok := item.(nodeRef); ok { + node := ref.node + if ti.accept(node) { + return f(node) + } } return true diff --git a/pkg/scheduler/objects/preemption.go b/pkg/scheduler/objects/preemption.go index 46ae4b55..198e8016 100644 --- a/pkg/scheduler/objects/preemption.go +++ b/pkg/scheduler/objects/preemption.go @@ -542,7 +542,7 @@ func (p *Preemptor) tryNodes() (string, []*Allocation, bool) { AllocationKey: p.ask.GetAllocationKey(), NodeID: nodeID, PreemptAllocationKeys: keys, - StartIndex: int32(idx), + StartIndex: int32(idx), //nolint: gosec }) } } diff --git a/pkg/scheduler/objects/queue.go b/pkg/scheduler/objects/queue.go index 91256f3b..858e2928 100644 --- a/pkg/scheduler/objects/queue.go +++ b/pkg/scheduler/objects/queue.go @@ -1399,7 +1399,7 @@ func (sq *Queue) canRunApp(appID string) bool { if sq.maxRunningApps == 0 || sq.allocatingAcceptedApps[appID] { return true } - running := sq.runningApps + uint64(len(sq.allocatingAcceptedApps)+1) + running := sq.runningApps + uint64(len(sq.allocatingAcceptedApps)+1) //nolint: gosec return running <= sq.maxRunningApps } @@ -1970,7 +1970,7 @@ func priorityValueByPolicy(policy policies.PriorityPolicy, offset int32, priorit if result < int64(configs.MinPriority) { return configs.MinPriority } - return int32(result) + return int32(result) //nolint: gosec } } diff --git a/pkg/scheduler/ugm/manager_test.go b/pkg/scheduler/ugm/manager_test.go index 91d70257..828c5378 100644 --- a/pkg/scheduler/ugm/manager_test.go +++ b/pkg/scheduler/ugm/manager_test.go @@ -1989,12 +1989,13 @@ func assertUGM(t *testing.T, userGroup security.UserGroup, expected *resources.R func assertMaxLimits(t *testing.T, userGroup security.UserGroup, expectedResource *resources.Resource, expectedMaxApps int) { manager := GetUserManager() - assert.Equal(t, manager.GetUserTracker(userGroup.User).queueTracker.maxRunningApps, uint64(expectedMaxApps*2)) - assert.Equal(t, manager.GetGroupTracker(userGroup.Groups[0]).queueTracker.maxRunningApps, uint64(expectedMaxApps*2)) + expectedMaxAppsUint := uint64(expectedMaxApps) //nolint:gosec + assert.Equal(t, manager.GetUserTracker(userGroup.User).queueTracker.maxRunningApps, expectedMaxAppsUint*2) + assert.Equal(t, manager.GetGroupTracker(userGroup.Groups[0]).queueTracker.maxRunningApps, expectedMaxAppsUint*2) assert.Equal(t, resources.Equals(manager.GetUserTracker(userGroup.User).queueTracker.maxResources, resources.Multiply(expectedResource, 2)), true) assert.Equal(t, resources.Equals(manager.GetGroupTracker(userGroup.Groups[0]).queueTracker.maxResources, resources.Multiply(expectedResource, 2)), true) - assert.Equal(t, manager.GetUserTracker(userGroup.User).queueTracker.childQueueTrackers["parent"].maxRunningApps, uint64(expectedMaxApps)) - assert.Equal(t, manager.GetGroupTracker(userGroup.Groups[0]).queueTracker.childQueueTrackers["parent"].maxRunningApps, uint64(expectedMaxApps)) + assert.Equal(t, manager.GetUserTracker(userGroup.User).queueTracker.childQueueTrackers["parent"].maxRunningApps, expectedMaxAppsUint) + assert.Equal(t, manager.GetGroupTracker(userGroup.Groups[0]).queueTracker.childQueueTrackers["parent"].maxRunningApps, expectedMaxAppsUint) assert.Equal(t, resources.Equals(manager.GetUserTracker(userGroup.User).queueTracker.childQueueTrackers["parent"].maxResources, expectedResource), true) assert.Equal(t, resources.Equals(manager.GetGroupTracker(userGroup.Groups[0]).queueTracker.childQueueTrackers["parent"].maxResources, expectedResource), true) } diff --git a/pkg/scheduler/ugm/queue_tracker.go b/pkg/scheduler/ugm/queue_tracker.go index 36ddba25..ca9d7ce9 100644 --- a/pkg/scheduler/ugm/queue_tracker.go +++ b/pkg/scheduler/ugm/queue_tracker.go @@ -397,7 +397,7 @@ func (qt *QueueTracker) canRunApp(hierarchy []string, applicationID string, trac } // apply user/group specific limit settings set if configured, otherwise use wild card limit settings - if qt.maxRunningApps != 0 && running > int(qt.maxRunningApps) { + if qt.maxRunningApps != 0 && running > int(qt.maxRunningApps) { //nolint: gosec return false } return true diff --git a/pkg/scheduler/utilities_test.go b/pkg/scheduler/utilities_test.go index a87b26bd..25397293 100644 --- a/pkg/scheduler/utilities_test.go +++ b/pkg/scheduler/utilities_test.go @@ -693,14 +693,18 @@ func assertUserGroupResourceMaxLimits(t *testing.T, userGroup security.UserGroup getMaxResource(usage.Queues, maxResources) for q, qMaxLimits := range expectedQueuesMaxLimits { if qRes, ok := maxResources[q]; ok { - assert.Equal(t, resources.Equals(qRes, qMaxLimits[maxresources].(*resources.Resource)), true) + maxRes, ok := qMaxLimits[maxresources].(*resources.Resource) + assert.Assert(t, ok, "expected resource type is not resource") + assert.Equal(t, resources.Equals(qRes, maxRes), true) } } maxApplications := make(map[string]uint64) getMaxApplications(usage.Queues, maxApplications) for q, qMaxLimits := range expectedQueuesMaxLimits { if qApps, ok := maxApplications[q]; ok { - assert.Equal(t, qApps, qMaxLimits[maxapplications].(uint64), "queue path is "+q+" actual: "+strconv.Itoa(int(qApps))+", expected: "+strconv.Itoa(int(qMaxLimits[maxapplications].(uint64)))) + maxApps, ok := qMaxLimits[maxapplications].(uint64) + assert.Assert(t, ok, "expected application type is not uint64") + assert.Equal(t, qApps, maxApps, "queue path is "+q+" actual: "+strconv.Itoa(int(qApps))+", expected: "+strconv.Itoa(int(maxApps))) //nolint:gosec } } } @@ -712,14 +716,18 @@ func assertUserGroupResourceMaxLimits(t *testing.T, userGroup security.UserGroup getMaxResource(gUsage.Queues, gMaxResources) for q, qMaxLimits := range expectedQueuesMaxLimits { if qRes, ok := gMaxResources[q]; ok { - assert.Equal(t, resources.Equals(qRes, qMaxLimits[maxresources].(*resources.Resource)), true) + maxRes, ok := qMaxLimits[maxresources].(*resources.Resource) + assert.Assert(t, ok, "expected resource type is not resource") + assert.Equal(t, resources.Equals(qRes, maxRes), true) } } gMaxApps := make(map[string]uint64) getMaxApplications(gUsage.Queues, gMaxApps) for q, qMaxLimits := range expectedQueuesMaxLimits { if qApps, ok := gMaxApps[q]; ok { - assert.Equal(t, qApps, qMaxLimits[maxapplications].(uint64)) + maxApps, ok := qMaxLimits[maxapplications].(uint64) + assert.Assert(t, ok, "expected application type is not uint64") + assert.Equal(t, qApps, maxApps) } } } --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@yunikorn.apache.org For additional commands, e-mail: issues-h...@yunikorn.apache.org