@@ -116,7 +116,7 @@ use product_config::ProductConfigManager;
116116use snafu:: { ResultExt , Snafu } ;
117117use stackable_telemetry:: tracing:: TelemetryOptions ;
118118
119- use crate :: { namespace:: WatchNamespace , utils:: cluster_info:: KubernetesClusterInfoOpts } ;
119+ use crate :: { namespace:: WatchNamespace , utils:: cluster_info:: KubernetesClusterInfoOptions } ;
120120
121121pub const AUTHOR : & str =
"Stackable GmbH - [email protected] " ; 122122
@@ -163,10 +163,10 @@ 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, OperatorEnvironmentOptions, ProductOperatorRun, ProductConfigPath};
167+ /// # use stackable_operator::{namespace::WatchNamespace, utils::cluster_info::KubernetesClusterInfoOptions};
168+ /// # use stackable_telemetry::tracing::TelemetryOptions;
167169/// use clap::Parser;
168- /// use stackable_operator::{namespace::WatchNamespace, utils::cluster_info::KubernetesClusterInfoOpts};
169- /// use stackable_telemetry::tracing::TelemetryOptions;
170170///
171171/// #[derive(clap::Parser, Debug, PartialEq, Eq)]
172172/// struct Run {
@@ -176,17 +176,36 @@ 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", "--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+ /// ]);
180195/// assert_eq!(opts, Command::Run(Run {
181196/// name: "foo".to_string(),
182197/// common: ProductOperatorRun {
183198/// product_config: ProductConfigPath::from("bar".as_ref()),
184199/// 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 {
187202/// kubernetes_cluster_domain: None,
188203/// kubernetes_node_name: "baz".to_string(),
189204/// },
205+ /// operator_environment: OperatorEnvironmentOptions {
206+ /// operator_namespace: "stackable-operators".to_string(),
207+ /// operator_service_name: "foo-operator".to_string(),
208+ /// },
190209/// },
191210/// }));
192211/// ```
@@ -220,10 +239,13 @@ pub struct ProductOperatorRun {
220239 pub watch_namespace : WatchNamespace ,
221240
222241 #[ command( flatten) ]
223- pub telemetry_arguments : TelemetryOptions ,
242+ pub operator_environment : OperatorEnvironmentOptions ,
243+
244+ #[ command( flatten) ]
245+ pub telemetry : TelemetryOptions ,
224246
225247 #[ command( flatten) ]
226- pub cluster_info_opts : KubernetesClusterInfoOpts ,
248+ pub cluster_info : KubernetesClusterInfoOptions ,
227249}
228250
229251/// A path to a [`ProductConfigManager`] spec file
@@ -281,11 +303,26 @@ impl ProductConfigPath {
281303 }
282304}
283305
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+
284322#[ cfg( test) ]
285323mod tests {
286- use std:: { env , fs:: File } ;
324+ use std:: fs:: File ;
287325
288- use clap:: Parser ;
289326 use rstest:: * ;
290327 use tempfile:: tempdir;
291328
@@ -294,7 +331,6 @@ mod tests {
294331 const USER_PROVIDED_PATH : & str = "user_provided_path_properties.yaml" ;
295332 const DEPLOY_FILE_PATH : & str = "deploy_config_spec_properties.yaml" ;
296333 const DEFAULT_FILE_PATH : & str = "default_file_path_properties.yaml" ;
297- const WATCH_NAMESPACE : & str = "WATCH_NAMESPACE" ;
298334
299335 #[ test]
300336 fn verify_cli ( ) {
@@ -378,76 +414,4 @@ mod tests {
378414 panic ! ( "must return RequiredFileMissing when file was not found" )
379415 }
380416 }
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- }
453417}
0 commit comments