Skip to content

Commit 9089385

Browse files
committed
Move subject_alterative_dns_names into Options
1 parent a8a2381 commit 9089385

File tree

6 files changed

+44
-18
lines changed

6 files changed

+44
-18
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-webhook/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ tower.workspace = true
2929
tracing.workspace = true
3030
tracing-opentelemetry.workspace = true
3131
x509-cert.workspace = true
32+
33+
[dev-dependencies]
34+
clap.workspace = true

crates/stackable-webhook/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! use tokio::sync::mpsc;
1414
//!
1515
//! let router = Router::new();
16-
//! let server = WebhookServer::new(router, Options::default(), vec![]);
16+
//! let server = WebhookServer::new(router, Options::default());
1717
//! ```
1818
//!
1919
//! For some usages, complete end-to-end [`WebhookServer`] implementations
@@ -101,7 +101,7 @@ impl WebhookServer {
101101
/// use tokio::sync::mpsc;
102102
///
103103
/// let router = Router::new();
104-
/// let server = WebhookServer::new(router, Options::default(), vec![]);
104+
/// let server = WebhookServer::new(router, Options::default());
105105
/// ```
106106
///
107107
/// ### Example with Custom Options
@@ -113,16 +113,15 @@ impl WebhookServer {
113113
///
114114
/// let options = Options::builder()
115115
/// .bind_address([127, 0, 0, 1], 8080)
116+
/// .add_subject_alterative_dns_name("my-san-entry")
116117
/// .build();
117-
/// let sans = vec!["my-san-entry".to_string()];
118118
///
119119
/// let router = Router::new();
120-
/// let server = WebhookServer::new(router, options, sans);
120+
/// let server = WebhookServer::new(router, options);
121121
/// ```
122122
pub async fn new(
123123
router: Router,
124124
options: Options,
125-
subject_alterative_dns_names: Vec<String>,
126125
) -> Result<(Self, mpsc::Receiver<Certificate>)> {
127126
tracing::trace!("create new webhook server");
128127

@@ -147,7 +146,7 @@ impl WebhookServer {
147146

148147
tracing::debug!("create TLS server");
149148
let (tls_server, cert_rx) =
150-
TlsServer::new(options.socket_addr, router, subject_alterative_dns_names)
149+
TlsServer::new(options.socket_addr, router, options.subject_alterative_dns_names)
151150
.await
152151
.context(CreateTlsServerSnafu)?;
153152

crates/stackable-webhook/src/options.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub struct Options {
4141
/// The default HTTPS socket address the [`TcpListener`][tokio::net::TcpListener]
4242
/// binds to.
4343
pub socket_addr: SocketAddr,
44+
45+
/// The subject alterative DNS names that should be added to the certificates generated for this
46+
/// webhook.
47+
pub subject_alterative_dns_names: Vec<String>,
4448
}
4549

4650
impl Default for Options {
@@ -66,6 +70,7 @@ impl Options {
6670
#[derive(Debug, Default)]
6771
pub struct OptionsBuilder {
6872
socket_addr: Option<SocketAddr>,
73+
subject_alterative_dns_names: Vec<String>,
6974
}
7075

7176
impl OptionsBuilder {
@@ -91,11 +96,32 @@ impl OptionsBuilder {
9196
self
9297
}
9398

99+
/// Sets the subject alterative DNS names that should be added to the certificates generated for
100+
/// this webhook.
101+
pub fn subject_alterative_dns_names(
102+
mut self,
103+
subject_alterative_dns_name: Vec<String>,
104+
) -> Self {
105+
self.subject_alterative_dns_names = subject_alterative_dns_name;
106+
self
107+
}
108+
109+
/// Adds the (subject alterative DNS name to the list of names.
110+
pub fn add_subject_alterative_dns_name(
111+
mut self,
112+
subject_alterative_dns_name: impl Into<String>,
113+
) -> Self {
114+
self.subject_alterative_dns_names
115+
.push(subject_alterative_dns_name.into());
116+
self
117+
}
118+
94119
/// Builds the final [`Options`] by using default values for any not
95120
/// explicitly set option.
96121
pub fn build(self) -> Options {
97122
Options {
98123
socket_addr: self.socket_addr.unwrap_or(DEFAULT_SOCKET_ADDRESS),
124+
subject_alterative_dns_names: self.subject_alterative_dns_names,
99125
}
100126
}
101127
}

crates/stackable-webhook/src/servers/conversion.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ impl ConversionWebhookServer {
9595
/// # Example
9696
///
9797
/// ```no_run
98+
/// use clap::Parser;
9899
/// use stackable_webhook::{
99100
/// servers::{ConversionReview, ConversionWebhookServer},
100101
/// Options
101102
/// };
102-
/// use stackable_operator::cli::OperatorEnvironmentOpts;
103+
/// use stackable_operator::cli::OperatorEnvironmentOptions;
103104
/// use stackable_operator::kube::Client;
104105
/// use stackable_operator::crd::s3::{S3Connection, S3ConnectionVersion};
105106
///
@@ -114,12 +115,7 @@ impl ConversionWebhookServer {
114115
///
115116
/// const OPERATOR_NAME: &str = "PRODUCT_OPERATOR";
116117
/// let client = Client::try_default().await.expect("failed to create Kubernetes client");
117-
/// // Normally you would get this from the CLI arguments in
118-
/// // `ProductOperatorRun::operator_environment`
119-
/// let operator_environment = OperatorEnvironmentOpts {
120-
/// operator_namespace: "stackable-operator".to_string(),
121-
/// operator_service_name: "product-operator".to_string(),
122-
/// };
118+
/// let operator_environment = OperatorEnvironmentOptions::parse();
123119
///
124120
/// // Construct the conversion webhook server
125121
/// let conversion_webhook = ConversionWebhookServer::new(
@@ -141,7 +137,7 @@ impl ConversionWebhookServer {
141137
)]
142138
pub async fn new<H>(
143139
crds_and_handlers: impl IntoIterator<Item = (CustomResourceDefinition, H)>,
144-
options: Options,
140+
mut options: Options,
145141
client: Client,
146142
field_manager: impl Into<String> + Debug,
147143
operator_environment: OperatorEnvironmentOptions,
@@ -167,13 +163,14 @@ impl ConversionWebhookServer {
167163

168164
// This is how Kubernetes calls us, so it decides about the naming.
169165
// AFAIK we can not influence this, so this is the only SAN entry needed.
170-
let sans = vec![format!(
166+
let subject_alterative_dns_name = format!(
171167
"{service_name}.{operator_namespace}.svc",
172168
service_name = operator_environment.operator_service_name,
173169
operator_namespace = operator_environment.operator_namespace,
174-
)];
170+
);
171+
options.subject_alterative_dns_names.push(subject_alterative_dns_name);
175172

176-
let (server, mut cert_rx) = WebhookServer::new(router, options, sans)
173+
let (server, mut cert_rx) = WebhookServer::new(router, options)
177174
.await
178175
.context(CreateWebhookServerSnafu)?;
179176

crates/stackable-webhook/src/tls/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub struct TlsServer {
6565

6666
impl TlsServer {
6767
#[instrument(name = "create_tls_server", skip(router))]
68-
pub async fn new<'a>(
68+
pub async fn new(
6969
socket_addr: SocketAddr,
7070
router: Router,
7171
subject_alterative_dns_names: Vec<String>,

0 commit comments

Comments
 (0)