From cf4fb1f532404c1bf16fa270ec9ccf5cf20cdeaf Mon Sep 17 00:00:00 2001 From: rambohe-ch Date: Mon, 6 Jan 2025 16:31:07 +1100 Subject: [PATCH] fix add pod request into reconcile queue instead of node Signed-off-by: rambohe-ch --- .../podbinding/pod_binding_controller.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/yurtmanager/controller/yurtcoordinator/podbinding/pod_binding_controller.go b/pkg/yurtmanager/controller/yurtcoordinator/podbinding/pod_binding_controller.go index b6f58bc695b..05ce8c0291d 100644 --- a/pkg/yurtmanager/controller/yurtcoordinator/podbinding/pod_binding_controller.go +++ b/pkg/yurtmanager/controller/yurtcoordinator/podbinding/pod_binding_controller.go @@ -92,7 +92,7 @@ func Add(ctx context.Context, cfg *appconfig.CompletedConfig, mgr manager.Manage continue } if len(pods[i].Spec.NodeName) != 0 { - wq.Add(reconcile.Request{NamespacedName: types.NamespacedName{Name: pods[i].Spec.NodeName}}) + wq.Add(reconcile.Request{NamespacedName: types.NamespacedName{Namespace: pods[i].Namespace, Name: pods[i].Name}}) } } }, @@ -114,6 +114,13 @@ func Add(ctx context.Context, cfg *appconfig.CompletedConfig, mgr manager.Manage if !ok { return false } + + // only process edge nodes, and skip nodes with other type. + if newNode.Labels[projectinfo.GetEdgeWorkerLabelKey()] != "true" { + klog.Infof("node %s is not a edge node, skip node autonomy settings reconcile.", newNode.Name) + return false + } + // only enqueue if autonomy annotations changed if (oldNode.Annotations[projectinfo.GetAutonomyAnnotation()] != newNode.Annotations[projectinfo.GetAutonomyAnnotation()]) || (oldNode.Annotations[projectinfo.GetNodeAutonomyDurationAnnotation()] != newNode.Annotations[projectinfo.GetNodeAutonomyDurationAnnotation()]) { @@ -194,11 +201,11 @@ func Add(ctx context.Context, cfg *appconfig.CompletedConfig, mgr manager.Manage // Reconcile reads that state of Node in cluster and makes changes if node autonomy state has been changed func (r *ReconcilePodBinding) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { + klog.Infof("reconcile pod request: %s/%s", req.Namespace, req.Name) pod := &corev1.Pod{} if err := r.Get(ctx, req.NamespacedName, pod); err != nil { return reconcile.Result{}, client.IgnoreNotFound(err) } - klog.Infof("reconcile pod request: %s/%s", pod.Namespace, pod.Name) if err := r.reconcilePod(pod); err != nil { return reconcile.Result{}, err @@ -218,6 +225,11 @@ func (r *ReconcilePodBinding) reconcilePod(pod *corev1.Pod) error { return client.IgnoreNotFound(err) } + // skip pods which don't run on edge nodes + if node.Labels[projectinfo.GetEdgeWorkerLabelKey()] != "true" { + return nil + } + storedPod := pod.DeepCopy() if isAutonomous, duration := resolveNodeAutonomySetting(node); isAutonomous { // update pod tolerationSeconds according to node autonomy annotation,