pbacsko commented on code in PR #428:
URL: https://github.com/apache/yunikorn-k8shim/pull/428#discussion_r888087405
##########
pkg/cache/context.go:
##########
@@ -691,21 +691,30 @@ func (ctx *Context) AddTask(request
*interfaces.AddTaskRequest) interfaces.Manag
if app, valid := managedApp.(*Application); valid {
existingTask, err :=
app.GetTask(request.Metadata.TaskID)
if err != nil {
- task :=
NewFromTaskMeta(request.Metadata.TaskID, app, ctx, request.Metadata)
+ var originator bool
+ var ownerReferenceUID string
+ // Is this task the originator of the
application?
+ // If yes, then make it as "first
pod/owner/driver" of the application and set the task as originator
+ for _, ownerReference := range
app.getPlaceholderOwnerReferences() {
+ referenceID :=
string(ownerReference.UID)
+ if request.Metadata.TaskID ==
referenceID {
+ originator = true
+ ownerReferenceUID = referenceID
+ break
+ }
+ }
+ task :=
NewFromTaskMeta(request.Metadata.TaskID, app, ctx, request.Metadata, originator)
app.addTask(task)
log.Logger().Info("task added",
zap.String("appID", app.applicationID),
zap.String("taskID", task.taskID),
zap.String("taskState",
task.GetTaskState()))
- if app.getOriginatingTask() == nil {
- for _, ownerReference := range
app.getPlaceholderOwnerReferences() {
- if task, taskErr :=
app.GetTask(string(ownerReference.UID)); task != nil && taskErr == nil {
- log.Logger().Info("app
request originating pod added",
-
zap.String("appID", app.applicationID),
-
zap.String("original task", task.GetTaskID()))
-
app.setOriginatingTask(task)
- break
- }
+ if app.GetOriginatingTask() == nil {
Review Comment:
Just curious... If we've already called `setOriginatingTask()` then this no
longer returns `nil`. Also, we set this if `originator == true` and we have
only one originator, right? So to me, it's cleaner to read sth like:
```
if originator {
app.setOriginatingTask(task)
log.Logger().Info("app request originating pod added",
zap.String("original task", task.GetTaskID()))
}
```
If `originator` is true and `app.GetTask(ownerReferenceUID)` returns an
existing task, that means an inconsistent state, isn't it?
If I'm correct, I'd rather simplify this and handle the `task != nil`
condition with an error, because it's something that's not supposed to happen:
```
if originator {
if app.GetOriginatingTask() != nil {
log.Logger.Error("Inconsistent state - found another originator task for
an application", zap.String("taskId", task.GetTaskID())
}
app.setOriginatingTask(task)
log.Logger().Info("app request originating pod added",
zap.String("original task", task.GetTaskID()))
}
```
--
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]