From 434fcfb292bc970d22a53996b3e4a2c1ddd060cf Mon Sep 17 00:00:00 2001 From: Techassi Date: Mon, 2 Mar 2026 16:58:27 +0100 Subject: [PATCH] fix: Correctly feature-gate code This commit renames the versioned feature to crd. It also correctly feature-gates code to be able to support no default features. --- crates/stackable-operator/Cargo.toml | 20 +++++++++++++------ .../stackable-operator/src/cli/maintenance.rs | 2 ++ crates/stackable-operator/src/cli/mod.rs | 6 ++++-- .../src/cluster_resources.rs | 9 +++++++-- crates/stackable-operator/src/eos/mod.rs | 2 ++ crates/stackable-operator/src/lib.rs | 3 ++- 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/crates/stackable-operator/Cargo.toml b/crates/stackable-operator/Cargo.toml index 4c2181b7e..15e32b73a 100644 --- a/crates/stackable-operator/Cargo.toml +++ b/crates/stackable-operator/Cargo.toml @@ -8,15 +8,23 @@ edition.workspace = true repository.workspace = true [features] -full = ["certs", "telemetry", "versioned", "time", "webhook", "clap"] -default = ["telemetry", "versioned", "clap"] +# --- The section below defines features which are collections of other features --- +# NOTE (@Techassi): These lists should be kept in the same order as features are defined below. +full = ["clap", "crd", "telemetry", "webhook", "time", "certs"] +default = ["clap", "crd", "telemetry"] + +# --- The section below defines features which toggle individual functionality --- + +# This feature enables support for clap on various structs and enums to be used in clap-based CLIs. +clap = ["stackable-telemetry/clap"] + +# This feature enables various (versioned) CRD structs and enums to be exported. +crd = ["dep:stackable-versioned"] -clap = [] -certs = ["dep:stackable-certs"] telemetry = ["dep:stackable-telemetry"] -time = ["stackable-shared/time"] -versioned = ["dep:stackable-versioned"] webhook = ["dep:stackable-webhook"] +time = ["stackable-shared/time"] +certs = ["dep:stackable-certs"] [dependencies] stackable-certs = { path = "../stackable-certs", optional = true } diff --git a/crates/stackable-operator/src/cli/maintenance.rs b/crates/stackable-operator/src/cli/maintenance.rs index 13533f319..9a2da5f67 100644 --- a/crates/stackable-operator/src/cli/maintenance.rs +++ b/crates/stackable-operator/src/cli/maintenance.rs @@ -1,5 +1,6 @@ use clap::Args; +#[cfg(feature = "clap")] use crate::eos::EndOfSupportOptions; #[derive(Debug, PartialEq, Eq, Args)] @@ -18,6 +19,7 @@ pub struct MaintenanceOptions { // IMPORTANT: All (flattened) sub structs should be placed at the end to ensure the help // headings are correct. + #[cfg(feature = "clap")] #[command(flatten)] pub end_of_support: EndOfSupportOptions, } diff --git a/crates/stackable-operator/src/cli/mod.rs b/crates/stackable-operator/src/cli/mod.rs index 0224604fc..c9d70111c 100644 --- a/crates/stackable-operator/src/cli/mod.rs +++ b/crates/stackable-operator/src/cli/mod.rs @@ -2,9 +2,10 @@ //! running in a Kubernetes cluster. use clap::{Args, Parser}; -use stackable_telemetry::tracing::TelemetryOptions; -use crate::{namespace::WatchNamespace, utils::cluster_info::KubernetesClusterInfoOptions}; +#[cfg(feature = "clap")] +use crate::utils::cluster_info::KubernetesClusterInfoOptions; +use crate::{namespace::WatchNamespace, telemetry::tracing::TelemetryOptions}; mod environment; mod maintenance; @@ -111,6 +112,7 @@ pub struct CommonOptions { #[command(flatten)] pub telemetry: TelemetryOptions, + #[cfg(feature = "clap")] #[command(flatten)] pub cluster_info: KubernetesClusterInfoOptions, } diff --git a/crates/stackable-operator/src/cluster_resources.rs b/crates/stackable-operator/src/cluster_resources.rs index b8ece1137..ddc2a211c 100644 --- a/crates/stackable-operator/src/cluster_resources.rs +++ b/crates/stackable-operator/src/cluster_resources.rs @@ -27,6 +27,8 @@ use serde::{Serialize, de::DeserializeOwned}; use snafu::{OptionExt, ResultExt, Snafu}; use tracing::{debug, info, warn}; +#[cfg(feature = "crd")] +use crate::crd::listener; use crate::{ client::{Client, GetApi}, commons::{ @@ -36,7 +38,6 @@ use crate::{ ResourceRequirementsExt, ResourceRequirementsType, }, }, - crd::listener, deep_merger::{self, ObjectOverrides}, kvp::{ Label, LabelError, Labels, @@ -221,6 +222,7 @@ impl ClusterResource for Service {} impl ClusterResource for ServiceAccount {} impl ClusterResource for RoleBinding {} impl ClusterResource for PodDisruptionBudget {} +#[cfg(feature = "crd")] impl ClusterResource for listener::v1alpha1::Listener {} impl ClusterResource for Job { @@ -680,9 +682,12 @@ impl<'a> ClusterResources<'a> { self.delete_orphaned_resources_of_kind::(client), self.delete_orphaned_resources_of_kind::(client), self.delete_orphaned_resources_of_kind::(client), - self.delete_orphaned_resources_of_kind::(client), )?; + #[cfg(feature = "crd")] + self.delete_orphaned_resources_of_kind::(client) + .await?; + Ok(()) } diff --git a/crates/stackable-operator/src/eos/mod.rs b/crates/stackable-operator/src/eos/mod.rs index 7e732c175..8caf93f01 100644 --- a/crates/stackable-operator/src/eos/mod.rs +++ b/crates/stackable-operator/src/eos/mod.rs @@ -41,6 +41,8 @@ pub struct EndOfSupportOptions { pub support_duration: Duration, } +// These default functions are only needed when this is used in CLIs. +#[cfg(feature = "clap")] impl EndOfSupportOptions { fn default_interval() -> Duration { if cfg!(debug_assertions) { diff --git a/crates/stackable-operator/src/lib.rs b/crates/stackable-operator/src/lib.rs index c73e72143..df969babf 100644 --- a/crates/stackable-operator/src/lib.rs +++ b/crates/stackable-operator/src/lib.rs @@ -14,6 +14,7 @@ pub mod commons; pub mod config; pub mod constants; pub mod cpu; +#[cfg(feature = "crd")] pub mod crd; pub mod deep_merger; pub mod eos; @@ -44,7 +45,7 @@ pub use stackable_shared as shared; pub use stackable_shared::{crd::CustomResourceExt, yaml::YamlSchema}; #[cfg(feature = "telemetry")] pub use stackable_telemetry as telemetry; -#[cfg(feature = "versioned")] +#[cfg(feature = "crd")] pub use stackable_versioned as versioned; #[cfg(feature = "webhook")] pub use stackable_webhook as webhook;