Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/node-labeler/cmd/podutils.go
2498 views
1
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import corev1 "k8s.io/api/core/v1"
8
9
// IsPodReady returns true if a pod is ready; false otherwise.
10
func IsPodReady(pod corev1.Pod) bool {
11
return IsPodReadyConditionTrue(pod.Status)
12
}
13
14
// IsPodReadyConditionTrue returns true if a pod is ready; false otherwise.
15
func IsPodReadyConditionTrue(status corev1.PodStatus) bool {
16
condition := GetPodReadyCondition(status)
17
return condition != nil && condition.Status == corev1.ConditionTrue
18
}
19
20
// GetPodReadyCondition extracts the pod ready condition from the given status and returns that.
21
// Returns nil if the condition is not present.
22
func GetPodReadyCondition(status corev1.PodStatus) *corev1.PodCondition {
23
_, condition := GetPodCondition(&status, corev1.PodReady)
24
return condition
25
}
26
27
// GetPodCondition extracts the provided condition from the given status and returns that.
28
// Returns nil and -1 if the condition is not present, and the index of the located condition.
29
func GetPodCondition(status *corev1.PodStatus, conditionType corev1.PodConditionType) (int, *corev1.PodCondition) {
30
if status == nil {
31
return -1, nil
32
}
33
34
for i := range status.Conditions {
35
if status.Conditions[i].Type == conditionType {
36
return i, &status.Conditions[i]
37
}
38
}
39
40
return -1, nil
41
}
42
43