yangwwei commented on a change in pull request #213:
URL:
https://github.com/apache/incubator-yunikorn-k8shim/pull/213#discussion_r546202364
##########
File path: pkg/callback/scheduler_callback.go
##########
@@ -118,15 +118,36 @@ func (callback *AsyncRMCallback)
RecvUpdateResponse(response *si.UpdateResponse)
for _, release := range response.ReleasedAllocations {
log.Logger().Debug("callback: response to released allocations",
zap.String("UUID", release.UUID))
+
+ // delete the allocated pod
+ if app :=
callback.context.GetApplicationInternal(release.ApplicationID); app != nil {
+ // TerminationType 0 mean STOPPED_BY_RM
+ if release.TerminationType !=
si.AllocationRelease_STOPPED_BY_RM {
+ for _, task := range app.GetTaskMap() {
+ if task.GetTaskAllocationUUID() ==
release.UUID {
+ err :=
task.DeleteTaskPod(task.GetTaskPod())
+ if err != nil {
+
log.Logger().Error("failed to delete pod", zap.Error(err))
+ }
+ }
+ }
+ }
+ }
Review comment:
let's use event handling to handle this, so we do not need to expose
`GetApplicationInternal ()`, `GetTaskMap()` functions. We can change this to:
```
ev := cache.NewReleaseAppAllocationEvent(app.GetApplicationID(),
toReleaseAllocations, events.ReleaseAppAllocation)
dispatcher.Dispatch(ev)
```
in `application.go`, we just need to add another event
`ReleaseAppAllocation`, and that triggers state transition from `Running` to
`Running`. And in the handler, we can do the task pod cleanup.
##########
File path: pkg/callback/scheduler_callback.go
##########
@@ -118,15 +118,36 @@ func (callback *AsyncRMCallback)
RecvUpdateResponse(response *si.UpdateResponse)
for _, release := range response.ReleasedAllocations {
log.Logger().Debug("callback: response to released allocations",
zap.String("UUID", release.UUID))
+
+ // delete the allocated pod
+ if app :=
callback.context.GetApplicationInternal(release.ApplicationID); app != nil {
+ // TerminationType 0 mean STOPPED_BY_RM
+ if release.TerminationType !=
si.AllocationRelease_STOPPED_BY_RM {
+ for _, task := range app.GetTaskMap() {
+ if task.GetTaskAllocationUUID() ==
release.UUID {
+ err :=
task.DeleteTaskPod(task.GetTaskPod())
+ if err != nil {
+
log.Logger().Error("failed to delete pod", zap.Error(err))
+ }
+ }
+ }
+ }
+ }
}
// handle status changes
for _, updated := range response.UpdatedApplications {
log.Logger().Debug("status update callback received",
zap.String("appId", updated.ApplicationID),
zap.String("new status", updated.State))
-
- //handle status update
+ // delete application from context
+ if updated.State == events.States().Application.Completed {
+ err :=
callback.context.RemoveApplicationInternal(updated.ApplicationID)
+ if err != nil {
+ log.Logger().Error("failed to delete
application", zap.Error(err))
+ }
+ }
+ // handle status update
dispatcher.Dispatch(cache.NewApplicationStatusChangeEvent(updated.ApplicationID,
events.AppStateChange, updated.State))
Review comment:
after we delete the app in line 145, it continues to handle the event in
line 151. this seems to be problematic.
should we add an `else` here?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]