Skip to content

Commit

Permalink
Address golangci-lint v1.60.3 errors
Browse files Browse the repository at this point in the history
Specifically, gosec "integer overflow conversion" issues.

Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis committed Aug 27, 2024
1 parent 4c6cc4f commit 0a3b7a0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion test/e2e/framework/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/framework/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
},
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 14 additions & 14 deletions test/e2e/framework/network_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/framework/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
}},
},
Expand All @@ -62,15 +62,15 @@ 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)

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

Expand Down
6 changes: 6 additions & 0 deletions test/e2e/framework/test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"flag"
"os"
"strings"
"time"

"github.com/onsi/ginkgo/v2/types"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -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
}

0 comments on commit 0a3b7a0

Please sign in to comment.