Skip to content

Commit 1c4e2ad

Browse files
committed
docs: Add some field level docs
1 parent 85481e8 commit 1c4e2ad

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

crates/stackable-webhook/src/webhooks/conversion_webhook.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,18 @@ pub enum ConversionWebhookError {
3939
}
4040

4141
pub struct ConversionWebhook<H> {
42+
/// The list of CRDs and their according handlers, which take and return a [`ConversionReview`]
4243
crds_and_handlers: Vec<(CustomResourceDefinition, H)>,
44+
45+
/// Whether CRDs should be maintained
4346
disable_crd_maintenance: bool,
47+
48+
/// The Kubernetes client used to maintain the CRDs
4449
client: Client,
45-
/// The field manager used when maintaining the CRDs.
50+
51+
/// The field manager used when maintaining the CRDs
4652
field_manager: String,
53+
4754
// This channel can only be used exactly once. The sender's send method consumes self, and
4855
// as such, the sender is wrapped in an Option to be able to call take to consume the inner
4956
// value.

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ pub enum MutatingWebhookError {
5757
/// // The context of the controller, e.g. contains a Kubernetes client
5858
/// let ctx = Arc::new(());
5959
/// // Read in from user input, e.g. CLI arguments
60-
/// let disable_restarter_mutating_webhook = false;
60+
/// let disable_mutating_webhook_configuration_maintenance = false;
6161
///
6262
/// let mutating_webhook = Box::new(MutatingWebhook::new(
6363
/// get_mutating_webhook_configuration(),
6464
/// my_handler,
6565
/// ctx,
66-
/// disable_restarter_mutating_webhook,
66+
/// disable_mutating_webhook_configuration_maintenance,
6767
/// client,
6868
/// "my-field-manager".to_owned(),
6969
/// ));
@@ -95,25 +95,37 @@ pub enum MutatingWebhookError {
9595
/// }
9696
/// ```
9797
pub struct MutatingWebhook<H, S, R> {
98+
/// The [`MutatingWebhookConfiguration`] that is applied to the Kubernetes cluster.
99+
///
100+
/// Your [`MutatingWebhookConfiguration`] can contain 0..n webhooks, but it is recommended to
101+
/// only have a single entry in there, as the clientConfig of all entries will be set to the
102+
/// same service, port and HTTP path.
103+
///
104+
/// All webhooks need to set the `admissionReviewVersions` to `["v1"]`, as this mutating webhook
105+
/// only supports that version! A failure to do so will result in a panic during the
106+
/// [`MutatingWebhook`] creation.
98107
mutating_webhook_configuration: MutatingWebhookConfiguration,
108+
109+
/// The async handler that get's a [`AdmissionRequest`] and returns an [`AdmissionResponse`]
99110
handler: H,
111+
112+
/// The internal state of the webhook. You can define yourself what exactly this state is.
100113
handler_state: Arc<S>,
114+
115+
/// This field is not needed, it only tracks the type of the Kubernetes resource we are mutating
101116
_resource: PhantomData<R>,
102117

118+
/// Whether MutatingWebhookConfigurations should be maintained
103119
disable_mutating_webhook_configuration_maintenance: bool,
120+
121+
/// The Kubernetes client used to maintain the MutatingWebhookConfigurations
104122
client: Client,
105123

106-
/// The field manager used when maintaining the MutatingWebhookConfigurations.
124+
/// The field manager used when maintaining the MutatingWebhookConfigurations
107125
field_manager: String,
108126
}
109127

110128
impl<H, S, R> MutatingWebhook<H, S, R> {
111-
/// All webhooks need to set the admissionReviewVersions to `["v1"]`, as this mutating webhook
112-
/// only supports that version! A failure to do so will result in a panic.
113-
///
114-
/// Your [`MutatingWebhookConfiguration`] can contain 0..n webhooks, but it is recommended to
115-
/// only have a single entry in there, as the clientConfig of all entries will be set to the
116-
/// same service, port and HTTP path.
117129
pub fn new(
118130
mutating_webhook_configuration: MutatingWebhookConfiguration,
119131
handler: H,

crates/stackable-webhook/src/webhooks/validating_webhook.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,37 @@ pub enum ValidatingWebhookError {
3535
///
3636
/// TODO
3737
pub struct ValidatingWebhook<H, S, R> {
38+
/// The [`ValidatingWebhookConfiguration`] that is applied to the Kubernetes cluster.
39+
///
40+
/// Your [`ValidatingWebhookConfiguration`] can contain 0..n webhooks, but it is recommended to
41+
/// only have a single entry in there, as the clientConfig of all entries will be set to the
42+
/// same service, port and HTTP path.
43+
///
44+
/// All webhooks need to set the `admissionReviewVersions` to `["v1"]`, as this validating webhook
45+
/// only supports that version! A failure to do so will result in a panic during the
46+
/// [`ValidatingWebhook`] creation.
3847
validating_webhook_configuration: ValidatingWebhookConfiguration,
48+
49+
/// The async handler that get's a [`AdmissionRequest`] and returns an [`AdmissionResponse`]
3950
handler: H,
51+
52+
/// The internal state of the webhook. You can define yourself what exactly this state is.
4053
handler_state: Arc<S>,
54+
55+
/// This field is not needed, it only tracks the type of the Kubernetes resource we are mutating
4156
_resource: PhantomData<R>,
4257

58+
/// Whether ValidatingWebhookConfigurations should be maintained
4359
disable_validating_webhook_configuration_maintenance: bool,
60+
61+
/// The Kubernetes client used to maintain the MutatingWebhookConfigurations
4462
client: Client,
4563

4664
/// The field manager used when maintaining the ValidatingWebhookConfigurations.
4765
field_manager: String,
4866
}
4967

5068
impl<H, S, R> ValidatingWebhook<H, S, R> {
51-
/// All webhooks need to set the admissionReviewVersions to `["v1"]`, as this validating webhook
52-
/// only supports that version! A failure to do so will result in a panic.
53-
///
54-
/// Your [`ValidatingWebhookConfiguration`] can contain 0..n webhooks, but it is recommended to
55-
/// only have a single entry in there, as the clientConfig of all entries will be set to the
56-
/// same service, port and HTTP path.
5769
pub fn new(
5870
validating_webhook_configuration: ValidatingWebhookConfiguration,
5971
handler: H,
@@ -149,6 +161,8 @@ where
149161

150162
let vwc_api: Api<ValidatingWebhookConfiguration> = Api::all(self.client.clone());
151163
// Other than with the CRDs we don't need to force-apply the ValidatingWebhookConfiguration
164+
// This is because the operators are, have been (and likely will be) the only ones creating
165+
// them.
152166
let patch = Patch::Apply(&validating_webhook_configuration);
153167
let patch_params = PatchParams::apply(&self.field_manager);
154168

0 commit comments

Comments
 (0)