diff --git a/pkg/controllers/resources/pods/syncer.go b/pkg/controllers/resources/pods/syncer.go index c196f0e3d..48b240922 100644 --- a/pkg/controllers/resources/pods/syncer.go +++ b/pkg/controllers/resources/pods/syncer.go @@ -128,15 +128,10 @@ func (s *syncer) NewList() client.ObjectList { func (s *syncer) ForwardCreate(ctx context.Context, vObj client.Object, log loghelper.Logger) (ctrl.Result, error) { vPod := vObj.(*corev1.Pod) - pPod, err := s.translatePod(vPod) - if err != nil { - return ctrl.Result{}, err - } - if vPod.DeletionTimestamp != nil { // delete pod immediately log.Infof("delete pod %s/%s immediately, because it is being deleted & there is no physical pod", vPod.Namespace, vPod.Name) - err = s.virtualClient.Delete(ctx, vPod, &client.DeleteOptions{ + err := s.virtualClient.Delete(ctx, vPod, &client.DeleteOptions{ GracePeriodSeconds: &zero, }) if kerrors.IsNotFound(err) { @@ -145,6 +140,11 @@ func (s *syncer) ForwardCreate(ctx context.Context, vObj client.Object, log logh return ctrl.Result{}, err } + pPod, err := s.translatePod(vPod) + if err != nil { + return ctrl.Result{}, err + } + // ensure node selector if s.nodeSelector != nil { // 2 cases: