Skip to content

Commit f486835

Browse files
jyizhengBenjaminBraunDev
authored andcommitted
Enhance pool namespace resolution: use flag if set, else NAMESPACE en… (kubernetes-sigs#1578)
* Enhance pool namespace resolution: use flag if set, else NAMESPACE env var, else default; add documentation for behavior * address comments * treat empty string as unset, use flag value if non-empty, else env var, else default * address comments * update doc * relocate document
1 parent 04ae592 commit f486835

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

cmd/epp/runner/runner.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ var (
8383
enablePprof = flag.Bool("enable-pprof", runserver.DefaultEnablePprof, "Enables pprof handlers. Defaults to true. Set to false to disable pprof handlers.")
8484
poolName = flag.String("pool-name", runserver.DefaultPoolName, "Name of the InferencePool this Endpoint Picker is associated with.")
8585
poolGroup = flag.String("pool-group", runserver.DefaultPoolGroup, "group of the InferencePool this Endpoint Picker is associated with.")
86-
poolNamespace = flag.String("pool-namespace", runserver.DefaultPoolNamespace, "Namespace of the InferencePool this Endpoint Picker is associated with.")
86+
poolNamespace = flag.String("pool-namespace", "", "Namespace of the InferencePool this Endpoint Picker is associated with.")
8787
logVerbosity = flag.Int("v", logging.DEFAULT, "number for the log level verbosity")
8888
secureServing = flag.Bool("secure-serving", runserver.DefaultSecureServing, "Enables secure serving. Defaults to true.")
8989
healthChecking = flag.Bool("health-checking", runserver.DefaultHealthChecking, "Enables health checking")
@@ -195,9 +195,20 @@ func (r *Runner) Run(ctx context.Context) error {
195195
FilterProvider: filters.WithAuthenticationAndAuthorization,
196196
}
197197

198+
// Determine pool namespace: if --pool-namespace is non-empty, use it; else NAMESPACE env var; else default
199+
resolvePoolNamespace := func() string {
200+
if *poolNamespace != "" {
201+
return *poolNamespace
202+
}
203+
if nsEnv := os.Getenv("NAMESPACE"); nsEnv != "" {
204+
return nsEnv
205+
}
206+
return runserver.DefaultPoolNamespace
207+
}
208+
resolvedPoolNamespace := resolvePoolNamespace()
198209
poolNamespacedName := types.NamespacedName{
199210
Name: *poolName,
200-
Namespace: *poolNamespace,
211+
Namespace: resolvedPoolNamespace,
201212
}
202213
poolGroupKind := schema.GroupKind{
203214
Group: *poolGroup,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# EPP Configuration Flags
2+
3+
This page documents selected configuration flags for the Endpoint Picker (EPP) binary. Most flags are self-explanatory via their `--help` descriptions; only flags with nuanced or non-obvious behavior are detailed here.
4+
5+
## --pool-namespace
6+
7+
**Description:**
8+
Specifies the namespace of the InferencePool this Endpoint Picker is associated with.
9+
10+
**Resolution order:**
11+
1. If `--pool-namespace` is set to a non-empty value, its value is used.
12+
2. If the flag is not set (i.e., left empty), the `NAMESPACE` environment variable is checked. If set, its value is used.
13+
3. If neither is set, the namespace defaults to `default`.
14+
15+
This allows the EPP to automatically use the namespace it is running in (when the `NAMESPACE` env var is set via Kubernetes Downward API), without requiring explicit configuration. If you want to force the use of the default namespace, explicitly set `--pool-namespace=default`. If you want to use the environment variable or fallback, leave the flag unset or set it to an empty string.
16+
17+
**Example manifest snippet to set the env var from pod metadata:**
18+
19+
```yaml
20+
env:
21+
- name: NAMESPACE
22+
valueFrom:
23+
fieldRef:
24+
fieldPath: metadata.namespace
25+
```
26+
27+
---
28+
29+
For a full list of flags, run:
30+
31+
```
32+
EPP_BINARY --help
33+
```

0 commit comments

Comments
 (0)