func()

in internal/controller/pod_controller.go [239:270]


func (r *podDeleteController) handlePodChanged(ctx context.Context, pod *corev1.Pod) error {

	wl := &workload.PodWorkload{Pod: pod}

	// Find all proxies that match this pod
	proxies, err := findMatchingProxies(ctx, r.Client, r.updater, wl)
	if err != nil {
		return fmt.Errorf("unable to find proxies when pod changed, %v", err)
	}

	// There are no proxies, ignore this event.
	if len(proxies) == 0 {
		return nil
	}

	// Check if this pod is in an error or waiting state and is missing
	// proxy containers.
	wlConfigErr := r.updater.CheckWorkloadContainers(wl, proxies)

	// If the pod is misconfigured, attempt to delete it.
	if wlConfigErr != nil {
		l := logf.FromContext(ctx)
		l.Info("Pod configured incorrectly. Deleting.",
			"Namespace", pod.Namespace, "Name", pod.Name, "Status", pod.Status)
		err = r.Client.Delete(ctx, pod)
		if err != nil && !apierrors.IsNotFound(err) {
			return fmt.Errorf("unable to delete pod %v/%v, %v", pod.Namespace, pod.Name, err)
		}
	}

	return nil
}