Path: blob/main/components/node-labeler/cmd/podutils.go
2498 views
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package cmd56import corev1 "k8s.io/api/core/v1"78// IsPodReady returns true if a pod is ready; false otherwise.9func IsPodReady(pod corev1.Pod) bool {10return IsPodReadyConditionTrue(pod.Status)11}1213// IsPodReadyConditionTrue returns true if a pod is ready; false otherwise.14func IsPodReadyConditionTrue(status corev1.PodStatus) bool {15condition := GetPodReadyCondition(status)16return condition != nil && condition.Status == corev1.ConditionTrue17}1819// GetPodReadyCondition extracts the pod ready condition from the given status and returns that.20// Returns nil if the condition is not present.21func GetPodReadyCondition(status corev1.PodStatus) *corev1.PodCondition {22_, condition := GetPodCondition(&status, corev1.PodReady)23return condition24}2526// GetPodCondition extracts the provided condition from the given status and returns that.27// Returns nil and -1 if the condition is not present, and the index of the located condition.28func GetPodCondition(status *corev1.PodStatus, conditionType corev1.PodConditionType) (int, *corev1.PodCondition) {29if status == nil {30return -1, nil31}3233for i := range status.Conditions {34if status.Conditions[i].Type == conditionType {35return i, &status.Conditions[i]36}37}3839return -1, nil40}414243