29 lines
974 B
Go
29 lines
974 B
Go
package helper
|
|
|
|
import (
|
|
corev1 "k8s.io/api/core/v1"
|
|
)
|
|
|
|
// GetPodCondition extracts the provided condition from the given status and returns that.
|
|
// Returns nil and -1 if the condition is not present, and the index of the located condition.
|
|
func GetPodCondition(status *corev1.PodStatus, conditionType corev1.PodConditionType) (int, *corev1.PodCondition) {
|
|
if status == nil {
|
|
return -1, nil
|
|
}
|
|
return GetPodConditionFromList(status.Conditions, conditionType)
|
|
}
|
|
|
|
// GetPodConditionFromList extracts the provided condition from the given list of condition and
|
|
// returns the index of the condition and the condition. Returns -1 and nil if the condition is not present.
|
|
func GetPodConditionFromList(conditions []corev1.PodCondition, conditionType corev1.PodConditionType) (int, *corev1.PodCondition) {
|
|
if conditions == nil {
|
|
return -1, nil
|
|
}
|
|
for i := range conditions {
|
|
if conditions[i].Type == conditionType {
|
|
return i, &conditions[i]
|
|
}
|
|
}
|
|
return -1, nil
|
|
}
|