Skip to content

Commit

Permalink
fix: fix incomplete cleanup in tunnel.json and zombie process in func…
Browse files Browse the repository at this point in the history
…tional test
  • Loading branch information
ComradeProgrammer committed May 20, 2024
1 parent 981083d commit f4e30a8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
10 changes: 8 additions & 2 deletions pkg/minikube/tunnel/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ func (r *persistentRegistry) IsAlreadyDefinedAndRunning(tunnel *ID) (*ID, error)
}

for _, t := range tunnels {
if t.Route.Equal(tunnel.Route) {
// it is possible that different tunnel can be started for different tunnel
// so we also need to check whether the machine name(profile name)
// when we want to identify duplicated tunnels
if tunnel.MachineName == t.MachineName && t.Route.Equal(tunnel.Route) {
isRunning, err := checkIfRunning(t.Pid)
if err != nil {
return nil, fmt.Errorf("error checking whether conflicting tunnel (%v) is running: %s", t, err)
Expand All @@ -87,7 +90,10 @@ func (r *persistentRegistry) Register(tunnel *ID) (rerr error) {

alreadyExists := false
for i, t := range tunnels {
if t.Route.Equal(tunnel.Route) {
// it is allowed for multiple minikube clusters to have multiple tunnels simultaneously
// it is possible that an old tunnel from an old profile has duplicated route information
// so we need to check both machine name and route information
if tunnel.MachineName == t.MachineName && t.Route.Equal(tunnel.Route) {
isRunning, err := checkIfRunning(t.Pid)
if err != nil {
return fmt.Errorf("error checking whether conflicting tunnel (%v) is running: %s", t, err)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestFunctional(t *testing.T) {

// TestFunctionalNewestKubernetes are functionality run functional tests using NewestKubernetesVersion
func TestFunctionalNewestKubernetes(t *testing.T) {
if strings.Contains(*startArgs, "--kubernetes-version") {
if strings.Contains(*startArgs, "--kubernetes-version") || constants.NewestKubernetesVersion == constants.DefaultKubernetesVersion {
t.Skip()
}
k8sVersionString := constants.NewestKubernetesVersion
Expand All @@ -90,7 +90,7 @@ func TestFunctionalNewestKubernetes(t *testing.T) {

func testFunctional(t *testing.T, k8sVersion string) {
profile := UniqueProfileName("functional")
ctx := context.WithValue(context.Background(), "k8sVersion", k8sVersion)
ctx := context.WithValue(context.Background(), ContextKey("k8sVersion"), k8sVersion)
ctx, cancel := context.WithTimeout(ctx, Minutes(40))
defer func() {
if !*cleanup {
Expand Down
5 changes: 5 additions & 0 deletions test/integration/functional_test_tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,9 @@ func validateTunnelDelete(_ context.Context, t *testing.T, _ string) {
checkRoutePassword(t)
// Stop tunnel
tunnelSession.Stop(t)
// prevent the child process from becoming a defunct zombie process
if err := tunnelSession.cmd.Wait(); err != nil {
t.Logf("failed to stop process: %v", err)
return
}
}
4 changes: 3 additions & 1 deletion test/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ func StartArgs() []string {
return strings.Split(*startArgs, " ")
}

type ContextKey string

func StartArgsWithContext(ctx context.Context) []string {
res := strings.Split(*startArgs, " ")
value := ctx.Value("k8sVersion")
value := ctx.Value(ContextKey("k8sVersion"))
if value != nil && value != "" {
res = append(res, fmt.Sprintf("--kubernetes-version=%s", value))
}
Expand Down

0 comments on commit f4e30a8

Please sign in to comment.