pbacsko commented on code in PR #730:
URL: https://github.com/apache/yunikorn-k8shim/pull/730#discussion_r1498688210
##########
pkg/cache/application.go:
##########
@@ -320,6 +320,10 @@ func (app *Application) getNonTerminatedTaskAlias()
[]string {
return nonTerminatedTaskAlias
}
+func (app *Application) IsAllTasksTerminated() bool {
Review Comment:
Nit: `AreAllTasksTerminated()`
##########
pkg/shim/scheduler.go:
##########
@@ -158,6 +158,25 @@ func (ss *KubernetesShim) registerShimLayer() error {
func (ss *KubernetesShim) schedule() {
apps := ss.context.GetAllApplications()
for _, app := range apps {
+ // Clean up terminal failed apps for shim side
+ // 1. When we reject an app, we set the app state to Rejected,
and immediately set it to Failed, but we don't clean up the app.
+ // 2. When we failed an app, we set the app state to Failed,
but we don't clean up the app.
+ // 3. The completed app already handled by UpdateApplication
function.
+ // case cache.ApplicationStates().Completed:
+ //
callback.context.RemoveApplicationInternal(updated.ApplicationID)
+ // 4. The killed status is not used until now, so we don't need
to handle it.
+ if app.GetApplicationState() ==
cache.ApplicationStates().Failed {
+ if app.IsAllTasksTerminated() {
+ log.Log(log.ShimScheduler).Info("Clean up
failed application",
+ zap.String("appID",
app.GetApplicationID()))
+
ss.context.RemoveApplicationInternal(app.GetApplicationID())
+ } else {
+ log.Log(log.ShimScheduler).Info("Failed
application is not cleaned up due to not all tasks terminated, wait for next
scheduling iteration",
+ zap.String("appID",
app.GetApplicationID()))
Review Comment:
I'd just remove this log entry althogether. If someone reduces the
scheduling interval, it can flood the logs.
##########
pkg/shim/scheduler_mock_test.go:
##########
@@ -128,6 +128,23 @@ func (fc *MockScheduler) addNode(nodeName string,
nodeLabels map[string]string,
return fc.apiProvider.GetAPIs().SchedulerAPI.UpdateNode(request)
}
+func (fc *MockScheduler) waitApplicationDeleted(t *testing.T, appID string) {
Review Comment:
nit: rename method to sth like `waitForApplicationDeletion()`.
##########
pkg/shim/scheduler.go:
##########
@@ -158,6 +158,25 @@ func (ss *KubernetesShim) registerShimLayer() error {
func (ss *KubernetesShim) schedule() {
apps := ss.context.GetAllApplications()
for _, app := range apps {
+ // Clean up terminal failed apps for shim side
+ // 1. When we reject an app, we set the app state to Rejected,
and immediately set it to Failed, but we don't clean up the app.
+ // 2. When we failed an app, we set the app state to Failed,
but we don't clean up the app.
+ // 3. The completed app already handled by UpdateApplication
function.
+ // case cache.ApplicationStates().Completed:
+ //
callback.context.RemoveApplicationInternal(updated.ApplicationID)
+ // 4. The killed status is not used until now, so we don't need
to handle it.
Review Comment:
This comment doesn't really add extra information about what's happening
here. It sounds more like a problem description that is addressed by the new
code. I suggest removing it.
##########
pkg/shim/scheduler_mock_test.go:
##########
@@ -128,6 +128,23 @@ func (fc *MockScheduler) addNode(nodeName string,
nodeLabels map[string]string,
return fc.apiProvider.GetAPIs().SchedulerAPI.UpdateNode(request)
}
+func (fc *MockScheduler) waitApplicationDeleted(t *testing.T, appID string) {
+ deadline := time.Now().Add(10 * time.Second)
+ for {
+ app := fc.context.GetApplication(appID)
+ if app == nil {
+ break
+ }
+ log.Log(log.Test).Info("waiting for app deleted",
+ zap.String("appID", appID))
+ time.Sleep(time.Second)
+ if time.Now().After(deadline) {
+ t.Errorf("application %s is not deleted in given time",
appID)
+ return
+ }
+ }
Review Comment:
I know it's probably based on `waitAndAssertApplicationState()`, but there's
a better way. Simply use `utils.WaitForCondition()`.
```
err := utils.WaitForCondition(func() bool {
return fc.context.GetApplication(appID) != nil
}, time.Second, 5*time.Second)
assert.NilError(t, err, "application has not been deleted")
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]