github.com/interconnectedcloud/qdr-operator@v0.0.0-20210826174505-576d2b33dac7/test/e2e/framework/pod.go (about) 1 package framework 2 3 import ( 4 "context" 5 "github.com/interconnectedcloud/qdr-operator/pkg/apis/interconnectedcloud/v1alpha1" 6 v1 "k8s.io/api/core/v1" 7 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 8 "time" 9 ) 10 11 // WaitForPodStatus waits for given podName to be available with a matching PodPhase 12 // or it returns a timeout. 13 func (f *Framework) WaitForPodStatus(podName string, status v1.PodPhase, timeout time.Duration, interval time.Duration) (*v1.Pod, error) { 14 15 var pod *v1.Pod 16 var err error 17 18 ctx, cancel := context.WithTimeout(context.TODO(), timeout) 19 defer cancel() 20 err = RetryWithContext(ctx, interval, func() (bool, error) { 21 pod, err = f.KubeClient.CoreV1().Pods(f.Namespace).Get(podName, metav1.GetOptions{}) 22 if err != nil { 23 // pod does not exist yet 24 return false, nil 25 } 26 return pod.Status.Phase == status, nil 27 }) 28 29 return pod, err 30 } 31 32 // GetInterconnectPods returns all pods for the given interconnect instance 33 func (f *Framework) GetInterconnectPods(ic *v1alpha1.Interconnect) ([]v1.Pod, error) { 34 options := metav1.ListOptions{LabelSelector: "application=" + ic.Name + ",interconnect_cr=" + ic.Name} 35 podList, err := f.KubeClient.CoreV1().Pods(ic.Namespace).List(options) 36 return podList.Items, err 37 } 38 39 // GetInterconnectPodNames returns all pod names for the given interconnect instance 40 func (f *Framework) GetInterconnectPodNames(ic *v1alpha1.Interconnect) ([]string, error) { 41 var podNames []string 42 pods, err := f.GetInterconnectPods(ic) 43 for _, pod := range pods { 44 podNames = append(podNames, pod.Name) 45 } 46 return podNames, err 47 }