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, diff --git a/pkg/yurtmanager/controller/yurtcoordinator/podbinding/pod_binding_controller_test.go b/pkg/yurtmanager/controller/yurtcoordinator/podbinding/pod_binding_controller_test.go index d8bf46857e3..89c1b4baa70 100644 --- a/pkg/yurtmanager/controller/yurtcoordinator/podbinding/pod_binding_controller_test.go +++ b/pkg/yurtmanager/controller/yurtcoordinator/podbinding/pod_binding_controller_test.go @@ -30,6 +30,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake" "sigs.k8s.io/controller-runtime/pkg/reconcile" + + "github.com/openyurtio/openyurt/pkg/projectinfo" ) func podIndexer(rawObj client.Object) []string { @@ -90,6 +92,9 @@ func TestReconcile(t *testing.T) { node: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: "node1", + Labels: map[string]string{ + projectinfo.GetEdgeWorkerLabelKey(): "true", + }, Annotations: map[string]string{ "node.openyurt.io/autonomy-duration": "100s", }, @@ -151,6 +156,9 @@ func TestReconcile(t *testing.T) { node: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: "node1", + Labels: map[string]string{ + projectinfo.GetEdgeWorkerLabelKey(): "true", + }, Annotations: map[string]string{ "node.openyurt.io/autonomy-duration": "0s", }, @@ -214,6 +222,9 @@ func TestReconcile(t *testing.T) { node: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: "node1", + Labels: map[string]string{ + projectinfo.GetEdgeWorkerLabelKey(): "true", + }, }, }, resultPod: &corev1.Pod{