Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gao12312 committed Dec 19, 2024
1 parent 28ef86c commit 7b58919
Showing 1 changed file with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func (c *RootPodSyncReconciler) SetupWithManager(mgr manager.Manager) error {
return false
},
UpdateFunc: func(updateEvent event.UpdateEvent) bool {
pod1 := updateEvent.ObjectOld.(*corev1.Pod)
pod2 := updateEvent.ObjectNew.(*corev1.Pod)
old := updateEvent.ObjectOld.(*corev1.Pod)
curr := updateEvent.ObjectNew.(*corev1.Pod)
if !skipFunc(updateEvent.ObjectNew) {
return false
}
return !reflect.DeepEqual(pod1.Status, pod2.Status)
return !reflect.DeepEqual(old.Status, curr.Status)
},
DeleteFunc: func(deleteEvent event.DeleteEvent) bool {
return false
Expand Down Expand Up @@ -85,17 +85,7 @@ func (c *RootPodSyncReconciler) Reconcile(ctx context.Context, request reconcile
klog.Errorf("get %s error: %v", request.NamespacedName, err)
return reconcile.Result{RequeueAfter: utils.DefaultRequeueTime}, nil
}

if !podutils.IsKosmosPod(&rootpod) {
klog.V(4).Info("Pod is not create by kosmos tree, ignore")
return reconcile.Result{}, nil
}

if !c.GlobalLeafManager.HasNode(rootpod.Spec.NodeName) {
klog.Errorf("Failed to get leaf Node %s", rootpod.Spec.NodeName)
return reconcile.Result{}, nil
}

//get LeafResource
lr, err := c.GlobalLeafManager.GetLeafResourceByNodeName(rootpod.Spec.NodeName)
if err != nil {
klog.Errorf("Failed to get leaf client for %s", rootpod.Spec.NodeName)
Expand All @@ -119,8 +109,12 @@ func (c *RootPodSyncReconciler) Reconcile(ctx context.Context, request reconcile
rPodCopy := rootpod.DeepCopy()
rPodCopy.Status = leafPod.Status
podutils.FitObjectMeta(&rPodCopy.ObjectMeta)
if err := c.RootClient.Status().Update(ctx, rPodCopy); err != nil && !apierrors.IsNotFound(err) {
klog.Errorf("error while updating rootpod status in kubernetes, %s", err)
if err := c.RootClient.Status().Update(ctx, rPodCopy); err != nil {
if apierrors.IsNotFound(err) {
klog.Errorf("rootpod %s not found while updating status", rootpod.Name)
} else {
klog.Errorf("error while updating rootpod status in kubernetes, %s", err)
}
return reconcile.Result{}, nil
}
klog.Infof("update rootpod %s status success", leafPod.Name)
Expand Down

0 comments on commit 7b58919

Please sign in to comment.