Skip to content

[tmpnet] Avoid port forwarding when running in a kube cluster #3997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions tests/fixture/tmpnet/kube_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@
}
}

// TODO(marun) Detect whether this test code is running inside the cluster
// and use the URI directly
// Use direct pod URI if running inside the cluster
if p.isRunningInCluster() {
return p.node.URI, func() {}, nil
}

port, stopChan, err := p.forwardPort(ctx, config.DefaultHTTPPort)
if err != nil {
Expand All @@ -164,8 +166,10 @@
}
}

// TODO(marun) Detect whether this test code is running inside the cluster
// and use the URI directly
// Use direct pod staking address if running inside the cluster
if p.isRunningInCluster() {
return p.node.StakingAddress, func() {}, nil
}

port, stopChan, err := p.forwardPort(ctx, config.DefaultStakingPort)
if err != nil {
Expand Down Expand Up @@ -837,3 +841,11 @@
},
}
}

// isRunningInCluster detects if this code is running inside a Kubernetes cluster
// by checking for the presence of the service account token that's automatically
// mounted in every pod.
func (p *KubeRuntime) isRunningInCluster() bool {

Check failure on line 848 in tests/fixture/tmpnet/kube_runtime.go

View workflow job for this annotation

GitHub Actions / Lint

unused-receiver: method receiver 'p' is not referenced in method's body, consider removing or renaming it as _ (revive)
_, err := os.Stat("/var/run/secrets/kubernetes.io/serviceaccount/token")
return err == nil
}
Loading