This is an automated email from the ASF dual-hosted git repository.

wilfreds 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 5bad231e [YUNIKORN-3135] Foreign pods: improve updates (#987)
5bad231e is described below

commit 5bad231e000cc4b47950e9446a6149163cbb263c
Author: Peter Bacsko <[email protected]>
AuthorDate: Wed Nov 26 11:10:21 2025 +1100

    [YUNIKORN-3135] Foreign pods: improve updates (#987)
    
    Pods can be updated for multiple reasons. State changes are only part of
    the reason. For foreign pods, that do not change state, do not send an
    update to the core unless the pods' resources chgange.
    
    Improve test case TestAddUpdatePodForeign() to be slightly more realistic.
    
    Closes: #987
    
    Signed-off-by: Wilfred Spiegelenburg <[email protected]>
---
 pkg/cache/context.go      | 17 +++++++++--------
 pkg/cache/context_test.go | 10 ++++++----
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/pkg/cache/context.go b/pkg/cache/context.go
index 6e59be64..7c6abde4 100644
--- a/pkg/cache/context.go
+++ b/pkg/cache/context.go
@@ -213,7 +213,7 @@ func (ctx *Context) updateNodeInternal(node *v1.Node, 
register bool) {
                                zap.String("nodeName", node.Name))
                        applicationID := utils.GetApplicationIDFromPod(pod)
                        if applicationID == "" {
-                               ctx.updateForeignPod(pod)
+                               ctx.updateForeignPod(nil, pod)
                        } else {
                                ctx.updateYuniKornPod(applicationID, nil, pod)
                        }
@@ -315,7 +315,7 @@ func (ctx *Context) UpdatePod(oldObj, newObj interface{}) {
        }
        applicationID := utils.GetApplicationIDFromPod(pod)
        if applicationID == "" {
-               ctx.updateForeignPod(pod)
+               ctx.updateForeignPod(oldPod, pod)
        } else {
                ctx.updateYuniKornPod(applicationID, oldPod, pod)
        }
@@ -389,9 +389,8 @@ func (ctx *Context) ensureAppAndTaskCreated(pod *v1.Pod, 
app *Application) {
        }
 }
 
-func (ctx *Context) updateForeignPod(pod *v1.Pod) {
+func (ctx *Context) updateForeignPod(oldPod, pod *v1.Pod) {
        podStatusBefore := ""
-       oldPod := ctx.schedulerCache.GetPod(string(pod.UID))
        if oldPod != nil {
                podStatusBefore = string(oldPod.Status.Phase)
        }
@@ -408,10 +407,12 @@ func (ctx *Context) updateForeignPod(pod *v1.Pod) {
                                zap.String("podName", pod.Name),
                                zap.String("podStatusBefore", podStatusBefore),
                                zap.String("podStatusCurrent", 
string(pod.Status.Phase)))
-                       allocReq := common.CreateAllocationForForeignPod(pod)
-                       if err := 
ctx.apiProvider.GetAPIs().SchedulerAPI.UpdateAllocation(allocReq); err != nil {
-                               log.Log(log.ShimContext).Error("failed to add 
foreign allocation to the core",
-                                       zap.Error(err))
+                       if oldPod == nil || 
!common.Equals(common.GetPodResource(oldPod), common.GetPodResource(pod)) {
+                               allocReq := 
common.CreateAllocationForForeignPod(pod)
+                               if err := 
ctx.apiProvider.GetAPIs().SchedulerAPI.UpdateAllocation(allocReq); err != nil {
+                                       log.Log(log.ShimContext).Error("failed 
to add foreign allocation to the core",
+                                               zap.Error(err))
+                               }
                        }
                } else {
                        // pod is orphaned (references an unknown node)
diff --git a/pkg/cache/context_test.go b/pkg/cache/context_test.go
index ca71bc94..26dc7ed8 100644
--- a/pkg/cache/context_test.go
+++ b/pkg/cache/context_test.go
@@ -624,7 +624,8 @@ func TestAddUpdatePodForeign(t *testing.T) {
 
        // validate update (no change)
        allocRequest = nil
-       context.UpdatePod(nil, pod1)
+       pod1Upd := pod1.DeepCopy()
+       context.UpdatePod(pod1, pod1Upd)
        assert.Assert(t, allocRequest == nil, "unexpected update")
        pod = context.schedulerCache.GetPod(string(pod1.UID))
        assert.Assert(t, pod == nil, "unassigned pod found in cache")
@@ -643,8 +644,9 @@ func TestAddUpdatePodForeign(t *testing.T) {
 
        // validate update (no change)
        allocRequest = nil
-       context.UpdatePod(nil, pod2)
-       assert.Assert(t, allocRequest != nil, "update expected")
+       pod2Upd := pod2.DeepCopy()
+       context.UpdatePod(pod2, pod2Upd)
+       assert.Assert(t, allocRequest == nil, "unexpected update")
        pod = context.schedulerCache.GetPod(string(pod2.UID))
        assert.Assert(t, pod != nil, "pod not found in cache")
 
@@ -666,7 +668,7 @@ func TestAddUpdatePodForeign(t *testing.T) {
 
        // validate add
        allocRequest = nil
-       context.AddPod(pod3)
+       context.UpdatePod(pod2, pod3)
        assert.Assert(t, allocRequest != nil, "expected update")
        pod = context.schedulerCache.GetPod(string(pod3.UID))
        assert.Assert(t, pod == nil, "failed pod found in cache")


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to