INNER CODE UNIT · Go

keepWaitingForMainContainerToExit

secureCodeBox/secureCodeBox · lurker/main.go:172

func keepWaitingForMainContainerToExit(context context.Context, container string, podName string, namespace string, clientset *kubernetes.Clientset) bool {
	pod, err := clientset.CoreV1().Pods(namespace).Get(context, podName, metav1.GetOptions{})
	if apierrors.IsNotFound(err) {
		log.Printf("Pod %s not found in namespace %s", pod, namespace)
	} else if statusError, isStatus := err.(*apierrors.StatusError); isStatus {
		log.Printf("Error getting pod %v", statusError.ErrStatus.Message)
	} else if err != nil {
		panic(err.Error())
	}

	return !mainContainerExited(container, pod.Status.ContainerStatuses)
}

func mainContainerExited(container string, containerStatuses []corev1.ContainerStatus) bool {
	for _, status := range containerStatuses {
		if status.Name == container && status.State.Terminated != nil {
			log.Printf("Main Container exited. Lurker will end as well.")
			return true

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…