package status import ( corev1 "k8s.io/api/core/v1" ) const ( CrashLoopBackOff = "CrashLoopBackOff" ) // IsPodReady returns true if both of these are true: // - Pod's Phase is Running // - Pod's Ready condition is True func IsPodReady(pod *corev1.Pod) bool { if pod.Status.Phase != corev1.PodRunning { return false } for _, con := range pod.Status.Conditions { if con.Type == corev1.PodReady && con.Status == corev1.ConditionTrue { return true } } return false } // IsContainerCLBO returns true if the container is in CrashLoopBackOff state // and has restarted more than threshold times. func IsContainerCLBO(status corev1.ContainerStatus, threshold uint16) bool { if status.Ready { return false } if status.State.Waiting == nil || status.State.Waiting.Reason != CrashLoopBackOff { return false } return status.RestartCount > int32(threshold) }