Skip to content

Commit 0ed667e

Browse files
authored
Enhance pool namespace resolution: use flag if set, else NAMESPACE en… (#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 f9fbbfd commit 0ed667e

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
@@ -80,7 +80,7 @@ var (
8080
enablePprof = flag.Bool("enable-pprof", runserver.DefaultEnablePprof, "Enables pprof handlers. Defaults to true. Set to false to disable pprof handlers.")
8181
poolName = flag.String("pool-name", runserver.DefaultPoolName, "Name of the InferencePool this Endpoint Picker is associated with.")
8282
poolGroup = flag.String("pool-group", runserver.DefaultPoolGroup, "group of the InferencePool this Endpoint Picker is associated with.")
83-
poolNamespace = flag.String("pool-namespace", runserver.DefaultPoolNamespace, "Namespace of the InferencePool this Endpoint Picker is associated with.")
83+
poolNamespace = flag.String("pool-namespace", "", "Namespace of the InferencePool this Endpoint Picker is associated with.")
8484
logVerbosity = flag.Int("v", logging.DEFAULT, "number for the log level verbosity")
8585
secureServing = flag.Bool("secure-serving", runserver.DefaultSecureServing, "Enables secure serving. Defaults to true.")
8686
healthChecking = flag.Bool("health-checking", runserver.DefaultHealthChecking, "Enables health checking")
@@ -188,9 +188,20 @@ func (r *Runner) Run(ctx context.Context) error {
188188
FilterProvider: filters.WithAuthenticationAndAuthorization,
189189
}
190190

191+
// Determine pool namespace: if --pool-namespace is non-empty, use it; else NAMESPACE env var; else default
192+
resolvePoolNamespace := func() string {
193+
if *poolNamespace != "" {
194+
return *poolNamespace
195+
}
196+
if nsEnv := os.Getenv("NAMESPACE"); nsEnv != "" {
197+
return nsEnv
198+
}
199+
return runserver.DefaultPoolNamespace
200+
}
201+
resolvedPoolNamespace := resolvePoolNamespace()
191202
poolNamespacedName := types.NamespacedName{
192203
Name: *poolName,
193-
Namespace: *poolNamespace,
204+
Namespace: resolvedPoolNamespace,
194205
}
195206
poolGroupKind := schema.GroupKind{
196207
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)