Skip to content
Closed
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
70 changes: 68 additions & 2 deletions lib/backend-common/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ use crate::disagg::DisaggregationMode;
/// ```
#[derive(Args, Clone, Debug)]
pub struct CommonArgs {
/// Dynamo namespace for discovery routing.
#[arg(long, default_value = "dynamo", env = "DYN_NAMESPACE")]
/// Dynamo namespace for discovery routing. A non-empty
/// DYN_NAMESPACE_WORKER_SUFFIX is appended as "{namespace}-{suffix}".
#[arg(
long,
default_value = "dynamo",
env = "DYN_NAMESPACE",
value_parser = parse_worker_namespace

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operator upgrade workloads can supply an already-suffixed DYN_NAMESPACE together with DYN_NAMESPACE_WORKER_SUFFIX (for example, default-qwen-decode-<hash> and <hash> in deploy/operator/internal/controller/upgrade_test.go). Applying this value parser unconditionally turns that into default-qwen-decode-<hash>-<hash>, while the controller's published runtime namespace remains suffixed once. Rust sidecars then register outside the namespace used for the active worker generation. Preserve an already-applied worker suffix, or have the caller provide an unambiguous base namespace before appending.

🤖 AI Fix

Append DYN_NAMESPACE_WORKER_SUFFIX only when the parsed namespace does not already end with the exact hyphen-delimited suffix, and add coverage for an already-suffixed DYN_NAMESPACE.

)]
pub namespace: String,

/// Component name within the namespace.
Expand Down Expand Up @@ -95,3 +101,63 @@ pub struct CommonArgs {
#[arg(long, default_value_t = false, env = "DYN_ENABLE_RL")]
pub enable_rl: bool,
}

fn parse_worker_namespace(namespace: &str) -> Result<String, std::convert::Infallible> {
match std::env::var("DYN_NAMESPACE_WORKER_SUFFIX") {
Ok(suffix) if !suffix.is_empty() => Ok(format!("{namespace}-{suffix}")),
_ => Ok(namespace.to_owned()),
}
}

#[cfg(test)]
mod tests {
use clap::Parser;

use super::CommonArgs;

#[derive(Parser)]
struct TestArgs {
#[command(flatten)]
common: CommonArgs,
}

#[test]
#[serial_test::serial]
fn parses_namespace_without_worker_suffix() {
for suffix in [None, Some("")] {
temp_env::with_vars(
[
("DYN_NAMESPACE", Some("test-namespace")),
("DYN_NAMESPACE_WORKER_SUFFIX", suffix),
],
|| {
let args = TestArgs::try_parse_from(["test"]).unwrap();
assert_eq!(args.common.namespace, "test-namespace");
},
);
}
}

#[test]
#[serial_test::serial]
fn parses_namespace_with_worker_suffix() {
for (namespace, expected) in [
(Some("test-namespace"), "test-namespace-worker-hash"),
(None, "dynamo-worker-hash"),
] {
temp_env::with_vars(
[
("DYN_NAMESPACE", namespace),
("DYN_NAMESPACE_WORKER_SUFFIX", Some("worker-hash")),
],
|| {
let args = TestArgs::try_parse_from(["test"]).unwrap();
assert_eq!(args.common.namespace, expected);

let args = TestArgs::try_parse_from(["test", "--namespace", "cli"]).unwrap();
Comment thread
tmonty12 marked this conversation as resolved.
Resolved
assert_eq!(args.common.namespace, "cli-worker-hash");
},
);
}
}
}
Loading