Skip to content

Commit

Permalink
fix add pod request into reconcile queue instead of node (#2245)
Browse files Browse the repository at this point in the history
Signed-off-by: rambohe-ch <[email protected]>
  • Loading branch information
rambohe-ch authored Jan 6, 2025
1 parent b94aea8 commit 3217403
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
}
}
},
Expand All @@ -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()]) {
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 3217403

Please sign in to comment.