@@ -116,7 +116,7 @@ use product_config::ProductConfigManager;
116
116
use snafu:: { ResultExt , Snafu } ;
117
117
use stackable_telemetry:: tracing:: TelemetryOptions ;
118
118
119
- use crate :: { namespace:: WatchNamespace , utils:: cluster_info:: KubernetesClusterInfoOpts } ;
119
+ use crate :: { namespace:: WatchNamespace , utils:: cluster_info:: KubernetesClusterInfoOptions } ;
120
120
121
121
pub const AUTHOR : & str =
"Stackable GmbH - [email protected] " ;
122
122
@@ -163,10 +163,10 @@ 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, OperatorEnvironmentOptions, ProductOperatorRun, ProductConfigPath};
167
+ /// # use stackable_operator::{namespace::WatchNamespace, utils::cluster_info::KubernetesClusterInfoOptions};
168
+ /// # use stackable_telemetry::tracing::TelemetryOptions;
167
169
/// use clap::Parser;
168
- /// use stackable_operator::{namespace::WatchNamespace, utils::cluster_info::KubernetesClusterInfoOpts};
169
- /// use stackable_telemetry::tracing::TelemetryOptions;
170
170
///
171
171
/// #[derive(clap::Parser, Debug, PartialEq, Eq)]
172
172
/// struct Run {
@@ -176,17 +176,36 @@ 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", "--kubernetes-node-name", "baz"]);
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
+ /// "--kubernetes-node-name",
193
+ /// "baz",
194
+ /// ]);
180
195
/// assert_eq!(opts, Command::Run(Run {
181
196
/// name: "foo".to_string(),
182
197
/// common: ProductOperatorRun {
183
198
/// product_config: ProductConfigPath::from("bar".as_ref()),
184
199
/// watch_namespace: WatchNamespace::One("foobar".to_string()),
185
- /// telemetry_arguments : TelemetryOptions::default(),
186
- /// cluster_info_opts: KubernetesClusterInfoOpts {
200
+ /// telemetry : TelemetryOptions::default(),
201
+ /// cluster_info: KubernetesClusterInfoOptions {
187
202
/// kubernetes_cluster_domain: None,
188
203
/// kubernetes_node_name: "baz".to_string(),
189
204
/// },
205
+ /// operator_environment: OperatorEnvironmentOptions {
206
+ /// operator_namespace: "stackable-operators".to_string(),
207
+ /// operator_service_name: "foo-operator".to_string(),
208
+ /// },
190
209
/// },
191
210
/// }));
192
211
/// ```
@@ -220,10 +239,13 @@ pub struct ProductOperatorRun {
220
239
pub watch_namespace : WatchNamespace ,
221
240
222
241
#[ command( flatten) ]
223
- pub telemetry_arguments : TelemetryOptions ,
242
+ pub operator_environment : OperatorEnvironmentOptions ,
243
+
244
+ #[ command( flatten) ]
245
+ pub telemetry : TelemetryOptions ,
224
246
225
247
#[ command( flatten) ]
226
- pub cluster_info_opts : KubernetesClusterInfoOpts ,
248
+ pub cluster_info : KubernetesClusterInfoOptions ,
227
249
}
228
250
229
251
/// A path to a [`ProductConfigManager`] spec file
@@ -281,11 +303,26 @@ impl ProductConfigPath {
281
303
}
282
304
}
283
305
306
+ #[ derive( clap:: Parser , Debug , PartialEq , Eq ) ]
307
+ pub struct OperatorEnvironmentOptions {
308
+ /// The namespace the operator is running in, usually `stackable-operators`.
309
+ ///
310
+ /// Note that when running the operator on Kubernetes we recommend to use the
311
+ /// [downward API](https://kubernetes.io/docs/concepts/workloads/pods/downward-api/)
312
+ /// to let Kubernetes project the namespace as the `OPERATOR_NAMESPACE` env variable.
313
+ #[ arg( long, env) ]
314
+ pub operator_namespace : String ,
315
+
316
+ /// The name of the service the operator is reachable at, usually
317
+ /// something like `<product>-operator`.
318
+ #[ arg( long, env) ]
319
+ pub operator_service_name : String ,
320
+ }
321
+
284
322
#[ cfg( test) ]
285
323
mod tests {
286
- use std:: { env , fs:: File } ;
324
+ use std:: fs:: File ;
287
325
288
- use clap:: Parser ;
289
326
use rstest:: * ;
290
327
use tempfile:: tempdir;
291
328
@@ -294,7 +331,6 @@ mod tests {
294
331
const USER_PROVIDED_PATH : & str = "user_provided_path_properties.yaml" ;
295
332
const DEPLOY_FILE_PATH : & str = "deploy_config_spec_properties.yaml" ;
296
333
const DEFAULT_FILE_PATH : & str = "default_file_path_properties.yaml" ;
297
- const WATCH_NAMESPACE : & str = "WATCH_NAMESPACE" ;
298
334
299
335
#[ test]
300
336
fn verify_cli ( ) {
@@ -378,76 +414,4 @@ mod tests {
378
414
panic ! ( "must return RequiredFileMissing when file was not found" )
379
415
}
380
416
}
381
-
382
- #[ test]
383
- fn product_operator_run_watch_namespace ( ) {
384
- // clean env var to not interfere if already set
385
- unsafe { env:: remove_var ( WATCH_NAMESPACE ) } ;
386
-
387
- // cli with namespace
388
- let opts = ProductOperatorRun :: parse_from ( [
389
- "run" ,
390
- "--product-config" ,
391
- "bar" ,
392
- "--watch-namespace" ,
393
- "foo" ,
394
- "--kubernetes-node-name" ,
395
- "baz" ,
396
- ] ) ;
397
- assert_eq ! (
398
- opts,
399
- ProductOperatorRun {
400
- product_config: ProductConfigPath :: from( "bar" . as_ref( ) ) ,
401
- watch_namespace: WatchNamespace :: One ( "foo" . to_string( ) ) ,
402
- cluster_info_opts: KubernetesClusterInfoOpts {
403
- kubernetes_cluster_domain: None ,
404
- kubernetes_node_name: "baz" . to_string( )
405
- } ,
406
- telemetry_arguments: Default :: default ( ) ,
407
- }
408
- ) ;
409
-
410
- // no cli / no env
411
- let opts = ProductOperatorRun :: parse_from ( [
412
- "run" ,
413
- "--product-config" ,
414
- "bar" ,
415
- "--kubernetes-node-name" ,
416
- "baz" ,
417
- ] ) ;
418
- assert_eq ! (
419
- opts,
420
- ProductOperatorRun {
421
- product_config: ProductConfigPath :: from( "bar" . as_ref( ) ) ,
422
- watch_namespace: WatchNamespace :: All ,
423
- cluster_info_opts: KubernetesClusterInfoOpts {
424
- kubernetes_cluster_domain: None ,
425
- kubernetes_node_name: "baz" . to_string( )
426
- } ,
427
- telemetry_arguments: Default :: default ( ) ,
428
- }
429
- ) ;
430
-
431
- // env with namespace
432
- unsafe { env:: set_var ( WATCH_NAMESPACE , "foo" ) } ;
433
- let opts = ProductOperatorRun :: parse_from ( [
434
- "run" ,
435
- "--product-config" ,
436
- "bar" ,
437
- "--kubernetes-node-name" ,
438
- "baz" ,
439
- ] ) ;
440
- assert_eq ! (
441
- opts,
442
- ProductOperatorRun {
443
- product_config: ProductConfigPath :: from( "bar" . as_ref( ) ) ,
444
- watch_namespace: WatchNamespace :: One ( "foo" . to_string( ) ) ,
445
- cluster_info_opts: KubernetesClusterInfoOpts {
446
- kubernetes_cluster_domain: None ,
447
- kubernetes_node_name: "baz" . to_string( )
448
- } ,
449
- telemetry_arguments: Default :: default ( ) ,
450
- }
451
- ) ;
452
- }
453
417
}
0 commit comments