@@ -163,7 +163,7 @@ pub enum Command<Run: Args = ProductOperatorRun> {
163163/// Can be embedded into an extended argument set:
164164///
165165/// ```rust
166- /// # use stackable_operator::cli::{Command, ProductOperatorRun, ProductConfigPath};
166+ /// # use stackable_operator::cli::{Command, OperatorEnvironmentOpts, ProductOperatorRun, ProductConfigPath};
167167/// use clap::Parser;
168168/// use stackable_operator::namespace::WatchNamespace;
169169/// use stackable_telemetry::tracing::TelemetryOptions;
@@ -176,14 +176,31 @@ pub enum Command<Run: Args = ProductOperatorRun> {
176176/// common: ProductOperatorRun,
177177/// }
178178///
179- /// let opts = Command::<Run>::parse_from(["foobar-operator", "run", "--name", "foo", "--product-config", "bar", "--watch-namespace", "foobar"]);
179+ /// let opts = Command::<Run>::parse_from([
180+ /// "foobar-operator",
181+ /// "run",
182+ /// "--name",
183+ /// "foo",
184+ /// "--product-config",
185+ /// "bar",
186+ /// "--watch-namespace",
187+ /// "foobar",
188+ /// "--operator-namespace",
189+ /// "stackable-operators",
190+ /// "--operator-service-name",
191+ /// "foo-operator",
192+ /// ]);
180193/// assert_eq!(opts, Command::Run(Run {
181194/// name: "foo".to_string(),
182195/// common: ProductOperatorRun {
183196/// product_config: ProductConfigPath::from("bar".as_ref()),
184197/// watch_namespace: WatchNamespace::One("foobar".to_string()),
185198/// telemetry_arguments: TelemetryOptions::default(),
186199/// cluster_info_opts: Default::default(),
200+ /// operator_environment: OperatorEnvironmentOpts {
201+ /// operator_namespace: "stackable-operators".to_string(),
202+ /// operator_service_name: "foo-operator".to_string(),
203+ /// },
187204/// },
188205/// }));
189206/// ```
@@ -216,6 +233,9 @@ pub struct ProductOperatorRun {
216233 #[ arg( long, env, default_value = "" ) ]
217234 pub watch_namespace : WatchNamespace ,
218235
236+ #[ command( flatten) ]
237+ pub operator_environment : OperatorEnvironmentOpts ,
238+
219239 #[ command( flatten) ]
220240 pub telemetry_arguments : TelemetryOptions ,
221241
@@ -278,6 +298,18 @@ impl ProductConfigPath {
278298 }
279299}
280300
301+ #[ derive( clap:: Parser , Debug , PartialEq , Eq ) ]
302+ pub struct OperatorEnvironmentOpts {
303+ /// The namespace the operator is running in, usually `stackable-operators`.
304+ #[ arg( long, env) ]
305+ pub operator_namespace : String ,
306+
307+ /// The name of the service the operator is reachable at, usually
308+ /// something like `<product>-operator`.
309+ #[ arg( long, env) ]
310+ pub operator_service_name : String ,
311+ }
312+
281313#[ cfg( test) ]
282314mod tests {
283315 use std:: { env, fs:: File } ;
@@ -292,6 +324,8 @@ mod tests {
292324 const DEPLOY_FILE_PATH : & str = "deploy_config_spec_properties.yaml" ;
293325 const DEFAULT_FILE_PATH : & str = "default_file_path_properties.yaml" ;
294326 const WATCH_NAMESPACE : & str = "WATCH_NAMESPACE" ;
327+ const OPERATOR_NAMESPACE : & str = "OPERATOR_NAMESPACE" ;
328+ const OPERATOR_SERVICE_NAME : & str = "OPERATOR_SERVICE_NAME" ;
295329
296330 #[ test]
297331 fn verify_cli ( ) {
@@ -388,6 +422,10 @@ mod tests {
388422 "bar" ,
389423 "--watch-namespace" ,
390424 "foo" ,
425+ "--operator-namespace" ,
426+ "stackable-operators" ,
427+ "--operator-service-name" ,
428+ "foo-operator" ,
391429 ] ) ;
392430 assert_eq ! (
393431 opts,
@@ -396,23 +434,42 @@ mod tests {
396434 watch_namespace: WatchNamespace :: One ( "foo" . to_string( ) ) ,
397435 cluster_info_opts: Default :: default ( ) ,
398436 telemetry_arguments: Default :: default ( ) ,
437+ operator_environment: OperatorEnvironmentOpts {
438+ operator_namespace: "stackable-operators" . to_string( ) ,
439+ operator_service_name: "foo-operator" . to_string( ) ,
440+ }
399441 }
400442 ) ;
401443
402444 // no cli / no env
403- let opts = ProductOperatorRun :: parse_from ( [ "run" , "--product-config" , "bar" ] ) ;
445+ let opts = ProductOperatorRun :: parse_from ( [
446+ "run" ,
447+ "--product-config" ,
448+ "bar" ,
449+ "--operator-namespace" ,
450+ "stackable-operators" ,
451+ "--operator-service-name" ,
452+ "foo-operator" ,
453+ ] ) ;
404454 assert_eq ! (
405455 opts,
406456 ProductOperatorRun {
407457 product_config: ProductConfigPath :: from( "bar" . as_ref( ) ) ,
408458 watch_namespace: WatchNamespace :: All ,
409459 cluster_info_opts: Default :: default ( ) ,
410460 telemetry_arguments: Default :: default ( ) ,
461+ operator_environment: OperatorEnvironmentOpts {
462+ operator_namespace: "stackable-operators" . to_string( ) ,
463+ operator_service_name: "foo-operator" . to_string( ) ,
464+ }
411465 }
412466 ) ;
413467
414468 // env with namespace
415469 unsafe { env:: set_var ( WATCH_NAMESPACE , "foo" ) } ;
470+ unsafe { env:: set_var ( OPERATOR_SERVICE_NAME , "foo-operator" ) } ;
471+ unsafe { env:: set_var ( OPERATOR_NAMESPACE , "stackable-operators" ) } ;
472+
416473 let opts = ProductOperatorRun :: parse_from ( [ "run" , "--product-config" , "bar" ] ) ;
417474 assert_eq ! (
418475 opts,
@@ -421,6 +478,10 @@ mod tests {
421478 watch_namespace: WatchNamespace :: One ( "foo" . to_string( ) ) ,
422479 cluster_info_opts: Default :: default ( ) ,
423480 telemetry_arguments: Default :: default ( ) ,
481+ operator_environment: OperatorEnvironmentOpts {
482+ operator_namespace: "stackable-operators" . to_string( ) ,
483+ operator_service_name: "foo-operator" . to_string( ) ,
484+ }
424485 }
425486 ) ;
426487 }
0 commit comments