From 739bb90b4169ed5e4b6988c73ad9f048473c7796 Mon Sep 17 00:00:00 2001 From: Wenqi Qiu Date: Fri, 8 Mar 2024 09:59:59 +0800 Subject: [PATCH] debug --- .../framework/client_pod/create.go | 35 ++++++++++++------- .../framework/networkpolicy/scale_up.go | 22 +++++++----- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/test/performance/framework/client_pod/create.go b/test/performance/framework/client_pod/create.go index 13928211d46..87fa0dda65a 100644 --- a/test/performance/framework/client_pod/create.go +++ b/test/performance/framework/client_pod/create.go @@ -29,23 +29,32 @@ import ( "k8s.io/klog/v2" ) -func CreateClientPod(ctx context.Context, kClient kubernetes.Interface, probes []string, containerName string) (*corev1.Pod, error) { +const ( + ScaleClientPodServerContainer = "client-pod-server" + ScaleClientPodProbeContainer = "networkpolicy-client-probe" +) + +func CreatePod(ctx context.Context, kClient kubernetes.Interface, probes []string, containerName string) (*corev1.Pod, error) { var err error var newPod *corev1.Pod namespace := ClientPodsNamespace podName := ScaleTestClientPodNamePrefix + uuid.New().String()[:6] err = retry.RetryOnConflict(retry.DefaultRetry, func() error { - newPod.Namespace = namespace - newPod.Name = podName - newPod.Spec = corev1.PodSpec{ - Affinity: &RealNodeAffinity, - Tolerations: []corev1.Toleration{MasterToleration}, - Containers: []corev1.Container{ - { - Name: ScaleClientContainerName, - Image: "busybox", - Command: []string{"nc", "-lk", "-p", "80"}, - ImagePullPolicy: corev1.PullIfNotPresent, + newPod = &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: podName, + Namespace: namespace, + }, + Spec: corev1.PodSpec{ + Affinity: &RealNodeAffinity, + Tolerations: []corev1.Toleration{MasterToleration}, + Containers: []corev1.Container{ + { + Name: ScaleClientPodServerContainer, + Image: "busybox", + Command: []string{"nc", "-lk", "-p", "80"}, + ImagePullPolicy: corev1.PullIfNotPresent, + }, }, }, } @@ -85,7 +94,7 @@ func CreateClientPod(ctx context.Context, kClient kubernetes.Interface, probes [ return nil, err } - err = wait.PollImmediate(time.Second, 30, func() (bool, error) { + err = wait.PollImmediate(2*time.Second, 60, func() (bool, error) { pod, err := kClient.CoreV1().Pods(namespace).Get(ctx, newPod.Name, metav1.GetOptions{}) if err != nil { return false, err diff --git a/test/performance/framework/networkpolicy/scale_up.go b/test/performance/framework/networkpolicy/scale_up.go index bca4258c55c..14020d564fa 100644 --- a/test/performance/framework/networkpolicy/scale_up.go +++ b/test/performance/framework/networkpolicy/scale_up.go @@ -15,14 +15,10 @@ package networkpolicy import ( - "antrea.io/antrea/test/performance/framework/client_pod" - "antrea.io/antrea/test/performance/framework/workload_pod" "context" "fmt" "time" - "k8s.io/klog/v2" - "github.com/google/uuid" corev1 "k8s.io/api/core/v1" netv1 "k8s.io/api/networking/v1" @@ -31,7 +27,9 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" + "k8s.io/klog/v2" + "antrea.io/antrea/test/performance/framework/client_pod" "antrea.io/antrea/test/performance/utils" ) @@ -117,17 +115,23 @@ func ScaleUp(ctx context.Context, kubeConfig *rest.Config, cs kubernetes.Interfa npInfo = NetworkPolicyInfo{Name: newNP.Name, Namespace: newNP.Namespace, Spec: newNP.Spec} if actualCheckNum < cap(ch) { startTimeStamp := time.Now().UnixNano() - serverIP, err := selectServerPod(ctx, cs, newNP.Namespace, npInfo) - if serverIP != "" && err == nil { + serverIP, err := selectServerPod(ctx, cs, ns, npInfo) + klog.InfoS("Select server Pod", "serverIP", serverIP, "error", err) + if err != nil { + klog.ErrorS(err, "selectServerPod") + return err + } + if serverIP != "" { actualCheckNum++ go func() { - clientPod, err := client_pod.CreateClientPod(ctx, cs, []string{fmt.Sprintf("%s:%d", serverIP, 80)}, "check"+np.Name) + clientPod, err := client_pod.CreatePod(ctx, cs, []string{fmt.Sprintf("%s:%d", serverIP, 80)}, client_pod.ScaleClientPodProbeContainer) if err != nil { klog.ErrorS(err, "Create client test Pod failed") + return } klog.InfoS("Update test Pod to check NetworkPolicy", "serverIP", serverIP) key := "to down" - if err := utils.FetchTimestampFromLog(ctx, cs, clientPod.Namespace, clientPod.Name, workload_pod.ScaleTestPodProbeContainerName, ch, startTimeStamp, key); err != nil { + if err := utils.FetchTimestampFromLog(ctx, cs, clientPod.Namespace, clientPod.Name, client_pod.ScaleClientPodProbeContainer, ch, startTimeStamp, key); err != nil { klog.ErrorS(err, "Checking the validity the NetworkPolicy error", "ClientPodName", clientPod.Name, "NetworkPolicy", npInfo) } }() @@ -281,5 +285,5 @@ func selectServerPod(ctx context.Context, cs kubernetes.Interface, ns string, np if toPod.Status.PodIP == "" { return "", fmt.Errorf("podIP is nil, Namespace: %s, Name: %s", toPod.Namespace, toPod.Name) } - return + return toPod.Status.PodIP, nil }