Skip to content

Commit

Permalink
Fix golint
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Qiu <[email protected]>
  • Loading branch information
wenqiq committed Mar 24, 2024
1 parent 0ef720d commit 0039d9a
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 170 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ require (
github.com/mdlayher/packet v1.1.2
github.com/miekg/dns v1.1.58
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
github.com/olekukonko/tablewriter v0.0.4
github.com/onsi/ginkgo/v2 v2.17.0
github.com/onsi/gomega v1.32.0
github.com/olekukonko/tablewriter v0.0.4
github.com/pkg/sftp v1.13.6
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/common v0.47.0
Expand Down
3 changes: 2 additions & 1 deletion test/performance/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import (
)

const (
WaitInterval = 5 * time.Second
WaitInterval = 5 * time.Second
DefaultTimeout = 60 * time.Second
)

type ScaleConfiguration struct {
Expand Down
9 changes: 4 additions & 5 deletions test/performance/framework/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package framework

//goland:noinspection ALL
import (
"context"
"fmt"
Expand Down Expand Up @@ -57,7 +56,7 @@ func ScaleRestartAgent(ctx context.Context, ch chan time.Duration, data *ScaleDa
}
startTime := time.Now().UnixNano()

err = wait.PollImmediateUntil(config.WaitInterval, func() (bool, error) {
err = wait.PollUntilContextTimeout(ctx, config.WaitInterval, config.DefaultTimeout, true, func(ctx context.Context) (bool, error) {
var ds *appv1.DaemonSet
if err := utils.DefaultRetry(func() error {
var err error
Expand All @@ -71,7 +70,7 @@ func ScaleRestartAgent(ctx context.Context, ch chan time.Duration, data *ScaleDa
klog.V(2).InfoS("Check agent restart", "DesiredNumberScheduled", ds.Status.DesiredNumberScheduled,
"NumberAvailable", ds.Status.NumberAvailable)
return ds.Status.DesiredNumberScheduled == ds.Status.NumberAvailable, nil
}, ctx.Done())
})

go func() {
podList, err := data.kubernetesClientSet.CoreV1().Pods(client_pod.ClientPodsNamespace).List(ctx, metav1.ListOptions{LabelSelector: client_pod.ScaleClientPodTemplateName})
Expand Down Expand Up @@ -139,7 +138,7 @@ func RestartController(ctx context.Context, ch chan time.Duration, data *ScaleDa
startTime := time.Now().UnixNano()
klog.InfoS("Deleting operate time", "Duration(ms)", (startTime-startTime0)/1000000)

err = wait.PollImmediateUntil(config.WaitInterval, func() (bool, error) {
err = wait.PollUntilContextTimeout(ctx, config.WaitInterval, config.DefaultTimeout, true, func(ctx context.Context) (bool, error) {
var dp *appv1.Deployment
if err := utils.DefaultRetry(func() error {
var err error
Expand All @@ -149,7 +148,7 @@ func RestartController(ctx context.Context, ch chan time.Duration, data *ScaleDa
return false, err
}
return dp.Status.ObservedGeneration == dp.Generation && dp.Status.ReadyReplicas == *dp.Spec.Replicas, nil
}, ctx.Done())
})

go func() {
key := "down to up"
Expand Down
80 changes: 3 additions & 77 deletions test/performance/framework/client_pod/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/google/uuid"
corev1 "k8s.io/api/core/v1"
Expand All @@ -27,6 +26,8 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"

"antrea.io/antrea/test/performance/config"
)

const (
Expand Down Expand Up @@ -95,7 +96,7 @@ func CreatePod(ctx context.Context, kClient kubernetes.Interface, probes []strin
return nil, err
}

err = wait.PollWithContext(ctx, 3*time.Second, 60*time.Second, func(ctx context.Context) (bool, error) {
err = wait.PollUntilContextTimeout(ctx, config.WaitInterval, config.DefaultTimeout, true, func(ctx context.Context) (bool, error) {
pod, err := kClient.CoreV1().Pods(namespace).Get(ctx, newPod.Name, metav1.GetOptions{})
klog.V(4).InfoS("Checking client Pod status", "Name", newPod.Name, "Namespace", namespace, "Status", pod.Status)
if err != nil {
Expand All @@ -110,78 +111,3 @@ func CreatePod(ctx context.Context, kClient kubernetes.Interface, probes []strin
klog.InfoS("Create Client Pod successfully!")
return newPod, nil
}

//
// func CreateClientPod(ctx context.Context, kClient kubernetes.Interface, namespace, podName string, probes []string, containerName string) (*corev1.Pod, error) {
// var err error
// expectContainerNum := 0
// var newPod *corev1.Pod
// err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
// pod, err := kClient.CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{})
// if err != nil {
// return err
// }
// var containers []corev1.Container
// for _, probe := range probes {
// l := strings.Split(probe, ":")
// server, port := l[0], l[1]
// if server == "" {
// server = "$NODE_IP"
// }
//
// containers = append(containers, corev1.Container{
// Name: containerName,
// Image: "busybox",
// // read up rest </proc/uptime; t1="${up%.*}${up#*.}"
// Command: []string{"/bin/sh", "-c", fmt.Sprintf("server=%s; output_file=\"ping_log.txt\"; if [ ! -e \"$output_file\" ]; then touch \"$output_file\"; fi; last_status=\"unknown\"; last_change_time=$(adjtimex | awk '/(time.tv_sec|time.tv_usec):/ { printf(\"%%06d\", $2) }' && printf \"\\n\"); while true; do current_time=$(adjtimex | awk '/(time.tv_sec|time.tv_usec):/ { printf(\"%%06d\", $2) }' && printf \"\\n\"); status=$(nc -vz -w 1 \"$server\" %s > /dev/null && echo \"up\" || echo \"down\"); time_diff=$((current_time - last_change_time)); if [ \"$status\" != \"$last_status\" ]; then echo \"$current_time Status changed from $last_status to $status after ${time_diff} nanoseconds\"; echo \"$current_time Status changed from $last_status to $status after ${time_diff} nanoseconds\" >> \"$output_file\"; last_change_time=$current_time; last_status=$status; fi; sleep 0.1; done\n", server, port)},
// ImagePullPolicy: corev1.PullIfNotPresent,
// Env: []corev1.EnvVar{
// {
// Name: "NODE_IP",
// ValueFrom: &corev1.EnvVarSource{
// FieldRef: &corev1.ObjectFieldSelector{
// FieldPath: "status.hostIP",
// },
// },
// },
// },
// })
// }
//
// pod.Spec.Containers = append(pod.Spec.Containers, containers...)
// expectContainerNum = len(pod.Spec.Containers)
//
// newPod = &corev1.Pod{
// ObjectMeta: metav1.ObjectMeta{
// Name: strings.Replace(pod.Name, "server", "client", 1),
// Namespace: pod.Namespace,
// Labels: pod.Labels,
// },
// Spec: pod.Spec,
// }
//
// _, err = kClient.CoreV1().Pods(namespace).Create(ctx, newPod, metav1.CreateOptions{})
// return err
// })
// if err != nil {
// return nil, err
// }
//
// err = wait.PollWithContext(ctx, 3*time.Second, 60*time.Second, func(ctx context.Context) (bool, error) {
// pod, err := kClient.CoreV1().Pods(namespace).Get(ctx, newPod.Name, metav1.GetOptions{})
// if err != nil {
// return false, err
// }
//
// if expectContainerNum == len(pod.Spec.Containers) && pod.Status.Phase == corev1.PodRunning {
// return true, nil
// }
// return false, nil
// })
//
// if err != nil {
// return nil, err
// }
// klog.InfoS("Create Client Pod successfully!")
// return newPod, nil
// }
4 changes: 2 additions & 2 deletions test/performance/framework/client_pod/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Update(ctx context.Context, kClient kubernetes.Interface, ns, clientDaemonS

klog.InfoS("DaemonSet updated successfully!", "Name", clientDaemonSetName)

if err := wait.PollImmediateUntil(config.WaitInterval, func() (bool, error) {
if err := wait.PollUntilContextTimeout(ctx, config.WaitInterval, config.DefaultTimeout, true, func(ctx context.Context) (bool, error) {
ds, err := kClient.AppsV1().DaemonSets(ns).Get(ctx, clientDaemonSetName, metav1.GetOptions{})
if err != nil {
return false, nil
Expand All @@ -107,7 +107,7 @@ func Update(ctx context.Context, kClient kubernetes.Interface, ns, clientDaemonS
clientPods = podList.Items
klog.InfoS("All Pods in DaemonSet updated successfully!", "Name", clientDaemonSetName, "PodNum", len(podList.Items))
return true, nil
}, ctx.Done()); err != nil {
}); err != nil {
return nil, fmt.Errorf("error when waiting scale test clients to be ready: %w", err)
}
return
Expand Down
9 changes: 2 additions & 7 deletions test/performance/framework/namespace/scale_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func ScaleDown(ctx context.Context, cs kubernetes.Interface, nsPrefix string) er
return err
}
}
return wait.PollImmediateUntil(config.WaitInterval, func() (done bool, err error) {
return wait.PollUntilContextTimeout(ctx, config.WaitInterval, config.DefaultTimeout, true, func(ctx context.Context) (done bool, err error) {
count := 0
for _, ns := range nssToDelete {
if err := cs.CoreV1().Namespaces().Delete(ctx, ns, metav1.DeleteOptions{}); errors.IsNotFound(err) {
Expand All @@ -96,10 +96,5 @@ func ScaleDown(ctx context.Context, cs kubernetes.Interface, nsPrefix string) er
}
klog.InfoS("Waiting for clean up namespaces", "all", len(nssToDelete), "deletedCount", count)
return count == len(nssToDelete), nil
}, ctx.Done())
}

// ScaleDownOnlyPods delete pods only so it will get recreated inside same ns
func ScaleDownOnlyPods(ctx context.Context) error {
return nil
})
}
4 changes: 2 additions & 2 deletions test/performance/framework/networkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (nps networkPolicies) scaleDown(ctx context.Context) error {
klog.V(2).InfoS("Deleted NetworkPolicies", "namespace", ns)
}

return wait.PollImmediateUntil(config.WaitInterval, func() (done bool, err error) {
return wait.PollUntilContextTimeout(ctx, config.WaitInterval, config.DefaultTimeout, true, func(ctx context.Context) (done bool, err error) {
cleanCount := 0
staleNpNum := 0
for _, ns := range nss {
Expand All @@ -240,5 +240,5 @@ func (nps networkPolicies) scaleDown(ctx context.Context) error {
}
klog.InfoS("Scale down NetworkPolicies", "CleanedNamespaceNum", cleanCount, "staleNpNum", staleNpNum)
return cleanCount == len(nss), nil
}, ctx.Done())
})
}
4 changes: 2 additions & 2 deletions test/performance/framework/server_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func ScaleUpWorkloadPods(ctx context.Context, ch chan time.Duration, data *Scale
}

// Waiting scale workload Pods to be ready
err = wait.PollUntil(config.WaitInterval, func() (bool, error) {
err = wait.PollUntilContextTimeout(ctx, config.WaitInterval, config.DefaultTimeout, true, func(ctx context.Context) (bool, error) {
podsResult, err := data.kubernetesClientSet.
CoreV1().Pods(ns).
List(ctx, metav1.ListOptions{LabelSelector: fmt.Sprintf("%s=%s", client_pod.AppLabelKey, client_pod.AppLabelValue)})
Expand All @@ -142,7 +142,7 @@ func ScaleUpWorkloadPods(ctx context.Context, ch chan time.Duration, data *Scale
return count >= data.podsNumPerNs, nil
}
return false, nil
}, ctx.Done())
})
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions test/performance/framework/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func scaleDown(ctx context.Context, data *ScaleData, svcs []ServiceInfo) error {
}
klog.V(2).InfoS("Deleted service", "serviceName", svc)
}
return wait.PollImmediateUntil(config.WaitInterval, func() (done bool, err error) {
return wait.PollUntilContextTimeout(ctx, config.WaitInterval, config.DefaultTimeout, true, func(ctx context.Context) (done bool, err error) {
count := 0
for _, svc := range svcs {
if err := cs.CoreV1().Services(svc.NameSpace).Delete(ctx, svc.Name, metav1.DeleteOptions{}); errors.IsNotFound(err) {
Expand All @@ -262,5 +262,5 @@ func scaleDown(ctx context.Context, data *ScaleData, svcs []ServiceInfo) error {
}
klog.InfoS("Scale down Services", "Services", len(svcs), "cleanedUpCount", count)
return count == len(svcs), nil
}, ctx.Done())
})
}
12 changes: 6 additions & 6 deletions test/performance/framework/set_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ func createTestPodClients(ctx context.Context, kClient kubernetes.Interface, ns
}); err != nil {
return err
}
if err := wait.PollImmediateUntil(config.WaitInterval, func() (bool, error) {
if err := wait.PollUntilContextTimeout(ctx, config.WaitInterval, config.DefaultTimeout, true, func(ctx context.Context) (bool, error) {
ds, err := kClient.AppsV1().DaemonSets(ns).Get(ctx, client_pod.ScaleTestClientDaemonSet, metav1.GetOptions{})
if err != nil {
return false, nil
}
return ds.Status.DesiredNumberScheduled == ds.Status.NumberReady, nil
}, ctx.Done()); err != nil {
}); err != nil {
return fmt.Errorf("error when waiting scale test clients to be ready: %w", err)
}
if err := wait.PollImmediateUntil(config.WaitInterval, func() (bool, error) {
if err := wait.PollUntilContextTimeout(ctx, config.WaitInterval, config.DefaultTimeout, true, func(ctx context.Context) (bool, error) {
podList, err := kClient.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: client_pod.ScaleClientPodTemplateName})
if err != nil {
return false, nil
Expand All @@ -96,7 +96,7 @@ func createTestPodClients(ctx context.Context, kClient kubernetes.Interface, ns
}
}
return true, nil
}, ctx.Done()); err != nil {
}); err != nil {
return fmt.Errorf("error when waiting scale test clients to get IP: %w", err)
}
return nil
Expand Down Expand Up @@ -217,7 +217,7 @@ func ScaleUp(ctx context.Context, kubeConfigPath, scaleConfigPath, templateFiles
}
klog.Infof("Checking scale test client DaemonSet")
expectClientNum := td.nodesNum - td.simulateNodesNum
err = wait.PollImmediateUntil(config.WaitInterval, func() (bool, error) {
err = wait.PollUntilContextTimeout(ctx, config.WaitInterval, config.DefaultTimeout, true, func(ctx context.Context) (bool, error) {
podList, err := kClient.CoreV1().Pods(client_pod.ClientPodsNamespace).List(ctx, metav1.ListOptions{LabelSelector: client_pod.ScaleClientPodTemplateName})
if err != nil {
return false, fmt.Errorf("error when getting scale test client pods: %w", err)
Expand All @@ -228,7 +228,7 @@ func ScaleUp(ctx context.Context, kubeConfigPath, scaleConfigPath, templateFiles
klog.InfoS("Waiting test client DaemonSet Pods ready", "podsNum", len(podList.Items),
"expectClientNum", expectClientNum)
return false, nil
}, ctx.Done())
})
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 0039d9a

Please sign in to comment.