Skip to content

Commit 3eda508

Browse files
giorio94adamjensenbot
authored andcommitted
Adapt E2E tests to the new pod reflection
1 parent 5e8673d commit 3eda508

File tree

2 files changed

+28
-41
lines changed

2 files changed

+28
-41
lines changed

test/e2e/testutils/net/pod.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ func CheckTesterPods(ctx context.Context,
6969
homeClient, cluster1Client, cluster2Client kubernetes.Interface,
7070
homeClusterID string, cluster1, cluster2 *TesterOpts) bool {
7171
reflectedNamespace := TestNamespaceName + "-" + homeClusterID
72-
if !util.IsPodUp(ctx, homeClient, TestNamespaceName, cluster1.PodName, true) ||
73-
!util.IsPodUp(ctx, homeClient, TestNamespaceName, cluster2.PodName, true) {
72+
if !util.IsPodUp(ctx, homeClient, TestNamespaceName, cluster1.PodName, util.PodLocal) ||
73+
!util.IsPodUp(ctx, homeClient, TestNamespaceName, cluster2.PodName, util.PodLocal) {
7474
return false
7575
}
7676
if cluster1.Offloaded {
77-
if !util.IsPodUp(ctx, cluster1Client, reflectedNamespace, cluster1.PodName, false) {
77+
if !util.IsPodUp(ctx, cluster1Client, reflectedNamespace, cluster1.PodName, util.PodRemote) {
7878
return false
7979
}
8080
}
8181
if cluster2.Offloaded {
82-
if !util.IsPodUp(ctx, cluster2Client, reflectedNamespace, cluster2.PodName, false) {
82+
if !util.IsPodUp(ctx, cluster2Client, reflectedNamespace, cluster2.PodName, util.PodRemote) {
8383
return false
8484
}
8585
}

test/e2e/testutils/util/pod.go

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,53 +17,40 @@ package util
1717
import (
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

Comments
 (0)