@@ -163,7 +163,7 @@ pub enum Command<Run: Args = ProductOperatorRun> {
163
163
/// Can be embedded into an extended argument set:
164
164
///
165
165
/// ```rust
166
- /// # use stackable_operator::cli::{Command, ProductOperatorRun, ProductConfigPath};
166
+ /// # use stackable_operator::cli::{Command, OperatorEnvironmentOpts, ProductOperatorRun, ProductConfigPath};
167
167
/// use clap::Parser;
168
168
/// use stackable_operator::namespace::WatchNamespace;
169
169
/// use stackable_telemetry::tracing::TelemetryOptions;
@@ -176,14 +176,31 @@ pub enum Command<Run: Args = ProductOperatorRun> {
176
176
/// common: ProductOperatorRun,
177
177
/// }
178
178
///
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
+ /// ]);
180
193
/// assert_eq!(opts, Command::Run(Run {
181
194
/// name: "foo".to_string(),
182
195
/// common: ProductOperatorRun {
183
196
/// product_config: ProductConfigPath::from("bar".as_ref()),
184
197
/// watch_namespace: WatchNamespace::One("foobar".to_string()),
185
198
/// telemetry_arguments: TelemetryOptions::default(),
186
199
/// 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
+ /// },
187
204
/// },
188
205
/// }));
189
206
/// ```
@@ -216,6 +233,9 @@ pub struct ProductOperatorRun {
216
233
#[ arg( long, env, default_value = "" ) ]
217
234
pub watch_namespace : WatchNamespace ,
218
235
236
+ #[ command( flatten) ]
237
+ pub operator_environment : OperatorEnvironmentOpts ,
238
+
219
239
#[ command( flatten) ]
220
240
pub telemetry_arguments : TelemetryOptions ,
221
241
@@ -278,6 +298,18 @@ impl ProductConfigPath {
278
298
}
279
299
}
280
300
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
+
281
313
#[ cfg( test) ]
282
314
mod tests {
283
315
use std:: { env, fs:: File } ;
@@ -292,6 +324,8 @@ mod tests {
292
324
const DEPLOY_FILE_PATH : & str = "deploy_config_spec_properties.yaml" ;
293
325
const DEFAULT_FILE_PATH : & str = "default_file_path_properties.yaml" ;
294
326
const WATCH_NAMESPACE : & str = "WATCH_NAMESPACE" ;
327
+ const OPERATOR_NAMESPACE : & str = "OPERATOR_NAMESPACE" ;
328
+ const OPERATOR_SERVICE_NAME : & str = "OPERATOR_SERVICE_NAME" ;
295
329
296
330
#[ test]
297
331
fn verify_cli ( ) {
@@ -388,6 +422,10 @@ mod tests {
388
422
"bar" ,
389
423
"--watch-namespace" ,
390
424
"foo" ,
425
+ "--operator-namespace" ,
426
+ "stackable-operators" ,
427
+ "--operator-service-name" ,
428
+ "foo-operator" ,
391
429
] ) ;
392
430
assert_eq ! (
393
431
opts,
@@ -396,23 +434,42 @@ mod tests {
396
434
watch_namespace: WatchNamespace :: One ( "foo" . to_string( ) ) ,
397
435
cluster_info_opts: Default :: default ( ) ,
398
436
telemetry_arguments: Default :: default ( ) ,
437
+ operator_environment: OperatorEnvironmentOpts {
438
+ operator_namespace: "stackable-operators" . to_string( ) ,
439
+ operator_service_name: "foo-operator" . to_string( ) ,
440
+ }
399
441
}
400
442
) ;
401
443
402
444
// 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
+ ] ) ;
404
454
assert_eq ! (
405
455
opts,
406
456
ProductOperatorRun {
407
457
product_config: ProductConfigPath :: from( "bar" . as_ref( ) ) ,
408
458
watch_namespace: WatchNamespace :: All ,
409
459
cluster_info_opts: Default :: default ( ) ,
410
460
telemetry_arguments: Default :: default ( ) ,
461
+ operator_environment: OperatorEnvironmentOpts {
462
+ operator_namespace: "stackable-operators" . to_string( ) ,
463
+ operator_service_name: "foo-operator" . to_string( ) ,
464
+ }
411
465
}
412
466
) ;
413
467
414
468
// env with namespace
415
469
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
+
416
473
let opts = ProductOperatorRun :: parse_from ( [ "run" , "--product-config" , "bar" ] ) ;
417
474
assert_eq ! (
418
475
opts,
@@ -421,6 +478,10 @@ mod tests {
421
478
watch_namespace: WatchNamespace :: One ( "foo" . to_string( ) ) ,
422
479
cluster_info_opts: Default :: default ( ) ,
423
480
telemetry_arguments: Default :: default ( ) ,
481
+ operator_environment: OperatorEnvironmentOpts {
482
+ operator_namespace: "stackable-operators" . to_string( ) ,
483
+ operator_service_name: "foo-operator" . to_string( ) ,
484
+ }
424
485
}
425
486
) ;
426
487
}
0 commit comments