...

Source file src/edge-infra.dev/pkg/edge/k8objectsutils/status/status.go

Documentation: edge-infra.dev/pkg/edge/k8objectsutils/status

     1  package status
     2  
     3  import (
     4  	corev1 "k8s.io/api/core/v1"
     5  )
     6  
     7  const (
     8  	CrashLoopBackOff = "CrashLoopBackOff"
     9  )
    10  
    11  // IsPodReady returns true if both of these are true:
    12  // - Pod's Phase is Running
    13  // - Pod's Ready condition is True
    14  func IsPodReady(pod *corev1.Pod) bool {
    15  	if pod.Status.Phase != corev1.PodRunning {
    16  		return false
    17  	}
    18  	for _, con := range pod.Status.Conditions {
    19  		if con.Type == corev1.PodReady && con.Status == corev1.ConditionTrue {
    20  			return true
    21  		}
    22  	}
    23  	return false
    24  }
    25  
    26  // IsContainerCLBO returns true if the container is in CrashLoopBackOff state
    27  // and has restarted more than threshold times.
    28  func IsContainerCLBO(status corev1.ContainerStatus, threshold uint16) bool {
    29  	if status.Ready {
    30  		return false
    31  	}
    32  	if status.State.Waiting == nil || status.State.Waiting.Reason != CrashLoopBackOff {
    33  		return false
    34  	}
    35  	return status.RestartCount > int32(threshold)
    36  }
    37  

View as plain text