Skip to content

Commit

Permalink
Fix error handling at k8sclient
Browse files Browse the repository at this point in the history
Error logging at WritePodAnnotations was modified to use stored pod
data. Otherwise pod data used in the log message are not available
in case that pod is not found or update of its state fails.
Original code caused null pointer dereference and application crash
during unit test execution.

Signed-off-by: Martin Klozik <[email protected]>
  • Loading branch information
p00rman committed May 14, 2020
1 parent 673eeb0 commit e69d0b3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/k8sclient/k8sclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ func WritePodAnnotation(kubeClient kubernetes.Interface, pod *v1.Pod) (*v1.Pod,
return pod, err
}

// Keep original pod info for log message in case of failure
origPod := pod
// Update the pod
pod = pod.DeepCopy()
if resultErr := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
Expand All @@ -153,7 +155,7 @@ func WritePodAnnotation(kubeClient kubernetes.Interface, pod *v1.Pod) (*v1.Pod,
pod, err = kubeClient.CoreV1().Pods(pod.Namespace).UpdateStatus(pod)
return err
}); resultErr != nil {
return nil, logging.Errorf("status update failed for pod %s/%s: %v", pod.Namespace, pod.Name, resultErr)
return nil, logging.Errorf("status update failed for pod %s/%s: %v", origPod.Namespace, origPod.Name, resultErr)
}
return pod, nil
}

0 comments on commit e69d0b3

Please sign in to comment.