Skip to content

Commit caa81fc

Browse files
committed
Add some docs
1 parent f48447c commit caa81fc

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,76 @@ pub enum MutatingWebhookError {
2929
},
3030
}
3131

32+
/// Mutating webhook, which let's you intercept object creations/modification and modify the object
33+
/// on the fly.
34+
///
3235
/// As the webhook is typed with the Resource type `R`, it can only handle a single resource
3336
/// mutation. Use multiple [`MutatingWebhookServer`] if you need to mutate multiple resource kinds.
37+
///
38+
/// ### Example usage
39+
///
40+
/// This is only some high-level basic usage!
41+
///
42+
/// For concrete usage please have a look at the restart controller mutating webhook in
43+
/// commons-operator.
44+
///
45+
/// ```
46+
/// use std::sync::Arc;
47+
///
48+
/// use k8s_openapi::api::admissionregistration::v1::MutatingWebhook;
49+
/// use k8s_openapi::api::admissionregistration::v1::MutatingWebhookConfiguration;
50+
/// use k8s_openapi::api::apps::v1::StatefulSet;
51+
///
52+
/// use stackable_operator::builder::meta::ObjectMetaBuilder;
53+
/// use stackable_operator::kube::Client;
54+
/// use stackable_operator::kube::core::admission::{AdmissionRequest, AdmissionResponse};
55+
/// use stackable_operator::kvp::Label;
56+
/// use stackable_webhook::WebhookServer;
57+
/// use stackable_webhook::servers::MutatingWebhookServer;
58+
///
59+
/// # async fn docs() {
60+
/// // The Kubernetes client
61+
/// let client = Client::try_default().await.unwrap();
62+
/// // The context of the controller, e.g. contains a Kubernetes client
63+
/// let ctx = Arc::new(());
64+
/// // Read in from user input, e.g. CLI arguments
65+
/// let disable_restarter_mutating_webhook = false;
66+
///
67+
/// let mutating_webhook = Box::new(MutatingWebhookServer::new(
68+
/// get_mutating_webhook_configuration(),
69+
/// my_handler,
70+
/// ctx,
71+
/// disable_restarter_mutating_webhook,
72+
/// client,
73+
/// "my-field-manager".to_owned(),
74+
/// ));
75+
///
76+
/// let webhook_options = todo!();
77+
/// let webhook_server = WebhookServer::new(webhook_options, vec![mutating_webhook]).await.unwrap();
78+
/// webhook_server.run().await.unwrap();
79+
/// # }
80+
///
81+
/// fn get_mutating_webhook_configuration() -> MutatingWebhookConfiguration {
82+
/// let webhook_name = "pod-labeler.stackable.tech";
83+
///
84+
/// MutatingWebhookConfiguration {
85+
/// webhooks: Some(vec![MutatingWebhook {
86+
/// // This is checked by the stackable_webhook code
87+
/// admission_review_versions: vec!["v1".to_owned()],
88+
/// ..Default::default()
89+
/// }]),
90+
/// ..Default::default()
91+
/// }
92+
/// }
93+
///
94+
/// // Basic no-op implementation
95+
/// pub async fn my_handler(
96+
/// ctx: Arc<()>,
97+
/// request: AdmissionRequest<StatefulSet>,
98+
/// ) -> AdmissionResponse {
99+
/// AdmissionResponse::from(&request)
100+
/// }
101+
/// ```
34102
pub struct MutatingWebhookServer<H, S, R> {
35103
mutating_webhook_configuration: MutatingWebhookConfiguration,
36104
handler: H,

0 commit comments

Comments
 (0)