diff --git a/Cargo.lock b/Cargo.lock index 998583808..01b01c1c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3002,7 +3002,7 @@ dependencies = [ "sha2", "signature", "snafu 0.8.6", - "stackable-operator", + "stackable-shared", "tokio", "tokio-rustls", "tracing", @@ -3036,13 +3036,14 @@ dependencies = [ "serde_json", "serde_yaml", "snafu 0.8.6", + "stackable-certs", "stackable-operator-derive", "stackable-shared", "stackable-telemetry", "stackable-versioned", + "stackable-webhook", "strum", "tempfile", - "time", "tokio", "tracing", "tracing-appender", @@ -3067,10 +3068,14 @@ version = "0.0.1" dependencies = [ "k8s-openapi", "kube", + "rstest", + "schemars", "semver", "serde", "serde_yaml", "snafu 0.8.6", + "strum", + "time", ] [[package]] @@ -3160,6 +3165,7 @@ dependencies = [ "snafu 0.8.6", "stackable-certs", "stackable-operator", + "stackable-shared", "stackable-telemetry", "tokio", "tokio-rustls", diff --git a/crates/stackable-certs/Cargo.toml b/crates/stackable-certs/Cargo.toml index 86654d365..421a5e952 100644 --- a/crates/stackable-certs/Cargo.toml +++ b/crates/stackable-certs/Cargo.toml @@ -11,7 +11,7 @@ default = [] rustls = ["dep:tokio-rustls"] [dependencies] -stackable-operator = { path = "../stackable-operator" } +stackable-shared = { path = "../stackable-shared" } const-oid.workspace = true ecdsa.workspace = true diff --git a/crates/stackable-certs/src/ca/consts.rs b/crates/stackable-certs/src/ca/consts.rs index bcd080cd4..300a3cbec 100644 --- a/crates/stackable-certs/src/ca/consts.rs +++ b/crates/stackable-certs/src/ca/consts.rs @@ -1,4 +1,4 @@ -use stackable_operator::time::Duration; +use stackable_shared::time::Duration; /// The default CA validity time span pub const DEFAULT_CA_VALIDITY: Duration = Duration::from_hours_unchecked(1); diff --git a/crates/stackable-certs/src/ca/mod.rs b/crates/stackable-certs/src/ca/mod.rs index 08f57d918..79f0c5b3c 100644 --- a/crates/stackable-certs/src/ca/mod.rs +++ b/crates/stackable-certs/src/ca/mod.rs @@ -4,9 +4,9 @@ use std::{fmt::Debug, str::FromStr}; use const_oid::db::rfc5280::{ID_KP_CLIENT_AUTH, ID_KP_SERVER_AUTH}; use k8s_openapi::api::core::v1::Secret; -use kube::runtime::reflector::ObjectRef; +use kube::{Api, Client, runtime::reflector::ObjectRef}; use snafu::{OptionExt, ResultExt, Snafu}; -use stackable_operator::{client::Client, commons::secret::SecretReference, time::Duration}; +use stackable_shared::{secret::SecretReference, time::Duration}; use tracing::{debug, instrument}; use x509_cert::{ Certificate, @@ -454,15 +454,15 @@ where /// Create a [`CertificateAuthority`] from a Kubernetes [`SecretReference`]. #[instrument( name = "create_certificate_authority_from_k8s_secret_ref", - skip(secret_ref, client) + skip(client) )] pub async fn from_secret_ref( secret_ref: &SecretReference, key_certificate: &str, key_private_key: &str, - client: &Client, + client: Client, ) -> Result> { - let secret_api = client.get_api::(&secret_ref.namespace); + let secret_api = Api::namespaced(client, &secret_ref.namespace); let secret = secret_api .get(&secret_ref.name) .await diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index 7feceb1c4..3135f7d17 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -7,8 +7,10 @@ All notable changes to this project will be documented in this file. ### Added - Add `ProbeBuilder` to build Kubernetes container probes ([#1078]). +- Re-export `stackable-certs` and `stackable-webhook` crates ([#1074]). - BREAKING: Add two new required CLI arguments: `--operator-namespace` and `--operator-service-name`. These two values are used to construct the service name in the CRD conversion webhook ([#1066]). +- Re-export `stackable-certs` and `stackable-webhook` crates ([#1074]). ### Changed @@ -16,6 +18,10 @@ All notable changes to this project will be documented in this file. - BREAKING: Rename two fields of the `ProductOperatorRun` struct for consistency and clarity ([#1066]): - `telemetry_arguments` -> `telemetry` - `cluster_info_opts` -> `cluster_info` +- BREAKING: Some modules have been moved into the `stackable-shared` crate, so that they can also be + used in `stackable-certs` and `stackable-webhook` ([#1074]): + - The module `stackable_operator::time` has moved to `stackable_operator::shared::time` + - The module `stackable_operator::commons::secret` has moved to `stackable_operator::shared::secret` ### Fixed @@ -23,6 +29,7 @@ All notable changes to this project will be documented in this file. This is the case when referencing custom images via a `@sha256:...` hash. As such, the `product_image_selection::resolve` function is now fallible ([#1076]). [#1066]: https://github.com/stackabletech/operator-rs/pull/1066 +[#1074]: https://github.com/stackabletech/operator-rs/pull/1074 [#1076]: https://github.com/stackabletech/operator-rs/pull/1076 [#1078]: https://github.com/stackabletech/operator-rs/pull/1078 diff --git a/crates/stackable-operator/Cargo.toml b/crates/stackable-operator/Cargo.toml index 15b7bd78a..70c753a68 100644 --- a/crates/stackable-operator/Cargo.toml +++ b/crates/stackable-operator/Cargo.toml @@ -8,17 +8,22 @@ edition.workspace = true repository.workspace = true [features] -full = ["time", "telemetry", "versioned"] +full = ["certs", "telemetry", "versioned", "time", "webhook"] default = ["telemetry", "versioned"] -time = ["dep:time"] -telemetry = [] -versioned = [] + +certs = ["dep:stackable-certs"] +telemetry = ["dep:stackable-telemetry"] +time = ["stackable-shared/time"] +versioned = ["dep:stackable-versioned"] +webhook = ["dep:stackable-webhook"] [dependencies] +stackable-certs = { path = "../stackable-certs", optional = true } stackable-operator-derive = { path = "../stackable-operator-derive" } stackable-shared = { path = "../stackable-shared" } -stackable-telemetry = { path = "../stackable-telemetry", features = ["clap"] } -stackable-versioned = { path = "../stackable-versioned" } +stackable-telemetry = { path = "../stackable-telemetry", optional = true, features = ["clap"] } +stackable-versioned = { path = "../stackable-versioned", optional = true } +stackable-webhook = { path = "../stackable-webhook", optional = true } chrono.workspace = true clap.workspace = true @@ -42,7 +47,6 @@ serde_yaml.workspace = true serde.workspace = true snafu.workspace = true strum.workspace = true -time = { workspace = true, optional = true } tokio.workspace = true tracing.workspace = true tracing-appender.workspace = true diff --git a/crates/stackable-operator/src/builder/pod/mod.rs b/crates/stackable-operator/src/builder/pod/mod.rs index c5cb895f5..143f7bb13 100644 --- a/crates/stackable-operator/src/builder/pod/mod.rs +++ b/crates/stackable-operator/src/builder/pod/mod.rs @@ -10,6 +10,7 @@ use k8s_openapi::{ apimachinery::pkg::{api::resource::Quantity, apis::meta::v1::ObjectMeta}, }; use snafu::{OptionExt, ResultExt, Snafu}; +use stackable_shared::time::Duration; use crate::{ builder::{ @@ -25,7 +26,6 @@ use crate::{ }, }, kvp::Labels, - time::Duration, }; pub mod container; diff --git a/crates/stackable-operator/src/builder/pod/probe.rs b/crates/stackable-operator/src/builder/pod/probe.rs index 7278dfaa2..cf569b55c 100644 --- a/crates/stackable-operator/src/builder/pod/probe.rs +++ b/crates/stackable-operator/src/builder/pod/probe.rs @@ -9,7 +9,7 @@ //! ``` //! use stackable_operator::{ //! builder::pod::probe::ProbeBuilder, -//! time::Duration, +//! shared::time::Duration, //! }; //! # use k8s_openapi::api::core::v1::HTTPGetAction; //! # use k8s_openapi::apimachinery::pkg::util::intstr::IntOrString; @@ -36,8 +36,7 @@ use k8s_openapi::{ apimachinery::pkg::util::intstr::IntOrString, }; use snafu::{ResultExt, Snafu, ensure}; - -use crate::time::Duration; +use stackable_shared::time::Duration; #[derive(Debug, Snafu)] pub enum Error { diff --git a/crates/stackable-operator/src/builder/pod/volume.rs b/crates/stackable-operator/src/builder/pod/volume.rs index d27b54aa6..0175a11d4 100644 --- a/crates/stackable-operator/src/builder/pod/volume.rs +++ b/crates/stackable-operator/src/builder/pod/volume.rs @@ -9,12 +9,12 @@ use k8s_openapi::{ apimachinery::pkg::api::resource::Quantity, }; use snafu::{ResultExt, Snafu}; +use stackable_shared::time::Duration; use tracing::warn; use crate::{ builder::meta::ObjectMetaBuilder, kvp::{Annotation, AnnotationError, Annotations, LabelError, Labels}, - time::Duration, }; /// A builder to build [`Volume`] objects. May only contain one `volume_source` diff --git a/crates/stackable-operator/src/commons/cache.rs b/crates/stackable-operator/src/commons/cache.rs index 72ec8bf23..ada2ede83 100644 --- a/crates/stackable-operator/src/commons/cache.rs +++ b/crates/stackable-operator/src/commons/cache.rs @@ -3,8 +3,7 @@ use std::marker::PhantomData; use educe::Educe; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; - -use crate::time::Duration; +use stackable_shared::time::Duration; /// [`TtlCache`] with sensible defaults for a user information cache pub type UserInformationCache = TtlCache; diff --git a/crates/stackable-operator/src/commons/mod.rs b/crates/stackable-operator/src/commons/mod.rs index 21a778f83..89e71fc2f 100644 --- a/crates/stackable-operator/src/commons/mod.rs +++ b/crates/stackable-operator/src/commons/mod.rs @@ -9,6 +9,5 @@ pub mod pdb; pub mod product_image_selection; pub mod rbac; pub mod resources; -pub mod secret; pub mod secret_class; pub mod tls_verification; diff --git a/crates/stackable-operator/src/config/merge.rs b/crates/stackable-operator/src/config/merge.rs index be1c137ef..8a5172e28 100644 --- a/crates/stackable-operator/src/config/merge.rs +++ b/crates/stackable-operator/src/config/merge.rs @@ -11,8 +11,7 @@ use k8s_openapi::{ apimachinery::pkg::{api::resource::Quantity, apis::meta::v1::LabelSelector}, }; pub use stackable_operator_derive::Merge; - -use crate::time::Duration; +use stackable_shared::time::Duration; /// A type that can be merged with itself /// diff --git a/crates/stackable-operator/src/crd/git_sync/mod.rs b/crates/stackable-operator/src/crd/git_sync/mod.rs index bc63e2a13..92e9eab52 100644 --- a/crates/stackable-operator/src/crd/git_sync/mod.rs +++ b/crates/stackable-operator/src/crd/git_sync/mod.rs @@ -4,9 +4,10 @@ use std::{collections::BTreeMap, path::PathBuf}; use schemars::{self, JsonSchema}; use serde::{Deserialize, Serialize}; +use stackable_shared::time::Duration; use url::Url; -use crate::{time::Duration, versioned::versioned}; +use crate::versioned::versioned; mod v1alpha1_impl; diff --git a/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs b/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs index 934204dc7..a29789ba8 100644 --- a/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs +++ b/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs @@ -4,6 +4,7 @@ use k8s_openapi::api::core::v1::{ Container, EmptyDirVolumeSource, EnvVar, EnvVarSource, SecretKeySelector, Volume, VolumeMount, }; use snafu::{ResultExt, Snafu}; +use stackable_shared::time::Duration; use strum::{EnumDiscriminants, IntoStaticStr}; use crate::{ @@ -17,7 +18,6 @@ use crate::{ framework::capture_shell_output, spec::{ContainerLogConfig, ContainerLogConfigChoice}, }, - time::Duration, utils::COMMON_BASH_TRAP_FUNCTIONS, }; diff --git a/crates/stackable-operator/src/lib.rs b/crates/stackable-operator/src/lib.rs index f0ccc5991..2ad7e67ab 100644 --- a/crates/stackable-operator/src/lib.rs +++ b/crates/stackable-operator/src/lib.rs @@ -2,7 +2,7 @@ //! //! - `default` enables a default set of features which most operators need. //! - `full` enables all available features. -//! - `time` enables interoperability between [`time::Duration`] and the `time` crate. +//! - `time` enables interoperability between [`shared::time::Duration`] and the `time` crate. //! - `telemetry` enables various helpers for emitting telemetry data. //! - `versioned` enables the macro for CRD versioning. @@ -26,7 +26,6 @@ pub mod product_config_utils; pub mod product_logging; pub mod role_utils; pub mod status; -pub mod time; pub mod utils; pub mod validation; @@ -37,9 +36,13 @@ pub use schemars; // Internal re-exports // TODO (@Techassi): Ideally we would want webhook and certs exported here as // well, but that would require some restructuring of crates. +#[cfg(feature = "certs")] +pub use stackable_certs as certs; 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")] pub use stackable_versioned as versioned; +#[cfg(feature = "webhook")] +pub use stackable_webhook as webhook; diff --git a/crates/stackable-shared/Cargo.toml b/crates/stackable-shared/Cargo.toml index 906b4ec72..df6ee6ad4 100644 --- a/crates/stackable-shared/Cargo.toml +++ b/crates/stackable-shared/Cargo.toml @@ -6,12 +6,23 @@ license.workspace = true edition.workspace = true repository.workspace = true +[features] +full = ["time"] +default = ["time"] + +time = ["dep:time"] + [dependencies] +k8s-openapi.workspace = true kube.workspace = true +schemars.workspace = true semver.workspace = true serde.workspace = true serde_yaml.workspace = true snafu.workspace = true +strum.workspace = true +time = { workspace = true, optional = true } [dev-dependencies] k8s-openapi.workspace = true +rstest.workspace = true diff --git a/crates/stackable-shared/src/lib.rs b/crates/stackable-shared/src/lib.rs index ea8e41a91..2f9b8ae93 100644 --- a/crates/stackable-shared/src/lib.rs +++ b/crates/stackable-shared/src/lib.rs @@ -2,4 +2,7 @@ //! workspace. pub mod crd; +pub mod secret; + +pub mod time; pub mod yaml; diff --git a/crates/stackable-operator/src/commons/secret.rs b/crates/stackable-shared/src/secret.rs similarity index 100% rename from crates/stackable-operator/src/commons/secret.rs rename to crates/stackable-shared/src/secret.rs diff --git a/crates/stackable-operator/src/time/duration.rs b/crates/stackable-shared/src/time/duration.rs similarity index 100% rename from crates/stackable-operator/src/time/duration.rs rename to crates/stackable-shared/src/time/duration.rs diff --git a/crates/stackable-operator/src/time/mod.rs b/crates/stackable-shared/src/time/mod.rs similarity index 100% rename from crates/stackable-operator/src/time/mod.rs rename to crates/stackable-shared/src/time/mod.rs diff --git a/crates/stackable-operator/src/time/serde_impl.rs b/crates/stackable-shared/src/time/serde_impl.rs similarity index 100% rename from crates/stackable-operator/src/time/serde_impl.rs rename to crates/stackable-shared/src/time/serde_impl.rs diff --git a/crates/stackable-operator/src/time/time_impl.rs b/crates/stackable-shared/src/time/time_impl.rs similarity index 100% rename from crates/stackable-operator/src/time/time_impl.rs rename to crates/stackable-shared/src/time/time_impl.rs diff --git a/crates/stackable-webhook/Cargo.toml b/crates/stackable-webhook/Cargo.toml index 5c1bf70eb..21b876d47 100644 --- a/crates/stackable-webhook/Cargo.toml +++ b/crates/stackable-webhook/Cargo.toml @@ -8,8 +8,8 @@ repository.workspace = true [dependencies] stackable-certs = { path = "../stackable-certs", features = ["rustls"] } +stackable-shared = { path = "../stackable-shared" } stackable-telemetry = { path = "../stackable-telemetry" } -stackable-operator = { path = "../stackable-operator" } arc-swap.workspace = true axum.workspace = true @@ -32,4 +32,11 @@ tracing-opentelemetry.workspace = true x509-cert.workspace = true [dev-dependencies] +# Only needed for doc tests +stackable-operator = { path = "../stackable-operator" } + clap.workspace = true + +# Only needed for tests, this is a false positive of "cargo udeps" +[package.metadata.cargo-udeps.ignore] +development = ["stackable-operator"] diff --git a/crates/stackable-webhook/src/servers/conversion.rs b/crates/stackable-webhook/src/servers/conversion.rs index 5d8af83d9..ed6b63579 100644 --- a/crates/stackable-webhook/src/servers/conversion.rs +++ b/crates/stackable-webhook/src/servers/conversion.rs @@ -52,7 +52,7 @@ pub enum ConversionWebhookError { #[snafu(display("failed to update CRD {crd_name:?}"))] UpdateCrd { - source: stackable_operator::kube::Error, + source: kube::Error, crd_name: String, }, } diff --git a/crates/stackable-webhook/src/tls/mod.rs b/crates/stackable-webhook/src/tls/mod.rs index 861c0ba21..a796e8b38 100644 --- a/crates/stackable-webhook/src/tls/mod.rs +++ b/crates/stackable-webhook/src/tls/mod.rs @@ -12,7 +12,7 @@ use hyper_util::rt::{TokioExecutor, TokioIo}; use opentelemetry::trace::{FutureExt, SpanKind}; use opentelemetry_semantic_conventions as semconv; use snafu::{ResultExt, Snafu}; -use stackable_operator::time::Duration; +use stackable_shared::time::Duration; use tokio::{ net::{TcpListener, TcpStream}, sync::mpsc, diff --git a/crates/xtask/src/crd/dummy.rs b/crates/xtask/src/crd/dummy.rs index 3f0652e80..8df402de7 100644 --- a/crates/xtask/src/crd/dummy.rs +++ b/crates/xtask/src/crd/dummy.rs @@ -4,7 +4,7 @@ use stackable_operator::{ config::fragment::Fragment, kube::CustomResource, role_utils::Role, - schemars::{self, JsonSchema}, + schemars::JsonSchema, status::condition::ClusterCondition, versioned::versioned, }; @@ -44,7 +44,7 @@ pub mod versioned { pdb_config: stackable_operator::commons::pdb::PdbConfig, product_image: stackable_operator::commons::product_image_selection::ProductImage, secret_class_volume: stackable_operator::commons::secret_class::SecretClassVolume, - secret_reference: stackable_operator::commons::secret::SecretReference, + secret_reference: stackable_operator::shared::secret::SecretReference, tls_client_details: stackable_operator::commons::tls_verification::TlsClientDetails, // Already versioned