From f29f9790ea56d95f53bccf27df590349aedc53ff Mon Sep 17 00:00:00 2001 From: lowang-bh Date: Sun, 13 Jul 2025 20:50:09 +0800 Subject: [PATCH] fix: same pod condition type should only exist one item Signed-off-by: lowang-bh --- component/ascend-for-volcano/common/util/task.go | 11 ++++++++++- component/ascend-for-volcano/plugin/task.go | 15 +++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/component/ascend-for-volcano/common/util/task.go b/component/ascend-for-volcano/common/util/task.go index a0775fbc7..13f7c1f7a 100644 --- a/component/ascend-for-volcano/common/util/task.go +++ b/component/ascend-for-volcano/common/util/task.go @@ -29,6 +29,7 @@ import ( "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog" + podutil "k8s.io/kubernetes/pkg/api/v1/pod" "volcano.sh/volcano/pkg/scheduler/api" "volcano.sh/volcano/pkg/scheduler/framework" ) @@ -154,7 +155,15 @@ func (asTask *NPUTask) UpdatePodPendingReason(taskInfo *api.TaskInfo, reasonTmp return nil } } - taskInfo.Pod.Status.Conditions = append(taskInfo.Pod.Status.Conditions, condition) + + // Fix: same PodConditionType should only exist one in conditions list. + // UpdatePodCondition will add this condition if its type doesn't exist, + // or do update if it exist and condition changed + hasUpdate := podutil.UpdatePodCondition(&taskInfo.Pod.Status, &condition) + if hasUpdate { + klog.V(LogDebugLev).Infof("UpdatePodPendingReason check whether pod has update return %v.", hasUpdate) + } + return nil } diff --git a/component/ascend-for-volcano/plugin/task.go b/component/ascend-for-volcano/plugin/task.go index f43618156..b75b83dcc 100644 --- a/component/ascend-for-volcano/plugin/task.go +++ b/component/ascend-for-volcano/plugin/task.go @@ -25,6 +25,7 @@ import ( "k8s.io/api/core/v1" "k8s.io/klog" + podutil "k8s.io/kubernetes/pkg/api/v1/pod" "volcano.sh/volcano/pkg/scheduler/api" "volcano.sh/volcano/pkg/scheduler/plugins/ascend-volcano-plugin/common/util" @@ -152,13 +153,15 @@ func updatePodPendingReason(task *api.TaskInfo, reasonTmp string) { Reason: v1.PodReasonUnschedulable, Message: reasonTmp, } - for _, tmp := range task.Pod.Status.Conditions { - if strings.Contains(tmp.Message, reasonTmp) { - klog.V(util.LogDebugLev).Infof("%s has record the reason:%s ,skip.", task.Name, reasonTmp) - return - } + + // Fix: same PodConditionType should only exist one in conditions list. + // UpdatePodCondition will add this condition if its type doesn't exist, + // or do update if it exist and condition changed + if hasUpdate := podutil.UpdatePodCondition(&task.Pod.Status, &condition); !hasUpdate { + klog.V(util.LogDebugLev).Infof("%s has record the reason: %s ,skip.", task.Name, reasonTmp) } - task.Pod.Status.Conditions = append(task.Pod.Status.Conditions, condition) + + return } // isNPUTask to judge the task either is NPU task or not. -- Gitee