Skip to content

Commit e2002a6

Browse files
fix: allow for load tests to run in-cluster (#4003)
1 parent 7f8d659 commit e2002a6

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

tests/fixture/tmpnet/flags/kubeconfig.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,17 @@ func newKubeconfigFlagSetVars(flagSet *pflag.FlagSet, docPrefix string) *Kubecon
4545
}
4646

4747
func (v *KubeconfigVars) register(stringVar varFunc[string], docPrefix string) {
48+
// the default kubeConfig path is set to empty to allow for the use of a projected
49+
// token when running in-cluster
50+
var defaultKubeConfigPath string
51+
if !tmpnet.IsRunningInCluster() {
52+
defaultKubeConfigPath = os.ExpandEnv("$HOME/.kube/config")
53+
}
54+
4855
stringVar(
4956
&v.Path,
5057
"kubeconfig",
51-
tmpnet.GetEnvWithDefault(KubeconfigPathEnvVar, os.ExpandEnv("$HOME/.kube/config")),
58+
tmpnet.GetEnvWithDefault(KubeconfigPathEnvVar, defaultKubeConfigPath),
5259
docPrefix+fmt.Sprintf(
5360
"The path to a kubernetes configuration file for the target cluster. Also possible to configure via the %s env variable.",
5461
KubeconfigPathEnvVar,

tests/fixture/tmpnet/kube_runtime.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (p *KubeRuntime) GetLocalURI(ctx context.Context) (string, func(), error) {
145145
}
146146

147147
// Use direct pod URI if running inside the cluster
148-
if isRunningInCluster() {
148+
if IsRunningInCluster() {
149149
return p.node.URI, func() {}, nil
150150
}
151151

@@ -167,7 +167,7 @@ func (p *KubeRuntime) GetLocalStakingAddress(ctx context.Context) (netip.AddrPor
167167
}
168168

169169
// Use direct pod staking address if running inside the cluster
170-
if isRunningInCluster() {
170+
if IsRunningInCluster() {
171171
return p.node.StakingAddress, func() {}, nil
172172
}
173173

@@ -842,10 +842,10 @@ func configureExclusiveScheduling(template *corev1.PodTemplateSpec, labelKey str
842842
}
843843
}
844844

845-
// isRunningInCluster detects if this code is running inside a Kubernetes cluster
845+
// IsRunningInCluster detects if this code is running inside a Kubernetes cluster
846846
// by checking for the presence of the service account token that's automatically
847847
// mounted in every pod.
848-
func isRunningInCluster() bool {
848+
func IsRunningInCluster() bool {
849849
_, err := os.Stat("/var/run/secrets/kubernetes.io/serviceaccount/token")
850850
return err == nil
851851
}

0 commit comments

Comments
 (0)