This is an automated email from the ASF dual-hosted git repository.
chia7712 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-k8shim.git
The following commit(s) were added to refs/heads/master by this push:
new 1014ba5b [YUNIKORN-2658] add nolint:funlen to long functions to
supress the lint warnings (#861) Closes: #861
1014ba5b is described below
commit 1014ba5b85526a2aa9a3ba3538280902c801e19f
Author: rich7420 <[email protected]>
AuthorDate: Tue Jun 25 21:58:29 2024 +0800
[YUNIKORN-2658] add nolint:funlen to long functions to supress the lint
warnings (#861)
Closes: #861
Signed-off-by: Chia-Ping Tsai <[email protected]>
---
pkg/cache/application_test.go | 2 +
pkg/cache/context_test.go | 2 +
pkg/cache/external/scheduler_cache_test.go | 1 +
pkg/cache/task_state.go | 241 ++++++++++++------------
pkg/cache/task_test.go | 1 +
pkg/common/resource_test.go | 1 +
pkg/plugin/predicates/predicate_manager_test.go | 2 +
7 files changed, 129 insertions(+), 121 deletions(-)
diff --git a/pkg/cache/application_test.go b/pkg/cache/application_test.go
index 9d91e46b..5d9a3ce9 100644
--- a/pkg/cache/application_test.go
+++ b/pkg/cache/application_test.go
@@ -525,6 +525,7 @@ func assertAppState(t *testing.T, app *Application,
expectedState string, durati
}
}
+//nolint:funlen
func TestGetNonTerminatedTaskAlias(t *testing.T) {
context := initContextForTest()
app := NewApplication(appID, "root.a", "testuser", testGroups,
map[string]string{}, newMockSchedulerAPI())
@@ -749,6 +750,7 @@ func TestTryReserve(t *testing.T) {
assert.NilError(t, err, "placeholders are not created")
}
+//nolint:funlen
func TestTryReservePostRestart(t *testing.T) {
context := initContextForTest()
dispatcher.RegisterEventHandler("TestAppHandler",
dispatcher.EventTypeApp, context.ApplicationEventHandler())
diff --git a/pkg/cache/context_test.go b/pkg/cache/context_test.go
index 67df1d47..cff04ee8 100644
--- a/pkg/cache/context_test.go
+++ b/pkg/cache/context_test.go
@@ -855,6 +855,7 @@ func TestAddTask(t *testing.T) {
assert.Equal(t, len(context.applications["app00001"].GetNewTasks()), 2)
}
+//nolint:funlen
func TestRecoverTask(t *testing.T) {
context, apiProvider := initContextAndAPIProviderForTest()
dispatcher.Start()
@@ -1481,6 +1482,7 @@ func TestPublishEventsCorrectly(t *testing.T) {
assert.NilError(t, err, "event should have been emitted")
}
+//nolint:funlen
func TestAddApplicationsWithTags(t *testing.T) {
context := initContextForTest()
diff --git a/pkg/cache/external/scheduler_cache_test.go
b/pkg/cache/external/scheduler_cache_test.go
index 61e8838b..c443491b 100644
--- a/pkg/cache/external/scheduler_cache_test.go
+++ b/pkg/cache/external/scheduler_cache_test.go
@@ -307,6 +307,7 @@ func TestGetNodesInfo(t *testing.T) {
expectHost(t, host2, nodesInfo)
}
+//nolint:funlen
func TestGetNodesInfoPodsWithAffinity(t *testing.T) {
cache := NewSchedulerCache(client.NewMockedAPIProvider(false).GetAPIs())
assert.Assert(t, cache.nodesInfoPodsWithAffinity == nil)
diff --git a/pkg/cache/task_state.go b/pkg/cache/task_state.go
index d0ee58ef..d244fa8d 100644
--- a/pkg/cache/task_state.go
+++ b/pkg/cache/task_state.go
@@ -316,129 +316,128 @@ func TaskStates() *TStates {
func newTaskState() *fsm.FSM {
states := TaskStates()
- return fsm.NewFSM(
- states.New, fsm.Events{
- {
- Name: InitTask.String(),
- Src: []string{states.New},
- Dst: states.Pending,
- },
- {
- Name: SubmitTask.String(),
- Src: []string{states.Pending},
- Dst: states.Scheduling,
- },
- {
- Name: TaskAllocated.String(),
- Src: []string{states.Scheduling},
- Dst: states.Allocated,
- },
- {
- Name: TaskAllocated.String(),
- Src: []string{states.Completed},
- Dst: states.Completed,
- },
- {
- Name: TaskBound.String(),
- Src: []string{states.Allocated},
- Dst: states.Bound,
- },
- {
- Name: CompleteTask.String(),
- Src: states.Any,
- Dst: states.Completed,
- },
- {
- Name: KillTask.String(),
- Src: []string{states.Pending,
states.Scheduling, states.Allocated, states.Bound},
- Dst: states.Killing,
- },
- {
- Name: TaskKilled.String(),
- Src: []string{states.Killing},
- Dst: states.Killed,
- },
- {
- Name: TaskRejected.String(),
- Src: []string{states.New, states.Pending,
states.Scheduling},
- Dst: states.Rejected,
- },
- {
- Name: TaskFail.String(),
- Src: []string{states.New, states.Pending,
states.Scheduling, states.Rejected, states.Allocated},
- Dst: states.Failed,
- },
+ return fsm.NewFSM(states.New, eventDesc(states), callbacks(states))
+}
+
+func eventDesc(states *TStates) fsm.Events {
+ return fsm.Events{
+ {
+ Name: InitTask.String(),
+ Src: []string{states.New},
+ Dst: states.Pending,
},
- fsm.Callbacks{
- // The state machine is tightly tied to the Task object.
- //
- // The first argument must always be a Task and if
there are more arguments,
- // they must be a string. If this precondition is not
met, a runtime panic
- // could occur.
- events.EnterState: func(_ context.Context, event
*fsm.Event) {
- task := event.Args[0].(*Task) //nolint:errcheck
- log.Log(log.ShimFSM).Info("Task state
transition",
- zap.String("app", task.applicationID),
- zap.String("task", task.taskID),
- zap.String("taskAlias", task.alias),
- zap.String("source", event.Src),
- zap.String("destination", event.Dst),
- zap.String("event", event.Event))
- },
- states.Pending: func(_ context.Context, event
*fsm.Event) {
- task := event.Args[0].(*Task) //nolint:errcheck
- task.postTaskPending()
- },
- states.Allocated: func(_ context.Context, event
*fsm.Event) {
- task := event.Args[0].(*Task) //nolint:errcheck
- task.postTaskAllocated()
- },
- states.Rejected: func(_ context.Context, event
*fsm.Event) {
- task := event.Args[0].(*Task) //nolint:errcheck
- task.postTaskRejected()
- },
- states.Failed: func(_ context.Context, event
*fsm.Event) {
- task := event.Args[0].(*Task) //nolint:errcheck
- eventArgs := make([]string, 1)
- reason := ""
- if err :=
events.GetEventArgsAsStrings(eventArgs, event.Args[1].([]interface{})); err !=
nil {
- log.Log(log.ShimFSM).Error("failed to
parse event arg", zap.Error(err))
- reason = err.Error()
- } else {
- reason = eventArgs[0]
- }
- task.postTaskFailed(reason)
- },
- states.Bound: func(_ context.Context, event *fsm.Event)
{
- task := event.Args[0].(*Task) //nolint:errcheck
- task.postTaskBound()
- },
- beforeHook(TaskFail): func(_ context.Context, event
*fsm.Event) {
- task := event.Args[0].(*Task) //nolint:errcheck
- task.beforeTaskFail()
- },
- beforeHook(TaskAllocated): func(_ context.Context,
event *fsm.Event) {
- task := event.Args[0].(*Task) //nolint:errcheck
- // All allocation events must include the
allocationKey and nodeID passed from the core
- eventArgs := make([]string, 2)
- if err :=
events.GetEventArgsAsStrings(eventArgs, event.Args[1].([]interface{})); err !=
nil {
- log.Log(log.ShimFSM).Error("failed to
parse event arg", zap.Error(err))
- return
- }
- allocationKey := eventArgs[0]
- nodeID := eventArgs[1]
- task.beforeTaskAllocated(event.Src,
allocationKey, nodeID)
- },
- beforeHook(CompleteTask): func(_ context.Context, event
*fsm.Event) {
- task := event.Args[0].(*Task) //nolint:errcheck
- task.beforeTaskCompleted()
- },
- SubmitTask.String(): func(_ context.Context, event
*fsm.Event) {
- task := event.Args[0].(*Task) //nolint:errcheck
- task.handleSubmitTaskEvent()
- },
+ {
+ Name: SubmitTask.String(),
+ Src: []string{states.Pending},
+ Dst: states.Scheduling,
},
- )
+ {
+ Name: TaskAllocated.String(),
+ Src: []string{states.Scheduling},
+ Dst: states.Allocated,
+ },
+ {
+ Name: TaskAllocated.String(),
+ Src: []string{states.Completed},
+ Dst: states.Completed,
+ },
+ {
+ Name: TaskBound.String(),
+ Src: []string{states.Allocated},
+ Dst: states.Bound,
+ },
+ {
+ Name: CompleteTask.String(),
+ Src: states.Any,
+ Dst: states.Completed,
+ },
+ {
+ Name: KillTask.String(),
+ Src: []string{states.Pending, states.Scheduling,
states.Allocated, states.Bound},
+ Dst: states.Killing,
+ },
+ {
+ Name: TaskKilled.String(),
+ Src: []string{states.Killing},
+ Dst: states.Killed,
+ },
+ {
+ Name: TaskRejected.String(),
+ Src: []string{states.New, states.Pending,
states.Scheduling},
+ Dst: states.Rejected,
+ },
+ {
+ Name: TaskFail.String(),
+ Src: []string{states.New, states.Pending,
states.Scheduling, states.Rejected, states.Allocated},
+ Dst: states.Failed,
+ },
+ }
+}
+
+func callbacks(states *TStates) fsm.Callbacks {
+ return fsm.Callbacks{
+ events.EnterState: func(_ context.Context, event *fsm.Event) {
+ task := event.Args[0].(*Task) //nolint:errcheck
+ log.Log(log.ShimFSM).Info("Task state transition",
+ zap.String("app", task.applicationID),
+ zap.String("task", task.taskID),
+ zap.String("taskAlias", task.alias),
+ zap.String("source", event.Src),
+ zap.String("destination", event.Dst),
+ zap.String("event", event.Event))
+ },
+ states.Pending: func(_ context.Context, event *fsm.Event) {
+ task := event.Args[0].(*Task) //nolint:errcheck
+ task.postTaskPending()
+ },
+ states.Allocated: func(_ context.Context, event *fsm.Event) {
+ task := event.Args[0].(*Task) //nolint:errcheck
+ task.postTaskAllocated()
+ },
+ states.Rejected: func(_ context.Context, event *fsm.Event) {
+ task := event.Args[0].(*Task) //nolint:errcheck
+ task.postTaskRejected()
+ },
+ states.Failed: func(_ context.Context, event *fsm.Event) {
+ task := event.Args[0].(*Task) //nolint:errcheck
+ eventArgs := make([]string, 1)
+ reason := ""
+ if err := events.GetEventArgsAsStrings(eventArgs,
event.Args[1].([]interface{})); err != nil {
+ log.Log(log.ShimFSM).Error("failed to parse
event arg", zap.Error(err))
+ reason = err.Error()
+ } else {
+ reason = eventArgs[0]
+ }
+ task.postTaskFailed(reason)
+ },
+ states.Bound: func(_ context.Context, event *fsm.Event) {
+ task := event.Args[0].(*Task) //nolint:errcheck
+ task.postTaskBound()
+ },
+ beforeHook(TaskFail): func(_ context.Context, event *fsm.Event)
{
+ task := event.Args[0].(*Task) //nolint:errcheck
+ task.beforeTaskFail()
+ },
+ beforeHook(TaskAllocated): func(_ context.Context, event
*fsm.Event) {
+ task := event.Args[0].(*Task) //nolint:errcheck
+ eventArgs := make([]string, 2)
+ if err := events.GetEventArgsAsStrings(eventArgs,
event.Args[1].([]interface{})); err != nil {
+ log.Log(log.ShimFSM).Error("failed to parse
event arg", zap.Error(err))
+ return
+ }
+ allocationKey := eventArgs[0]
+ nodeID := eventArgs[1]
+ task.beforeTaskAllocated(event.Src, allocationKey,
nodeID)
+ },
+ beforeHook(CompleteTask): func(_ context.Context, event
*fsm.Event) {
+ task := event.Args[0].(*Task) //nolint:errcheck
+ task.beforeTaskCompleted()
+ },
+ SubmitTask.String(): func(_ context.Context, event *fsm.Event) {
+ task := event.Args[0].(*Task) //nolint:errcheck
+ task.handleSubmitTaskEvent()
+ },
+ }
}
func beforeHook(event TaskEventType) string {
diff --git a/pkg/cache/task_test.go b/pkg/cache/task_test.go
index 3b11bbc5..8b0692e0 100644
--- a/pkg/cache/task_test.go
+++ b/pkg/cache/task_test.go
@@ -490,6 +490,7 @@ func TestSetTaskGroup(t *testing.T) {
assert.Equal(t, task.getTaskGroupName(), "test-group")
}
+//nolint:funlen
func TestHandleSubmitTaskEvent(t *testing.T) {
mockedContext, mockedSchedulerAPI := initContextAndAPIProviderForTest()
var allocRequest *si.AllocationRequest
diff --git a/pkg/common/resource_test.go b/pkg/common/resource_test.go
index 21be4add..5adbf8c8 100644
--- a/pkg/common/resource_test.go
+++ b/pkg/common/resource_test.go
@@ -147,6 +147,7 @@ func TestEquals(t *testing.T) {
assert.Equal(t, Equals(r1, r2), false)
}
+//nolint:funlen
func TestParsePodResource(t *testing.T) {
containers := make([]v1.Container, 0, 2)
diff --git a/pkg/plugin/predicates/predicate_manager_test.go
b/pkg/plugin/predicates/predicate_manager_test.go
index e29cec18..96beb38e 100644
--- a/pkg/plugin/predicates/predicate_manager_test.go
+++ b/pkg/plugin/predicates/predicate_manager_test.go
@@ -357,6 +357,7 @@ func TestPodFitsHostPorts(t *testing.T) {
}
}
+//nolint:funlen
func TestPodFitsSelector(t *testing.T) {
clientSet := clientSet()
informerFactory := informerFactory(clientSet)
@@ -1202,6 +1203,7 @@ func TestRunGeneralPredicates(t *testing.T) {
}
}
+//nolint:funlen
func TestInterPodAffinity(t *testing.T) {
clientSet := clientSet()
informerFactory := informerFactory(clientSet)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]