Skip to content

Commit

Permalink
feat: Add re-export for ConversionReview type in stackable-webhook (#…
Browse files Browse the repository at this point in the history
…749)

* feat: Add re-export for ConversionReview type

* Update changelog

* Fix wrong link reference in changelog

* Add code and doc comments about the re-exported type

* Clarify why we re-export the ConversionReview type
  • Loading branch information
Techassi authored Mar 13, 2024
1 parent d86a42d commit 8092fd4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ All notable changes to this project will be documented in this file.
## Added

- Add `stackable_webhook` crate which provides utilities to create webhooks with TLS termination ([#730]).
- Add `ConversionReview` re-export in `stackable_webhook` crate ([#749]).

[#730]: https://github.com/stackabletech/operator-rs/pull/730
[#749]: https://github.com/stackabletech/operator-rs/pull/749

## Changed

Expand Down
2 changes: 1 addition & 1 deletion stackable-webhook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub mod servers;
pub mod tls;

// Selected re-exports
pub use crate::{options::Options, servers::ConversionWebhookServer};
pub use crate::options::Options;

/// A result type alias with the library-level [`Error`] type as teh default
/// error type.
Expand Down
25 changes: 18 additions & 7 deletions stackable-webhook/src/servers/conversion.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use std::fmt::Debug;

use axum::{extract::State, routing::post, Json, Router};
use kube::core::conversion::ConversionReview;
use tracing::{debug, instrument};

// Re-export this type because users of the conversion webhook server require
// this type to write the handler function. Instead of importing this type from
// kube directly, consumers can use this type instead. This also eliminates
// keeping the kube dependency version in sync between here and the operator.
pub use kube::core::conversion::ConversionReview;

use crate::{options::Options, StatefulWebhookHandler, WebhookHandler, WebhookServer};

impl<F> WebhookHandler<ConversionReview, ConversionReview> for F
Expand Down Expand Up @@ -39,13 +44,16 @@ impl ConversionWebhookServer {
///
/// Each request is handled by the provided `handler` function. Any function
/// with the signature `(ConversionReview) -> ConversionReview` can be
/// provided.
/// provided. The [`ConversionReview`] type can be imported via a re-export at
/// [`stackable_webhook::server::ConversionReview`].
///
/// # Example
///
/// ```
/// use stackable_webhook::{servers::ConversionWebhookServer, Options};
/// use kube::core::conversion::ConversionReview;
/// use stackable_webhook::{
/// servers::{ConversionReview, ConversionWebhookServer},
/// Options
/// };
///
/// // Construct the conversion webhook server
/// let server = ConversionWebhookServer::new(handler, Options::default());
Expand Down Expand Up @@ -77,7 +85,8 @@ impl ConversionWebhookServer {
///
/// Each request is handled by the provided `handler` function. Any function
/// with the signature `(ConversionReview, S) -> ConversionReview` can be
/// provided.
/// provided. The [`ConversionReview`] type can be imported via a re-export at
/// [`stackable_webhook::server::ConversionReview`].
///
/// It is recommended to wrap the state in an [`Arc`][std::sync::Arc] if it
/// needs to be mutable, see
Expand All @@ -88,8 +97,10 @@ impl ConversionWebhookServer {
/// ```
/// use std::sync::Arc;
///
/// use stackable_webhook::{servers::ConversionWebhookServer, Options};
/// use kube::core::conversion::ConversionReview;
/// use stackable_webhook::{
/// servers::{ConversionReview, ConversionWebhookServer},
/// Options
/// };
///
/// #[derive(Debug, Clone)]
/// struct State {}
Expand Down

0 comments on commit 8092fd4

Please sign in to comment.