Skip to content

Commit 0508e1b

Browse files
committed
docs(webhook): Add example for ConversionWebhookServer::with_maintainer
1 parent 352129e commit 0508e1b

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,76 @@ impl ConversionWebhookServer {
189189
/// Creates and returns a tuple consisting of a [`ConversionWebhookServer`], a [`CustomResourceDefinitionMaintainer`],
190190
/// and a [`oneshot::Receiver`].
191191
///
192+
/// ## Parameters
193+
///
194+
/// - `crds_and_handlers`: An iterator over a 2-tuple (pair) mapping a [`CustomResourceDefinition`]
195+
/// to a handler function. In most cases, the generated `CustomResource::try_merge` function
196+
/// should be used. It provides the expected `fn(ConversionReview) -> ConversionReview`
197+
/// signature.
198+
/// - `operator_name`: The name of the operator. This is used to construct the webhook service
199+
/// name.
200+
/// - `operator_namespace`: The namespace the operator runs in. This is used to construct the
201+
/// webhook service name.
202+
/// - `disable_maintainer`: A boolean value to indicate if the [`CustomResourceDefinitionMaintainer`]
203+
/// should be disabled.
204+
/// - `client`: A [`kube::Client`] used to maintain the custom resource definitions.
205+
///
192206
/// See the referenced items for more details on usage.
207+
///
208+
/// ## Return Values
209+
///
210+
/// - The [`ConversionWebhookServer`] itself. This is used to run the server. See
211+
/// [`ConversionWebhookServer::run`] for more details.
212+
/// - The [`CustomResourceDefinitionMaintainer`] which is used to run the maintainer. See
213+
/// [`CustomResourceDefinitionMaintainer::run`] for more details.
214+
/// - A [`oneshot::Receiver`] which is triggered after the initial reconciliation of the CRDs
215+
/// succeeded. This signal can be used to deploy any custom resources defined by these CRDs.
216+
///
217+
/// ## Example
218+
///
219+
/// ```no_run
220+
/// # use futures_util::TryFutureExt;
221+
/// # use tokio_rustls::rustls::crypto::{CryptoProvider, ring::default_provider};
222+
/// use stackable_webhook::servers::{ConversionWebhookServer, ConversionWebhookOptions};
223+
/// use stackable_operator::{kube::Client, crd::s3::{S3Connection, S3ConnectionVersion}};
224+
///
225+
/// # #[tokio::main]
226+
/// # async fn main() {
227+
/// # CryptoProvider::install_default(default_provider()).unwrap();
228+
/// let client = Client::try_default().await.unwrap();
229+
///
230+
/// let crds_and_handlers = vec![
231+
/// (
232+
/// S3Connection::merged_crd(S3ConnectionVersion::V1Alpha1)
233+
/// .expect("the S3Connection CRD must be merged"),
234+
/// S3Connection::try_convert,
235+
/// )
236+
/// ];
237+
///
238+
/// let (conversion_webhook_server, crd_maintainer, _initial_reconcile_rx) =
239+
/// ConversionWebhookServer::with_maintainer(
240+
/// crds_and_handlers,
241+
/// "my-operator",
242+
/// "my-namespace",
243+
/// false,
244+
/// client,
245+
/// )
246+
/// .await
247+
/// .unwrap();
248+
///
249+
/// let conversion_webhook_server = conversion_webhook_server
250+
/// .run()
251+
/// .map_err(|err| err.to_string());
252+
///
253+
/// let crd_maintainer = crd_maintainer
254+
/// .run()
255+
/// .map_err(|err| err.to_string());
256+
///
257+
/// // Run both the conversion webhook server and crd_maintainer concurrently, eg. with
258+
/// // futures::try_join!.
259+
/// futures_util::try_join!(conversion_webhook_server, crd_maintainer).unwrap();
260+
/// # }
261+
/// ```
193262
pub async fn with_maintainer<'a, H>(
194263
// TODO (@Techassi): Use a trait type here which can be used to build all part of the
195264
// conversion webhook server and a CRD maintainer.

0 commit comments

Comments
 (0)