Skip to content

Commit fa9c584

Browse files
committed
feat!: Add a new CLI flag/env to disabling CRD maintenance
1 parent 89f484c commit fa9c584

File tree

4 files changed

+56
-19
lines changed

4 files changed

+56
-19
lines changed

crates/stackable-operator/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- BREAKING: Add a new CLI flag/env to disabling CRD maintenance: `--disable-crd-maintenance` ([#10XX]).
10+
11+
[#10XX]: https://github.com/stackabletech/operator-rs/pull/10XX
12+
713
## [0.96.0] - 2025-08-25
814

915
### Added

crates/stackable-operator/src/cli.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,17 @@ pub struct ProductOperatorRun {
245245
/// Provides a specific namespace to watch (instead of watching all namespaces)
246246
#[arg(long, env, default_value = "")]
247247
pub watch_namespace: WatchNamespace,
248+
249+
/// Don't maintain the CustomResourceDefinitions (CRDs) the operator is responsible for.
250+
///
251+
/// Maintenance includes creating the CRD initially, adding new versions and keeping the TLS
252+
/// certificate of webhooks up to date. Turning this off can be desirable to reduce the RBAC
253+
/// permission of the operators.
254+
///
255+
/// WARNING: If you disable CRD maintenance you are responsible for maintaining it, including
256+
/// the points above.
257+
#[arg(long, env)]
258+
pub disable_crd_maintenance: bool,
248259
}
249260

250261
/// All the CLI arguments that all (or at least most) Stackable applications use.

crates/stackable-webhook/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- BREAKING: Support disabling CRD maintenance using a new boolean flag in `ConversionWebhookServer::new` ([#10XX]).
10+
11+
[#10XX]: https://github.com/stackabletech/operator-rs/pull/10XX
12+
713
## [0.5.0] - 2025-08-21
814

915
### Changed

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

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,22 @@ pub struct ConversionWebhookServer {
9191
options: ConversionWebhookOptions,
9292
router: Router,
9393
client: Client,
94+
maintain_crds: bool,
9495
}
9596

9697
impl ConversionWebhookServer {
9798
/// Creates a new conversion webhook server, which expects POST requests being made to the
9899
/// `/convert/{crd name}` endpoint.
99100
///
100-
/// You need to provide two things for every CRD passed in via the `crds_and_handlers` argument:
101+
/// You need to provide a few things for every CRD passed in via the `crds_and_handlers` argument:
101102
///
102103
/// 1. The CRD
103104
/// 2. A conversion function to convert between CRD versions. Typically you would use the
104-
/// the auto-generated `try_convert` function on CRD spec definition structs for this.
105+
/// the auto-generated `try_convert` function on CRD spec definition structs for this.
106+
/// 3. A [`kube::Client`] used to create/update the CRDs.
107+
/// 4. If we should maintain the CRDs. Use `stackable_operator::cli::ProductOperatorRun::disable_crd_maintenance`
108+
/// for this.
109+
// # Because of https://github.com/rust-lang/cargo/issues/3475 we can not use a real link here
105110
///
106111
/// The [`ConversionWebhookServer`] takes care of reconciling the CRDs into the Kubernetes
107112
/// cluster and takes care of adding itself as conversion webhook. This includes TLS
@@ -165,6 +170,7 @@ impl ConversionWebhookServer {
165170
crds_and_handlers: impl IntoIterator<Item = (CustomResourceDefinition, H)>,
166171
options: ConversionWebhookOptions,
167172
client: Client,
173+
maintain_crds: bool,
168174
) -> Result<Self, ConversionWebhookError>
169175
where
170176
H: WebhookHandler<ConversionReview, ConversionReview> + Clone + Send + Sync + 'static,
@@ -190,6 +196,7 @@ impl ConversionWebhookServer {
190196
router,
191197
client,
192198
crds,
199+
maintain_crds,
193200
})
194201
}
195202

@@ -201,6 +208,7 @@ impl ConversionWebhookServer {
201208
router,
202209
client,
203210
crds,
211+
maintain_crds,
204212
} = self;
205213

206214
let ConversionWebhookOptions {
@@ -233,28 +241,34 @@ impl ConversionWebhookServer {
233241
.recv()
234242
.await
235243
.context(ReceiveCertificateFromChannelSnafu)?;
236-
Self::reconcile_crds(
237-
&client,
238-
field_manager,
239-
&crds,
240-
operator_namespace,
241-
operator_service_name,
242-
current_cert,
243-
)
244-
.await
245-
.context(ReconcileCrdsSnafu)?;
246-
247-
try_join!(
248-
Self::run_webhook_server(server),
249-
Self::run_crd_reconciliation_loop(
250-
cert_rx,
244+
if maintain_crds {
245+
Self::reconcile_crds(
251246
&client,
252247
field_manager,
253248
&crds,
254249
operator_namespace,
255250
operator_service_name,
256-
),
257-
)?;
251+
current_cert,
252+
)
253+
.await
254+
.context(ReconcileCrdsSnafu)?;
255+
}
256+
257+
if maintain_crds {
258+
try_join!(
259+
Self::run_webhook_server(server),
260+
Self::run_crd_reconciliation_loop(
261+
cert_rx,
262+
&client,
263+
field_manager,
264+
&crds,
265+
operator_namespace,
266+
operator_service_name,
267+
),
268+
)?;
269+
} else {
270+
Self::run_webhook_server(server).await?;
271+
};
258272

259273
Ok(())
260274
}

0 commit comments

Comments
 (0)