Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
wenqiq committed Mar 8, 2024
1 parent ec533f0 commit 739bb90
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
35 changes: 22 additions & 13 deletions test/performance/framework/client_pod/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
}
Expand Down Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions test/performance/framework/networkpolicy/scale_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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)
}
}()
Expand Down Expand Up @@ -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
}

0 comments on commit 739bb90

Please sign in to comment.