Skip to content

Commit

Permalink
Add mutex for teardown synchronization and validate service port range
Browse files Browse the repository at this point in the history
  • Loading branch information
battlebyte committed Sep 16, 2024
1 parent ccb66c0 commit 3709b10
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions kong2kic/kong2kic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"regexp"
"strings"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -266,7 +267,14 @@ func setupTestingEnvironmentWithVersion(
return env, kongAddon, nil
}

// Mutex to avoid race condition on ~/.kube/config file
var teardownMutex sync.Mutex

func teardownEnvironment(ctx context.Context, t *testing.T, env environment.Environment) {
// Lock the mutex to ensure only one teardown process at a time
teardownMutex.Lock()
defer teardownMutex.Unlock()

t.Logf("cleaning up environment %s and cluster %s", env.Name(), env.Cluster().Name())
require.NoError(t, env.Cleanup(ctx))
}
Expand Down
4 changes: 4 additions & 0 deletions kong2kic/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func createIngressPaths(
},
}
if servicePort != nil {
// check that the port is within the valid range
if *servicePort > 65535 || *servicePort < 0 {
log.Fatalf("Port %d is not within the valid range. Please provide a port between 0 and 65535.\n", *servicePort)
}
backend.Service.Port.Number = int32(*servicePort)

Check failure on line 106 in kong2kic/route.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion int -> int32 (gosec)
}
paths = append(paths, k8snetv1.HTTPIngressPath{
Expand Down
4 changes: 4 additions & 0 deletions kong2kic/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func createK8sService(service *file.FService, upstreams []file.FUpstream) *k8sco

// Set the service port
if service.Port != nil {
// check that the port is within the valid range
if *service.Port > 65535 || *service.Port < 0 {
log.Fatalf("Port %d is not within the valid range. Please provide a port between 0 and 65535.\n", *service.Port)
}
servicePort := k8scorev1.ServicePort{
Protocol: protocol,
Port: int32(*service.Port),

Check failure on line 74 in kong2kic/service.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion int -> int32 (gosec)
Expand Down

0 comments on commit 3709b10

Please sign in to comment.