craigcondit commented on code in PR #734:
URL: https://github.com/apache/yunikorn-k8shim/pull/734#discussion_r1441984050


##########
pkg/cache/context.go:
##########
@@ -126,64 +115,101 @@ func (ctx *Context) AddSchedulingEventHandlers() {
                UpdateFn: ctx.updatePriorityClass,
                DeleteFn: ctx.deletePriorityClass,
        })
+       ctx.apiProvider.AddEventHandler(&client.ResourceEventHandlers{
+               Type:     client.NodeInformerHandlers,
+               AddFn:    ctx.addNode,
+               UpdateFn: ctx.updateNode,
+               DeleteFn: ctx.deleteNode,
+       })
+       ctx.apiProvider.AddEventHandler(&client.ResourceEventHandlers{
+               Type:     client.PodInformerHandlers,
+               AddFn:    ctx.AddPod,
+               UpdateFn: ctx.UpdatePod,
+               DeleteFn: ctx.DeletePod,
+       })
 }
 
 func (ctx *Context) IsPluginMode() bool {
        return ctx.pluginMode
 }
 
 func (ctx *Context) addNode(obj interface{}) {
+       ctx.updateNode(nil, obj)
+}
+
+func (ctx *Context) updateNode(_, obj interface{}) {
        ctx.lock.Lock()
        defer ctx.lock.Unlock()
-
        node, err := convertToNode(obj)
        if err != nil {
                log.Log(log.ShimContext).Error("node conversion failed", 
zap.Error(err))
                return
        }
-
-       // add node to secondary scheduler cache
-       log.Log(log.ShimContext).Warn("adding node to cache", 
zap.String("NodeName", node.Name))
-       ctx.schedulerCache.AddNode(node)
-
-       // add node to internal cache
-       ctx.nodes.addNode(node)
-
-       // post the event
-       events.GetRecorder().Eventf(node.DeepCopy(), nil, v1.EventTypeNormal, 
"NodeAccepted", "NodeAccepted",
-               fmt.Sprintf("node %s is accepted by the scheduler", node.Name))
+       ctx.updateNodeInternal(node, true)
 }
 
-func (ctx *Context) updateNode(oldObj, newObj interface{}) {
-       ctx.lock.Lock()
-       defer ctx.lock.Unlock()
+func (ctx *Context) updateNodeInternal(node *v1.Node, register bool) {
+       // update scheduler cache
+       if prevNode, adoptedPods := ctx.schedulerCache.UpdateNode(node); 
prevNode == nil {
+               // newly added node
+
+               // if requested, register this node with the scheduler core. 
this is optional to allow for bulk registration
+               // during scheduler initialization.
+               if register {
+                       if err := ctx.registerNode(node); err != nil {
+                               // remove from secondary cache and return

Review Comment:
   We do, there's just not as much stored separately. Primary cache (context) 
contains YK-specific objects, secondary contains K8s ones.



-- 
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]

Reply via email to