@@ -17,53 +17,40 @@ package util
1717import (
1818 "context"
1919
20- corev1 "k8s.io/api/core/v1"
2120 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22- "k8s.io/apimachinery/pkg/labels"
2321 "k8s.io/client-go/kubernetes"
2422 "k8s.io/klog/v2"
2523
2624 "github.com/liqotech/liqo/pkg/utils/pod"
27- "github.com/liqotech/liqo/pkg/virtualKubelet"
25+ )
26+
27+ // PodType -> defines the type of a pod (local/remote).
28+ type PodType string
29+
30+ const (
31+ // PodLocal -> the pod is local.
32+ PodLocal = "local"
33+ // PodRemote -> the pod is remote.
34+ PodRemote = "remote"
2835)
2936
3037// IsPodUp waits for a specific namespace/podName to be ready. It returns true if the pod within the timeout, false otherwise.
31- func IsPodUp (ctx context.Context , client kubernetes.Interface , namespace , podName string , isHomePod bool ) bool {
32- var podToCheck * corev1.Pod
33- var err error
34- var labelSelector = map [string ]string {
35- virtualKubelet .ReflectedpodKey : podName ,
38+ func IsPodUp (ctx context.Context , client kubernetes.Interface , namespace , podName string , podType PodType ) bool {
39+ klog .Infof ("checking if %s pod %s/%s is ready" , podType , namespace , podName )
40+ podToCheck , err := client .CoreV1 ().Pods (namespace ).Get (ctx , podName , metav1.GetOptions {})
41+ if err != nil {
42+ klog .Errorf ("an error occurred while getting %s pod %s/%s: %v" , podType , namespace , podName , err )
43+ return false
3644 }
37- if isHomePod {
38- klog .Infof ("checking if local pod %s/%s is ready" , namespace , podName )
39- podToCheck , err = client .CoreV1 ().Pods (namespace ).Get (ctx , podName , metav1.GetOptions {})
40- if err != nil {
41- klog .Errorf ("an error occurred while getting pod %s/%s: %v" , namespace , podName , err )
42- return false
43- }
44- } else {
45- labelSelector := labels .SelectorFromSet (labelSelector ).String ()
46- klog .Infof ("checking if remote pod is ready in namespace %s and label selector %s" , namespace , labelSelector )
47- pods , err := client .CoreV1 ().Pods (namespace ).List (ctx , metav1.ListOptions {
48- LabelSelector : labelSelector ,
49- })
50- if err != nil {
51- klog .Errorf ("an error occurred while getting remote pod: %v" , err )
52- return false
53- }
54- if len (pods .Items ) == 0 {
55- klog .Error ("an error occurred: remote pod not found" )
56- return false
57- }
58- podToCheck = & pods .Items [0 ]
59- }
60- state := pod .IsPodReady (podToCheck )
61- if isHomePod {
62- klog .Infof ("local pod %s/%s is ready" , podToCheck .Namespace , podToCheck .Name )
63- } else {
64- klog .Infof ("remote pod %s/%s is ready" , podToCheck .Namespace , podToCheck .Name )
45+
46+ ready := pod .IsPodReady (podToCheck )
47+ message := "ready"
48+ if ! ready {
49+ message = "NOT ready"
6550 }
66- return state
51+
52+ klog .Infof ("%s pod %s/%s is %s" , podType , podToCheck .Namespace , podToCheck .Name , message )
53+ return ready
6754}
6855
6956// ArePodsUp check if all the pods of a specific namespace are ready. It returns a list of ready pods, a list of unready
0 commit comments