Skip to content

Conversation

@sbernauer
Copy link
Member

@sbernauer sbernauer commented Nov 18, 2025

Description

Part of stackabletech/commons-operator#111
Used by stackabletech/commons-operator#387

BREAKING: Refactor the entire WebhookServer mechanism, so multiple webhooks can run in parallel.
Put individual webhooks (currently ConversionWebhook and MutatingWebhook) behind the Webhook trait.

Definition of Done Checklist

  • Not all of these items are applicable to all PRs, the author should update this template to only leave the boxes in that are relevant
  • Please make sure all these things are done and tick the boxes

Author

  • Changes are OpenShift compatible
  • CRD changes approved
  • CRD documentation for all fields, following the style guide.
  • Integration tests passed (for non trivial changes)
  • Changes need to be "offline" compatible

Reviewer

  • Code contains useful comments
  • Code contains useful logging statements
  • (Integration-)Test cases added
  • Documentation added or updated. Follows the style guide.
  • Changelog updated
  • Cargo.toml only contains references to git tags (not specific commits or branches)

Acceptance

  • Feature Tracker has been updated
  • Proper release label has been added

Copy link
Member

@NickLarsenNZ NickLarsenNZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments.

Also a few things for me to check into which shouldn't block you.

@sbernauer sbernauer marked this pull request as ready for review November 20, 2025 11:53
Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
sbernauer and others added 2 commits November 20, 2025 13:39
Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
NickLarsenNZ
NickLarsenNZ previously approved these changes Nov 20, 2025
Copy link
Member

@NickLarsenNZ NickLarsenNZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sbernauer sbernauer moved this to Development: In Review in Stackable Engineering Nov 21, 2025
@sbernauer sbernauer self-assigned this Nov 21, 2025
Copy link
Member

@Techassi Techassi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking for now, because there are a whole bunch of notes I have on this. These are best discussed verbally instead of writing back and forth.

/// ```
pub struct WebhookServer {
options: WebhookServerOptions,
webhooks: Vec<Box<dyn Webhook>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: In my opinion, this crate is only aimed at implementing Kubernetes webhooks, not any generic webhook. Kubernetes has a well-known set of supported webhooks: the conversion and admission webhooks. As such, we should use an enum in combination with enum_dispatch.

Comment on lines +83 to +84
#[derive(Clone, Debug)]
pub struct WebhookServerOptions {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This had a whole bunch of documentation. Why is this removed? I spent a significant amount of time writing up proper documentation for all the public items in this crate.

note: This had a builder. Why did it get removed?

Comment on lines 109 to 111
/// Creates a new webhook server with the given config and list of [`Webhook`]s.
///
/// The server listens on `socket_addr` which is provided via the [`WebhookOptions`] and handles
/// routing based on the provided Axum `router`. Most of the time it is sufficient to use
/// [`WebhookOptions::default()`]. See the documentation for [`WebhookOptions`] for more details
/// on the default values.
///
/// To start the server, use the [`WebhookServer::run()`] function. This will
/// run the server using the Tokio runtime until it is terminated.
///
/// ### Basic Example
///
/// ```
/// use stackable_webhook::{WebhookServer, WebhookOptions};
/// use axum::Router;
///
/// # async fn test() {
/// let router = Router::new();
/// let (server, cert_rx) = WebhookServer::new(router, WebhookOptions::default())
/// .await
/// .expect("failed to create WebhookServer");
/// # }
/// ```
///
/// ### Example with Custom Options
///
/// ```
/// use stackable_webhook::{WebhookServer, WebhookOptions};
/// use axum::Router;
///
/// # async fn test() {
/// let options = WebhookOptions::builder()
/// .bind_address([127, 0, 0, 1], 8080)
/// .add_subject_alterative_dns_name("my-san-entry")
/// .build();
///
/// let router = Router::new();
/// let (server, cert_rx) = WebhookServer::new(router, options)
/// .await
/// .expect("failed to create WebhookServer");
/// # }
/// ```
/// Please read their documentation for details.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Again, this had so much more documentation before, which is still valid after the change. Also, it should still provide a (basic) example on how to use it, and not just refer to the downstream impl.

Comment on lines +132 to +134
for webhook in &webhooks {
router = webhook.register_routes(router);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: We can add a debug statement here to log the registration of routes we add the the core webhook server.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you thinking of

tracing::debug!("Registering webhook routes");

or something more advanced? I can't really think of what else to log here 🙈

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we don't have access to which route we are adding at this point, but we can maybe add such a log statement where we do know the routes.

///
/// ### Example usage
///
/// TODO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Well... We should add that...

handler_state: Arc<S>,
_resource: PhantomData<R>,

disable_validating_webhook_configuration_maintenance: bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This is a mouthful with a bunch of superfluous information: The fact that we are talking about validation webhooks is already indicated by the struct name itself and the maintenance is dealing with the validating webhook config.

Suggested change
disable_validating_webhook_configuration_maintenance: bool,
disable_maintenance: bool,

handler_state: Arc<S>,
_resource: PhantomData<R>,

disable_mutating_webhook_configuration_maintenance: bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Same as in the validating webhook.

Comment on lines 38 to 44
validating_webhook_configuration: ValidatingWebhookConfiguration,
handler: H,
handler_state: Arc<S>,
_resource: PhantomData<R>,

disable_validating_webhook_configuration_maintenance: bool,
client: Client,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Add documentation to the fields.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some field level docs in 1c4e2ad

Comment on lines +58 to +63
validating_webhook_configuration: ValidatingWebhookConfiguration,
handler: H,
handler_state: Arc<S>,
disable_validating_webhook_configuration_maintenance: bool,
client: Client,
field_manager: String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: We should reduce the number of parameters here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Development: In Review

Development

Successfully merging this pull request may close these issues.

4 participants