Skip to content

Commit

Permalink
Merge pull request #282 from wzshiming/automated-cherry-pick-of-#276-…
Browse files Browse the repository at this point in the history
…upstream-release-0.1

Automated cherry pick of #276: Uniform "not found" output
  • Loading branch information
wzshiming authored Feb 13, 2023
2 parents a4e6c38 + 7d48975 commit a046693
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
16 changes: 12 additions & 4 deletions pkg/kwok/controllers/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,20 @@ func (c *NodeController) FinalizersModify(ctx context.Context, node *corev1.Node
}

logger := log.FromContext(ctx)
logger = logger.With(
"node", node.Name,
)
_, err = c.clientSet.CoreV1().Nodes().Patch(ctx, node.Name, types.JSONPatchType, data, metav1.PatchOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
logger.Error("node not found", err,
"node", node.Name,
logger.Warn("Patch node finalizers",
"err", err,
)
return nil
}
return err
}
logger.Info("Patch node finalizers")
return nil
}

Expand All @@ -313,7 +317,9 @@ func (c *NodeController) DeleteNode(ctx context.Context, node *corev1.Node) erro
err := c.clientSet.CoreV1().Nodes().Delete(ctx, node.Name, deleteOpt)
if err != nil {
if apierrors.IsNotFound(err) {
logger.Error("node not found", err)
logger.Warn("Delete node",
"err", err,
)
return nil
}
return err
Expand Down Expand Up @@ -429,7 +435,9 @@ func (c *NodeController) lockNode(ctx context.Context, node *corev1.Node, patch
_, err := c.clientSet.CoreV1().Nodes().Patch(ctx, node.Name, types.StrategicMergePatchType, patch, metav1.PatchOptions{}, "status")
if err != nil {
if apierrors.IsNotFound(err) {
logger.Error("node not found", err)
logger.Warn("Patch node",
"err", err,
)
return nil
}
return err
Expand Down
18 changes: 15 additions & 3 deletions pkg/kwok/controllers/pod_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,23 @@ func (c *PodController) FinalizersModify(ctx context.Context, pod *corev1.Pod, f
if err != nil {
return err
}

logger := log.FromContext(ctx)
logger = logger.With(
"pod", log.KObj(pod),
"node", pod.Spec.NodeName,
)
_, err = c.clientSet.CoreV1().Pods(pod.Namespace).Patch(ctx, pod.Name, types.JSONPatchType, data, metav1.PatchOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
logger.Error("pod not found", err, "node", pod.Name)
logger.Warn("Patch pod finalizers",
"err", err,
)
return nil
}
return err
}
logger.Info("Patch pod finalizers")
return nil
}

Expand All @@ -191,7 +199,9 @@ func (c *PodController) DeletePod(ctx context.Context, pod *corev1.Pod) error {
err := c.clientSet.CoreV1().Pods(pod.Namespace).Delete(ctx, pod.Name, deleteOpt)
if err != nil {
if apierrors.IsNotFound(err) {
logger.Warn("Delete pod", err)
logger.Warn("Delete pod",
"err", err,
)
return nil
}
return err
Expand Down Expand Up @@ -310,7 +320,9 @@ func (c *PodController) lockPod(ctx context.Context, pod *corev1.Pod, patch []by
_, err := c.clientSet.CoreV1().Pods(pod.Namespace).Patch(ctx, pod.Name, types.StrategicMergePatchType, patch, metav1.PatchOptions{}, "status")
if err != nil {
if apierrors.IsNotFound(err) {
logger.Warn("Patch pod", err)
logger.Warn("Patch pod",
"err", err,
)
return nil
}
return err
Expand Down

0 comments on commit a046693

Please sign in to comment.