This is an automated email from the ASF dual-hosted git repository.
manirajv06 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 eaf4e6a0 [YUNIKORN-3345] Turn on nonamedreturns linter (#1129)
eaf4e6a0 is described below
commit eaf4e6a0b62178db5dab977c7ed02d8cf6137140
Author: PoiBlackTea <[email protected]>
AuthorDate: Tue Aug 18 12:23:54 2026 +0530
[YUNIKORN-3345] Turn on nonamedreturns linter (#1129)
Turn on nonamedreturns linter in .golangci.yml and refactor functions using
named returns.
Closes: #1129
Signed-off-by: mani <[email protected]>
---
.golangci.yml | 1 +
pkg/common/configs/configvalidator.go | 7 +++++--
pkg/locking/locking.go | 2 +-
pkg/scheduler/objects/application.go | 7 ++++---
pkg/scheduler/objects/preemption_queue_test.go | 15 +++++++--------
pkg/scheduler/partition.go | 6 +++---
pkg/webservice/handlers_test.go | 8 ++++----
7 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/.golangci.yml b/.golangci.yml
index b328aec0..39d1ecb5 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -72,6 +72,7 @@ linters:
- gosec
- dogsled
- whitespace
+ - nonamedreturns
issues:
max-issues-per-linter: 0
max-same-issues: 0
diff --git a/pkg/common/configs/configvalidator.go
b/pkg/common/configs/configvalidator.go
index 3117368f..46578d06 100644
--- a/pkg/common/configs/configvalidator.go
+++ b/pkg/common/configs/configvalidator.go
@@ -827,8 +827,11 @@ func getLongestPlacementPaths(rules []PlacementRule)
([]placementStaticPath, err
return paths, nil
}
-func getLongestStaticPath(rule PlacementRule) (staticPath, ruleChain string,
foundDynamicRule bool, err error) {
+func getLongestStaticPath(rule PlacementRule) (string, string, bool, error) {
rules := getRuleChain(rule)
+ var staticPath string
+ var ruleChain string
+ var foundDynamicRule bool
for _, r := range rules {
if ruleChain == "" {
@@ -853,7 +856,7 @@ func getLongestStaticPath(rule PlacementRule) (staticPath,
ruleChain string, fou
if qualified {
if staticPath != "" {
// error, only the first fixed rule can be
fully qualified
- err = fmt.Errorf("illegal fully qualified
'fixed' rule with value %s", queueName)
+ err := fmt.Errorf("illegal fully qualified
'fixed' rule with value %s", queueName)
return staticPath, ruleChain, foundDynamicRule,
err
}
staticPath = queueName
diff --git a/pkg/locking/locking.go b/pkg/locking/locking.go
index f4d903c9..f8458cde 100644
--- a/pkg/locking/locking.go
+++ b/pkg/locking/locking.go
@@ -53,7 +53,7 @@ type errorBuf struct {
sync.Mutex
}
-func (b *errorBuf) Write(p []byte) (n int, err error) {
+func (b *errorBuf) Write(p []byte) (int, error) {
if b == nil {
return len(p), nil
}
diff --git a/pkg/scheduler/objects/application.go
b/pkg/scheduler/objects/application.go
index a31bfba6..6d630423 100644
--- a/pkg/scheduler/objects/application.go
+++ b/pkg/scheduler/objects/application.go
@@ -1256,8 +1256,9 @@ func (sa *Application) unreserveForApp(res *reservation)
int {
// cancelMatchingReservations cancels reservations that match the predicate.
// Returns the number of reservations released and the number remaining.
-func (sa *Application) cancelMatchingReservations(reservations []*reservation,
shouldCancel func(*reservation) bool) (released, remaining int) {
- remaining = len(reservations)
+func (sa *Application) cancelMatchingReservations(reservations []*reservation,
shouldCancel func(*reservation) bool) (int, int) {
+ released := 0
+ remaining := len(reservations)
for _, res := range reservations {
if !shouldCancel(res) {
continue
@@ -1266,7 +1267,7 @@ func (sa *Application)
cancelMatchingReservations(reservations []*reservation, s
released += num
remaining -= num
}
- return
+ return released, remaining
}
// cancelReservations will cancel all non required node reservations for a
node. The list of reservations passed in is
diff --git a/pkg/scheduler/objects/preemption_queue_test.go
b/pkg/scheduler/objects/preemption_queue_test.go
index 08794382..5733b8f9 100644
--- a/pkg/scheduler/objects/preemption_queue_test.go
+++ b/pkg/scheduler/objects/preemption_queue_test.go
@@ -374,21 +374,20 @@ func TestGetRemainingGuaranteedResource(t *testing.T) {
}
}
-func setup(t *testing.T) (rootQ, parentQ, childQ1, childQ2, childQ3 *Queue) {
+func setup(t *testing.T) (*Queue, *Queue, *Queue, *Queue, *Queue) {
rootQ, err := createRootQueue(map[string]string{})
assert.NilError(t, err)
- var parent1Q *Queue
- parentQ, err = createManagedQueue(rootQ, "parent", true,
map[string]string{})
+ parentQ, err := createManagedQueue(rootQ, "parent", true,
map[string]string{})
assert.NilError(t, err)
- parent1Q, err = createManagedQueue(rootQ, "parent1", true,
map[string]string{})
+ parent1Q, err := createManagedQueue(rootQ, "parent1", true,
map[string]string{})
assert.NilError(t, err)
- childQ1, err = createManagedQueue(parentQ, "child1", false,
map[string]string{})
+ childQ1, err := createManagedQueue(parentQ, "child1", false,
map[string]string{})
assert.NilError(t, err)
- childQ2, err = createManagedQueue(parentQ, "child2", false,
map[string]string{})
+ childQ2, err := createManagedQueue(parentQ, "child2", false,
map[string]string{})
assert.NilError(t, err)
- childQ3, err = createManagedQueue(parent1Q, "child3", false,
map[string]string{})
+ childQ3, err := createManagedQueue(parent1Q, "child3", false,
map[string]string{})
assert.NilError(t, err)
- return
+ return rootQ, parentQ, childQ1, childQ2, childQ3
}
func assertRemaining(t *testing.T, rootQ *Queue, parentQ *Queue, childQ2
*Queue, childQ1 *Queue, askQueue *Queue, res1 res) {
diff --git a/pkg/scheduler/partition.go b/pkg/scheduler/partition.go
index 2dd27962..dd900fad 100644
--- a/pkg/scheduler/partition.go
+++ b/pkg/scheduler/partition.go
@@ -1166,10 +1166,10 @@ func (pc *PartitionContext) GetNodes() []*objects.Node {
// UpdateAllocation adds or updates an Allocation. If the Allocation has no
NodeID specified, it is considered a
// pending allocation and processed appropriate. This call is idempotent, and
can be called multiple times with the
// same allocation (such as on change updates from the shim)
-// Upon successfully processing, two flags are returned: requestCreated (if a
new request was added) and allocCreated (if an allocation was satisifed).
+// Upon successfully processing, two flags are returned: requestCreated (if a
new request was added) and allocCreated (if an allocation was satisfied).
// This can be used by callers that need this information to take further
action.
// NOTE: this is a lock free call. It must NOT be called holding the
PartitionContext lock.
-func (pc *PartitionContext) UpdateAllocation(alloc *objects.Allocation)
(requestCreated bool, allocCreated bool, err error) { //nolint:funlen
+func (pc *PartitionContext) UpdateAllocation(alloc *objects.Allocation) (bool,
bool, error) { //nolint:funlen
// cannot do anything with a nil alloc, should only happen if the shim
broke things badly
if alloc == nil {
return false, false, nil
@@ -1350,7 +1350,7 @@ func (pc *PartitionContext) UpdateAllocation(alloc
*objects.Allocation) (request
return false, false, nil
}
-func (pc *PartitionContext) handleForeignAllocation(allocationKey,
applicationID, nodeID string, node *objects.Node, alloc *objects.Allocation)
(requestCreated bool, allocCreated bool, err error) {
+func (pc *PartitionContext) handleForeignAllocation(allocationKey,
applicationID, nodeID string, node *objects.Node, alloc *objects.Allocation)
(bool, bool, error) {
allocated := alloc.IsAllocated()
if !allocated {
return false, false, fmt.Errorf("trying to add a foreign
request (non-allocation) %s", allocationKey)
diff --git a/pkg/webservice/handlers_test.go b/pkg/webservice/handlers_test.go
index e5e49898..c17a39b7 100644
--- a/pkg/webservice/handlers_test.go
+++ b/pkg/webservice/handlers_test.go
@@ -2607,7 +2607,7 @@ func assertYunikornError(t *testing.T, output, errMsg
string) {
assert.Equal(t, errMsg, ykErr.Message)
}
-func addEvents(t *testing.T) (appEvent, nodeEvent, queueEvent *si.EventRecord)
{
+func addEvents(t *testing.T) (*si.EventRecord, *si.EventRecord,
*si.EventRecord) {
t.Helper()
events.Init()
ev := events.GetEventSystem().(*events.EventSystemImpl)
//nolint:errcheck
@@ -2616,7 +2616,7 @@ func addEvents(t *testing.T) (appEvent, nodeEvent,
queueEvent *si.EventRecord) {
"cpu": 1,
}).ToProto()
- appEvent = &si.EventRecord{
+ appEvent := &si.EventRecord{
Type: si.EventRecord_APP,
TimestampNano: 100,
Message: "app event",
@@ -2627,7 +2627,7 @@ func addEvents(t *testing.T) (appEvent, nodeEvent,
queueEvent *si.EventRecord) {
Resource: protoRes,
}
ev.AddEvent(appEvent)
- nodeEvent = &si.EventRecord{
+ nodeEvent := &si.EventRecord{
Type: si.EventRecord_NODE,
TimestampNano: 101,
Message: "node event",
@@ -2638,7 +2638,7 @@ func addEvents(t *testing.T) (appEvent, nodeEvent,
queueEvent *si.EventRecord) {
Resource: protoRes,
}
ev.AddEvent(nodeEvent)
- queueEvent = &si.EventRecord{
+ queueEvent := &si.EventRecord{
Type: si.EventRecord_QUEUE,
TimestampNano: 102,
Message: "queue event",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]