You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@yunikorn.apache.org by cc...@apache.org on 2025/02/21 21:59:49 UTC

(yunikorn-core) branch master updated: [YUNIKORN-3029] update golangci-lint for go 1.23 (#1013)

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

ccondit 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 621c1849 [YUNIKORN-3029] update golangci-lint for go 1.23 (#1013)
621c1849 is described below

commit 621c1849190b72fb622417967d61b082ce6a34dc
Author: kaichiachen <ka...@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 <cc...@apache.org>
---
 .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/predicates_test.go        |  2 +-
 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 ++++++++++++----
 17 files changed, 49 insertions(+), 29 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 0233cf6e..004da793 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 v0.0.0-20241016105739-f0e241aa0146
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 0a12a58b..82e31f92 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 16b81144..3a1bd38c 100644
--- a/pkg/scheduler/objects/application_state_test.go
+++ b/pkg/scheduler/objects/application_state_test.go
@@ -528,7 +528,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/predicates_test.go b/pkg/scheduler/objects/predicates_test.go
index e8a6ef1d..1eceb2d9 100644
--- a/pkg/scheduler/objects/predicates_test.go
+++ b/pkg/scheduler/objects/predicates_test.go
@@ -228,7 +228,7 @@ func TestPredicateCheckResult_PopulateVictims(t *testing.T) {
 				assert.Equal(t, tt.wantSuccess, tt.pcr.success, "success mismatch")
 				assert.Equal(t, tt.wantIndex, tt.pcr.index, "index mismatch")
 				if tt.wantVictims == nil {
-					assert.Assert(t, tt.pcr.victims == nil || len(tt.pcr.victims) == 0, "expected no victims")
+					assert.Assert(t, len(tt.pcr.victims) == 0, "expected no victims")
 				} else {
 					assert.Equal(t, len(tt.wantVictims), len(tt.pcr.victims), "victims length mismatch")
 				}
diff --git a/pkg/scheduler/objects/preemption.go b/pkg/scheduler/objects/preemption.go
index 0e5bf543..c9bf760d 100644
--- a/pkg/scheduler/objects/preemption.go
+++ b/pkg/scheduler/objects/preemption.go
@@ -541,7 +541,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 b111d338..19b4a8da 100644
--- a/pkg/scheduler/objects/queue.go
+++ b/pkg/scheduler/objects/queue.go
@@ -1417,7 +1417,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
 }
 
@@ -1998,7 +1998,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 9768cb28..0c3e06fc 100644
--- a/pkg/scheduler/ugm/manager_test.go
+++ b/pkg/scheduler/ugm/manager_test.go
@@ -2004,12 +2004,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 c5351947..e78d1f52 100644
--- a/pkg/scheduler/ugm/queue_tracker.go
+++ b/pkg/scheduler/ugm/queue_tracker.go
@@ -443,7 +443,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 dee25e9f..d7cbf1f7 100644
--- a/pkg/scheduler/utilities_test.go
+++ b/pkg/scheduler/utilities_test.go
@@ -727,13 +727,17 @@ func assertUserGroupResourceMaxLimits(t *testing.T, userGroup security.UserGroup
 		maxResources := ut.GetMaxResources()
 		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 := ut.GetMaxApplications()
 		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
 			}
 		}
 	}
@@ -743,13 +747,17 @@ func assertUserGroupResourceMaxLimits(t *testing.T, userGroup security.UserGroup
 		gMaxResources := gt.GetMaxResources()
 		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 := gt.GetMaxApplications()
 		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-unsubscribe@yunikorn.apache.org
For additional commands, e-mail: issues-help@yunikorn.apache.org