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 23, 2024
1 parent e4638d9 commit a2d68d5
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 95 deletions.
2 changes: 1 addition & 1 deletion test/performance/framework/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func ScaleRestartAgent(ctx context.Context, ch chan time.Duration, data *ScaleDa
go func() {
podList, err := data.kubernetesClientSet.CoreV1().Pods(client_pod.ClientPodsNamespace).List(ctx, metav1.ListOptions{LabelSelector: client_pod.ScaleClientPodTemplateName})
if err != nil {
err = fmt.Errorf("error when getting scale test client pods: %w", err)
klog.ErrorS(err, "error when getting scale test client pods")
return
}
for _, pod := range podList.Items {
Expand Down
2 changes: 0 additions & 2 deletions test/performance/framework/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func (c *ScaleTestCase) Run(ctx context.Context, testData *ScaleData) error {
testData.maxCheckNum = 10000
ress := make(chan time.Duration, testData.maxCheckNum)
res := "failed"
// actualCheckNum := 0
scaleNum := 0
defer func() {
close(ress)
Expand All @@ -91,7 +90,6 @@ func (c *ScaleTestCase) Run(ctx context.Context, testData *ScaleData) error {
if err != nil {
return err.(error)
}
// actualCheckNum = scaleRes.actualCheckNum
scaleNum = scaleRes.scaleNum
res = "success"
}
Expand Down
4 changes: 2 additions & 2 deletions test/performance/framework/client_pod/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package client_pod

import (
"fmt"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/google/uuid"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
)

Expand Down
14 changes: 14 additions & 0 deletions test/performance/framework/client_pod/update_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Antrea Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package client_pod

import (
Expand Down
84 changes: 0 additions & 84 deletions test/performance/framework/networkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,90 +185,6 @@ func (nps networkPolicies) scaleUp(ctx context.Context) (actualCheckNum int, err
return
}

func SelectConnectPod(ctx context.Context, cs kubernetes.Interface, ns string, np *NetworkPolicyInfo) (fromPod *corev1.Pod, toPodIP string, err error) {
klog.V(2).InfoS("Checking connectivity of the NetworkPolicy", "NetworkPolicyName", np.Name, "Namespace", np.Namespace)
if _, ok := np.Spec.PodSelector.MatchLabels[utils.PodOnRealNodeLabelKey]; !ok {
np.Spec.PodSelector.MatchLabels[utils.PodOnRealNodeLabelKey] = ""
}
podList, err := cs.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: metav1.FormatLabelSelector(&np.Spec.PodSelector)})
if err != nil {
return nil, "", fmt.Errorf("error when selecting networkpolicy applied to pods: %w", err)
}
if len(podList.Items) == 0 {
klog.V(2).InfoS("No Pod is selected by the NetworkPolicy, skip", "NetworkPolicyName", np.Name, "Namespace", np.Namespace)
return nil, "", nil
}
var fromPods []corev1.Pod
var toPods []corev1.Pod
if len(np.Spec.Ingress) > 0 {
toPods = podList.Items
if err := utils.DefaultRetry(func() error {
podSelector := np.Spec.Ingress[0].From[0].PodSelector
podSelector.MatchLabels[utils.PodOnRealNodeLabelKey] = ""
fromPodsList, err := cs.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: metav1.FormatLabelSelector(podSelector)})
if err != nil {
return err
}
fromPods = fromPodsList.Items
return nil
}); err != nil {
return nil, "", fmt.Errorf("error when retrieving Pods: %w", err)
}
} else if len(np.Spec.Egress) > 0 {
fromPods = podList.Items
if err := utils.DefaultRetry(func() error {
podSelector := np.Spec.Egress[0].To[0].PodSelector
podSelector.MatchLabels[utils.PodOnRealNodeLabelKey] = ""
toPodsList, err := cs.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: metav1.FormatLabelSelector(podSelector)})
if err != nil {
return err
}
toPods = toPodsList.Items
return nil
}); err != nil {
return nil, "", fmt.Errorf("error when retrieving Pods: %w", err)
}
}

if len(toPods) == 0 || len(fromPods) == 0 {
klog.V(2).InfoS("Skipping the check of the NetworkPolicy, since the label selector does not match any Pod", "NetworkPolicy", np.Name)
return nil, "", nil
}
fromPodsNum, toPodsNum := len(fromPods), len(toPods)
klog.V(2).InfoS("Select test Pods", "fromPodsNum", fromPodsNum, "toPodsNum", toPodsNum)
toPod := toPods[int(utils.GenRandInt())%toPodsNum]
fromPod = &fromPods[int(utils.GenRandInt())%fromPodsNum]
if toPod.Status.PodIP == "" {
return nil, "", fmt.Errorf("podIP is nil, Namespace: %s, Name: %s", toPod.Namespace, toPod.Name)
}
toPodIP = toPod.Status.PodIP
return
}

func SelectIsoPod(ctx context.Context, cs kubernetes.Interface, ns string, np NetworkPolicyInfo, clientPods []corev1.Pod) (fromPod *corev1.Pod, toPodIP string, err error) {
klog.V(2).InfoS("Checking isolation of the NetworkPolicy", "NetworkPolicyName", np.Name, "Namespace", np.Namespace)
podList, err := cs.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: metav1.FormatLabelSelector(&np.Spec.PodSelector)})
if err != nil {
return nil, "", fmt.Errorf("error when selecting networkpolicy applied to pods: %w", err)
}
if len(podList.Items) == 0 || len(clientPods) == 0 {
klog.V(2).InfoS("No Pod is selected by the NetworkPolicy, skip", "NetworkPolicyName", np.Name)
return nil, "", nil
}
var toPod corev1.Pod
if len(np.Spec.Ingress) > 0 {
fromPod = &clientPods[int(utils.GenRandInt())%len(clientPods)]
toPod = podList.Items[int(utils.GenRandInt())%len(podList.Items)]
} else if len(np.Spec.Egress) > 0 {
fromPod = &podList.Items[int(utils.GenRandInt())%len(podList.Items)]
toPod = clientPods[int(utils.GenRandInt())%len(clientPods)]
}
if toPod.Status.PodIP == "" {
return nil, "", fmt.Errorf("podIP is nil, Namespace: %s, Name: %s", toPod.Namespace, toPod.Name)
}
return
}

func selectServerPod(ctx context.Context, cs kubernetes.Interface, ns string, np NetworkPolicyInfo) (toPodIP string, err error) {
klog.V(2).InfoS("Checking isolation of the NetworkPolicy", "NetworkPolicyName", np.Name, "Namespace", np.Namespace)
podList, err := cs.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: metav1.FormatLabelSelector(&np.Spec.PodSelector)})
Expand Down
4 changes: 2 additions & 2 deletions test/performance/framework/server_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"context"
"fmt"
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
"os"
"path"
"time"
Expand All @@ -28,6 +27,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/klog/v2"

"antrea.io/antrea/test/performance/config"
Expand Down Expand Up @@ -110,7 +110,7 @@ func ScaleUpWorkloadPods(ctx context.Context, ch chan time.Duration, data *Scale
if err != nil {
return
}
for i, _ := range pods {
for i := range pods {
pod := pods[i]
gErr.Go(func() error {
if _, err := data.kubernetesClientSet.CoreV1().Pods(ns).Create(ctx, pod, metav1.CreateOptions{}); err != nil {
Expand Down
5 changes: 2 additions & 3 deletions test/performance/framework/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@

package framework

//goland:noinspection ALL
import (
"antrea.io/antrea/test/performance/framework/client_pod"
"bytes"
"context"
"fmt"
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
"net"
"os"
"path"
Expand All @@ -33,11 +30,13 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/klog/v2"

"antrea.io/antrea/pkg/ipam/ipallocator"
"antrea.io/antrea/test/e2e/providers"
"antrea.io/antrea/test/performance/config"
"antrea.io/antrea/test/performance/framework/client_pod"
"antrea.io/antrea/test/performance/utils"
)

Expand Down
14 changes: 14 additions & 0 deletions test/performance/framework/service_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Antrea Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package framework

import (
Expand Down
14 changes: 14 additions & 0 deletions test/performance/framework/utils/praser.go
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
// Copyright 2024 Antrea Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package utils
14 changes: 14 additions & 0 deletions test/performance/monitoring/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/usr/bin/env bash
# Copyright 2024 Antrea Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


set -eo pipefail

Expand Down
2 changes: 1 addition & 1 deletion test/performance/utils/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"context"
"fmt"
"io"
"k8s.io/klog/v2"
"net/url"
"regexp"
"strconv"
Expand All @@ -32,6 +31,7 @@ import (
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/remotecommand"
"k8s.io/klog/v2"

"antrea.io/antrea/test/performance/framework/client_pod"
)
Expand Down
14 changes: 14 additions & 0 deletions test/performance/utils/exec_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Antrea Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package utils

import (
Expand Down

0 comments on commit a2d68d5

Please sign in to comment.