// Copyright (c) 2023 Gitpod GmbH. All rights reserved. // Licensed under the GNU Affero General Public License (AGPL). // See License.AGPL.txt in the project root for license information. package cmd import corev1 "k8s.io/api/core/v1" // IsPodReady returns true if a pod is ready; false otherwise. func IsPodReady(pod corev1.Pod) bool { return IsPodReadyConditionTrue(pod.Status) } // IsPodReadyConditionTrue returns true if a pod is ready; false otherwise. func IsPodReadyConditionTrue(status corev1.PodStatus) bool { condition := GetPodReadyCondition(status) return condition != nil && condition.Status == corev1.ConditionTrue } // GetPodReadyCondition extracts the pod ready condition from the given status and returns that. // Returns nil if the condition is not present. func GetPodReadyCondition(status corev1.PodStatus) *corev1.PodCondition { _, condition := GetPodCondition(&status, corev1.PodReady) return condition } // 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 } for i := range status.Conditions { if status.Conditions[i].Type == conditionType { return i, &status.Conditions[i] } } return -1, nil }