diff --git a/test/e2e/framework/docker.go b/test/e2e/framework/docker.go index 572eb14b3..f88f9ace1 100644 --- a/test/e2e/framework/docker.go +++ b/test/e2e/framework/docker.go @@ -96,7 +96,7 @@ func (d *Docker) RunCommandUntil(command ...string) (string, string) { stdout, stderr, err = d.runCommand(command...) return err - }, time.Duration(TestContext.OperationTimeout)*time.Second, 5*time.Second).Should(Succeed(), + }, TestContext.OperationTimeoutToDuration(), 5*time.Second).Should(Succeed(), "Error attempting to run %v", append([]string{}, command...)) return stdout, stderr diff --git a/test/e2e/framework/endpoints.go b/test/e2e/framework/endpoints.go index 5bca84e99..59b7f7788 100644 --- a/test/e2e/framework/endpoints.go +++ b/test/e2e/framework/endpoints.go @@ -28,7 +28,7 @@ import ( typedv1 "k8s.io/client-go/kubernetes/typed/core/v1" ) -func (f *Framework) CreateTCPEndpoints(cluster ClusterIndex, epName, portName, address string, port int) *corev1.Endpoints { +func (f *Framework) CreateTCPEndpoints(cluster ClusterIndex, epName, portName, address string, port int32) *corev1.Endpoints { endpointsSpec := corev1.Endpoints{ ObjectMeta: metav1.ObjectMeta{ Name: epName, @@ -41,7 +41,7 @@ func (f *Framework) CreateTCPEndpoints(cluster ClusterIndex, epName, portName, a Ports: []corev1.EndpointPort{ { Name: portName, - Port: int32(port), + Port: port, Protocol: corev1.ProtocolTCP, }, }, diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 5c6fd6dd3..e7ac0e940 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -567,8 +567,7 @@ func AwaitUntil(opMsg string, doOperation DoOperationFunc, checkResult CheckResu func AwaitResultOrError(opMsg string, doOperation DoOperationFunc, checkResult CheckResultFunc) (interface{}, string, error) { var finalResult interface{} var lastMsg string - err := wait.PollUntilContextTimeout(context.Background(), 500*time.Millisecond, - time.Duration(TestContext.OperationTimeout)*time.Second, true, + err := wait.PollUntilContextTimeout(context.Background(), 500*time.Millisecond, TestContext.OperationTimeoutToDuration(), true, func(_ context.Context) (bool, error) { result, err := doOperation() if err != nil { diff --git a/test/e2e/framework/network_pods.go b/test/e2e/framework/network_pods.go index baa20986c..ec302802d 100644 --- a/test/e2e/framework/network_pods.go +++ b/test/e2e/framework/network_pods.go @@ -68,12 +68,12 @@ type NetworkPodConfig struct { Type NetworkPodType Cluster ClusterIndex Scheduling NetworkPodScheduling - Port int Data string NumOfDataBufs uint RemoteIP string ConnectionTimeout uint ConnectionAttempts uint + Port int32 Networking NetworkingType ContainerName string ImageName string @@ -281,10 +281,10 @@ func (np *NetworkPod) buildTCPCheckListenerPod() { " | nc -w $CONN_TIMEOUT -l -v -p $LISTEN_PORT -s 0.0.0.0 >/dev/termination-log 2>&1", }, Env: []v1.EnvVar{ - {Name: "LISTEN_PORT", Value: strconv.Itoa(np.Config.Port)}, + {Name: "LISTEN_PORT", Value: strconv.FormatInt(int64(np.Config.Port), 10)}, {Name: "SEND_STRING", Value: np.Config.Data}, - {Name: "CONN_TIMEOUT", Value: strconv.Itoa(int(np.Config.ConnectionTimeout * np.Config.ConnectionAttempts))}, - {Name: "BUFS_NUM", Value: strconv.Itoa(int(np.Config.NumOfDataBufs))}, + {Name: "CONN_TIMEOUT", Value: strconv.FormatUint(uint64(np.Config.ConnectionTimeout*np.Config.ConnectionAttempts), 10)}, + {Name: "BUFS_NUM", Value: strconv.FormatUint(uint64(np.Config.NumOfDataBufs), 10)}, }, SecurityContext: podSecurityContext, }, @@ -334,13 +334,13 @@ func (np *NetworkPod) buildTCPCheckConnectorPod() { " fi; done >/dev/termination-log 2>&1", }, Env: []v1.EnvVar{ - {Name: "REMOTE_PORT", Value: strconv.Itoa(np.Config.Port)}, + {Name: "REMOTE_PORT", Value: strconv.FormatInt(int64(np.Config.Port), 10)}, {Name: "SEND_STRING", Value: np.Config.Data}, {Name: "REMOTE_IP", Value: np.Config.RemoteIP}, - {Name: "CONN_TRIES", Value: strconv.Itoa(int(np.Config.ConnectionAttempts))}, - {Name: "CONN_TIMEOUT", Value: strconv.Itoa(int(np.Config.ConnectionTimeout))}, - {Name: "RETRY_SLEEP", Value: strconv.Itoa(int(np.Config.ConnectionTimeout / 2))}, - {Name: "BUFS_NUM", Value: strconv.Itoa(int(np.Config.NumOfDataBufs))}, + {Name: "CONN_TRIES", Value: strconv.FormatUint(uint64(np.Config.ConnectionAttempts), 10)}, + {Name: "CONN_TIMEOUT", Value: strconv.FormatUint(uint64(np.Config.ConnectionTimeout), 10)}, + {Name: "RETRY_SLEEP", Value: strconv.FormatUint(uint64(np.Config.ConnectionTimeout/2), 10)}, + {Name: "BUFS_NUM", Value: strconv.FormatUint(uint64(np.Config.NumOfDataBufs), 10)}, }, SecurityContext: podSecurityContext, }, @@ -384,10 +384,10 @@ func (np *NetworkPod) buildThroughputClientPod() { }, Env: []v1.EnvVar{ {Name: "TARGET_IP", Value: np.Config.RemoteIP}, - {Name: "TARGET_PORT", Value: strconv.Itoa(np.Config.Port)}, - {Name: "CONN_TRIES", Value: strconv.Itoa(int(np.Config.ConnectionAttempts))}, - {Name: "RETRY_SLEEP", Value: strconv.Itoa(int(np.Config.ConnectionTimeout))}, - {Name: "CONN_TIMEOUT", Value: strconv.Itoa(int(np.Config.ConnectionTimeout * 1000))}, + {Name: "TARGET_PORT", Value: strconv.FormatInt(int64(np.Config.Port), 10)}, + {Name: "CONN_TRIES", Value: strconv.FormatUint(uint64(np.Config.ConnectionAttempts), 10)}, + {Name: "RETRY_SLEEP", Value: strconv.FormatUint(uint64(np.Config.ConnectionTimeout), 10)}, + {Name: "CONN_TIMEOUT", Value: strconv.FormatUint(uint64(np.Config.ConnectionTimeout*1000), 10)}, }, SecurityContext: podSecurityContext, }, @@ -422,7 +422,7 @@ func (np *NetworkPod) buildThroughputServerPod() { ImagePullPolicy: v1.PullAlways, Command: []string{"sh", "-c", "iperf3 -s -p $TARGET_PORT"}, Env: []v1.EnvVar{ - {Name: "TARGET_PORT", Value: strconv.Itoa(np.Config.Port)}, + {Name: "TARGET_PORT", Value: strconv.FormatInt(int64(np.Config.Port), 10)}, }, SecurityContext: podSecurityContext, }, diff --git a/test/e2e/framework/services.go b/test/e2e/framework/services.go index d5e401b5e..a63853ff3 100644 --- a/test/e2e/framework/services.go +++ b/test/e2e/framework/services.go @@ -33,7 +33,7 @@ const ( TestAppLabel = "test-app" ) -func (f *Framework) NewService(name, portName string, port int, protocol corev1.Protocol, selector map[string]string, +func (f *Framework) NewService(name, portName string, port int32, protocol corev1.Protocol, selector map[string]string, isHeadless bool, ) *corev1.Service { service := corev1.Service{ @@ -42,9 +42,9 @@ func (f *Framework) NewService(name, portName string, port int, protocol corev1. }, Spec: corev1.ServiceSpec{ Ports: []corev1.ServicePort{{ - Port: int32(port), + Port: port, Name: portName, - TargetPort: intstr.FromInt(port), + TargetPort: intstr.FromInt32(port), Protocol: protocol, }}, }, @@ -62,7 +62,7 @@ func (f *Framework) NewService(name, portName string, port int, protocol corev1. return &service } -func (f *Framework) CreateTCPService(cluster ClusterIndex, selectorName string, port int) *corev1.Service { +func (f *Framework) CreateTCPService(cluster ClusterIndex, selectorName string, port int32) *corev1.Service { tcpService := f.NewService(fmt.Sprintf("test-svc-%s", selectorName), "tcp", port, corev1.ProtocolTCP, map[string]string{TestAppLabel: selectorName}, false) sc := KubeClients[cluster].CoreV1().Services(f.Namespace) @@ -70,7 +70,7 @@ func (f *Framework) CreateTCPService(cluster ClusterIndex, selectorName string, return f.CreateService(sc, tcpService) } -func (f *Framework) CreateHeadlessTCPService(cluster ClusterIndex, selectorName string, port int) *corev1.Service { +func (f *Framework) CreateHeadlessTCPService(cluster ClusterIndex, selectorName string, port int32) *corev1.Service { tcpService := f.NewService(fmt.Sprintf("test-svc-%s", selectorName), "tcp", port, corev1.ProtocolTCP, map[string]string{TestAppLabel: selectorName}, true) sc := KubeClients[cluster].CoreV1().Services(f.Namespace) @@ -121,7 +121,7 @@ func (f *Framework) NewNginxService(cluster ClusterIndex) *corev1.Service { return f.CreateService(sc, &nginxService) } -func (f *Framework) CreateTCPServiceWithoutSelector(cluster ClusterIndex, svcName, portName string, port int) *corev1.Service { +func (f *Framework) CreateTCPServiceWithoutSelector(cluster ClusterIndex, svcName, portName string, port int32) *corev1.Service { serviceSpec := f.NewService(svcName, portName, port, corev1.ProtocolTCP, nil, false) sc := KubeClients[cluster].CoreV1().Services(f.Namespace) diff --git a/test/e2e/framework/test_context.go b/test/e2e/framework/test_context.go index cf1b04f27..8110e37a5 100644 --- a/test/e2e/framework/test_context.go +++ b/test/e2e/framework/test_context.go @@ -22,6 +22,7 @@ import ( "flag" "os" "strings" + "time" "github.com/onsi/ginkgo/v2/types" "k8s.io/apimachinery/pkg/runtime/schema" @@ -87,3 +88,8 @@ func ValidateFlags(t *TestContextType) { klog.Fatalf("at least one kubernetes context must be specified.") } } + +func (t *TestContextType) OperationTimeoutToDuration() time.Duration { + //nolint:gosec // Ignore G115: integer overflow conversion uint -> int64 + return time.Duration(TestContext.OperationTimeout) * time.Second +}