-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpod.go
33 lines (28 loc) · 966 Bytes
/
pod.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package kube
import (
"context"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
coreclient "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/kubectl/pkg/util/podutils"
)
var IsPodReady = podutils.IsPodReady
func GetPodList(ctx context.Context, client coreclient.PodsGetter, opts ...KubeOption) (*corev1.PodList, error) {
o := NewKubeOptions(opts)
options := metav1.ListOptions{LabelSelector: o.LabelSelector}
return client.Pods(o.Namespace).List(ctx, options)
}
// GetFirstPod returns a pod matching the namespace and label selector
// and the number of all pods that match the label selector.
func GetPods(ctx context.Context, client coreclient.PodsGetter, opts ...KubeOption) ([]*corev1.Pod, error) {
podList, err := GetPodList(ctx, client, opts...)
if err != nil {
return nil, err
}
pods := []*corev1.Pod{}
for i := range podList.Items {
pod := podList.Items[i]
pods = append(pods, &pod)
}
return pods, nil
}