Skip to content

Commit 0ef29ab

Browse files
committed
WIP
1 parent 7b39422 commit 0ef29ab

File tree

10 files changed

+407
-236
lines changed

10 files changed

+407
-236
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/stackable-certs/src/ca/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use stackable_operator::time::Duration;
22

3-
/// The default CA validity time span of one hour (3600 seconds).
3+
/// The default CA validity time span
44
pub const DEFAULT_CA_VALIDITY: Duration = Duration::from_hours_unchecked(1);
55

66
/// The root CA subject name containing only the common name.

crates/stackable-certs/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use std::ops::Deref;
2323

2424
use snafu::Snafu;
25+
use stackable_operator::time::Duration;
2526
use x509_cert::{Certificate, spki::EncodePublicKey};
2627
#[cfg(feature = "rustls")]
2728
use {
@@ -36,6 +37,9 @@ use crate::keys::CertificateKeypair;
3637
pub mod ca;
3738
pub mod keys;
3839

40+
/// The default certificate validity time span
41+
pub const DEFAULT_CERTIFICATE_VALIDITY: Duration = Duration::from_hours_unchecked(1);
42+
3943
/// Error variants which can be encountered when creating a new
4044
/// [`CertificatePair`].
4145
#[derive(Debug, Snafu)]

crates/stackable-operator/src/cli.rs

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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)]
282314
mod 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
}

crates/stackable-telemetry/src/instrumentation/axum/mod.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,6 @@ const OTEL_TRACE_ID_TO: &str = "opentelemetry.trace_id.to";
7373
/// # let _: Router = router;
7474
/// ```
7575
///
76-
/// ### Example with Webhook
77-
///
78-
/// The usage is even simpler when combined with the `stackable_webhook` crate.
79-
/// The webhook server has built-in support to automatically emit HTTP spans on
80-
/// every incoming request.
81-
///
82-
/// ```
83-
/// use stackable_webhook::{WebhookServer, Options};
84-
/// use axum::Router;
85-
///
86-
/// let router = Router::new();
87-
/// let server = WebhookServer::new(router, Options::default());
88-
///
89-
/// # let _: WebhookServer = server;
90-
/// ```
91-
///
9276
/// This layer is implemented based on [this][1] official Tower guide.
9377
///
9478
/// [1]: https://github.com/tower-rs/tower/blob/master/guides/building-a-middleware-from-scratch.md

crates/stackable-webhook/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ tower-http.workspace = true
2626
tower.workspace = true
2727
tracing.workspace = true
2828
tracing-opentelemetry.workspace = true
29+
x509-cert.workspace = true

0 commit comments

Comments
 (0)