diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bb20c6880..51728bedf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ env: CARGO_TERM_COLOR: always CARGO_INCREMENTAL: '0' CARGO_PROFILE_DEV_DEBUG: '0' - RUST_TOOLCHAIN_VERSION: "1.84.1" + RUST_TOOLCHAIN_VERSION: "1.85.0" RUSTFLAGS: "-D warnings" RUSTDOCFLAGS: "-D warnings" RUST_LOG: "info" @@ -64,59 +64,6 @@ jobs: with: command: check ${{ matrix.checks }} - run_rustfmt: - name: Run Rustfmt - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - persist-credentials: false - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }} - components: rustfmt - - uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7 - with: - key: fmt - - run: cargo fmt --all -- --check - - run_clippy: - name: Run Clippy - runs-on: ubuntu-latest - steps: - - name: Install host dependencies - run: | - sudo apt-get update - sudo apt-get install protobuf-compiler krb5-user libkrb5-dev libclang-dev liblzma-dev libssl-dev pkg-config - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - persist-credentials: false - submodules: recursive - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }} - components: clippy - - uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7 - with: - key: clippy - - name: Run clippy action to produce annotations - # NOTE (@Techassi): This action might get a new release sonn, because it - # currently uses Node 16, which is deprecated in the next few months by - # GitHub. See https://github.com/giraffate/clippy-action/pull/87 - uses: giraffate/clippy-action@13b9d32482f25d29ead141b79e7e04e7900281e0 # v1.0.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - if: env.GITHUB_TOKEN != null && github.event.pull_request.draft == false - with: - clippy_flags: --all-targets -- -D warnings - reporter: 'github-pr-review' - github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Run clippy manually without annotations - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - if: env.GITHUB_TOKEN == null - run: cargo clippy --color never -q --all-targets -- -D warnings - run_rustdoc: name: Run RustDoc runs-on: ubuntu-latest @@ -136,8 +83,6 @@ jobs: run_tests: name: Run Cargo Tests needs: - - run_clippy - - run_rustfmt - run_rustdoc runs-on: ubuntu-latest steps: diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 3ab7055da..4dbb5f61a 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -13,7 +13,7 @@ on: - crates/** env: - RUST_TOOLCHAIN_VERSION: "1.84.1" + RUST_TOOLCHAIN_VERSION: "1.85.0" permissions: {} diff --git a/Cargo.toml b/Cargo.toml index 4cea8ca84..b43ada61b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [workspace] members = ["crates/*"] -resolver = "2" +resolver = "3" [workspace.package] authors = ["Stackable GmbH "] license = "Apache-2.0" -edition = "2021" +edition = "2024" repository = "https://github.com/stackabletech/operator-rs" [workspace.dependencies] diff --git a/crates/k8s-version/src/group.rs b/crates/k8s-version/src/group.rs index 9094b3b5e..ebe7c912b 100644 --- a/crates/k8s-version/src/group.rs +++ b/crates/k8s-version/src/group.rs @@ -1,7 +1,7 @@ use std::{fmt, ops::Deref, str::FromStr, sync::LazyLock}; use regex::Regex; -use snafu::{ensure, Snafu}; +use snafu::{Snafu, ensure}; const MAX_GROUP_LENGTH: usize = 253; diff --git a/crates/k8s-version/src/version.rs b/crates/k8s-version/src/version.rs index 6f6b16d55..ab6a2cc90 100644 --- a/crates/k8s-version/src/version.rs +++ b/crates/k8s-version/src/version.rs @@ -16,7 +16,9 @@ static VERSION_REGEX: LazyLock = LazyLock::new(|| { /// unparsed input. #[derive(Debug, PartialEq, Snafu)] pub enum ParseVersionError { - #[snafu(display("invalid version format. Input is empty, contains non-ASCII characters or contains more than 63 characters"))] + #[snafu(display( + "invalid version format. Input is empty, contains non-ASCII characters or contains more than 63 characters" + ))] InvalidFormat, #[snafu(display("failed to parse major version"))] diff --git a/crates/stackable-certs/src/ca/mod.rs b/crates/stackable-certs/src/ca/mod.rs index 28779d936..7c793d4f8 100644 --- a/crates/stackable-certs/src/ca/mod.rs +++ b/crates/stackable-certs/src/ca/mod.rs @@ -10,7 +10,7 @@ use stackable_operator::{client::Client, commons::secret::SecretReference, time: use tracing::{debug, instrument}; use x509_cert::{ builder::{Builder, CertificateBuilder, Profile}, - der::{pem::LineEnding, referenced::OwnedToRef, DecodePem}, + der::{DecodePem, pem::LineEnding, referenced::OwnedToRef}, ext::pkix::{AuthorityKeyIdentifier, ExtendedKeyUsage}, name::Name, serial_number::SerialNumber, @@ -19,8 +19,8 @@ use x509_cert::{ }; use crate::{ - keys::{ecdsa, rsa, CertificateKeypair}, CertificatePair, + keys::{CertificateKeypair, ecdsa, rsa}, }; mod consts; diff --git a/crates/stackable-certs/src/keys/ecdsa.rs b/crates/stackable-certs/src/keys/ecdsa.rs index c5ee0439b..38de9d225 100644 --- a/crates/stackable-certs/src/keys/ecdsa.rs +++ b/crates/stackable-certs/src/keys/ecdsa.rs @@ -1,7 +1,7 @@ //! Abstraction layer around the [`ecdsa`] crate. This module provides types //! which abstract away the generation of ECDSA keys used for signing of CAs //! and other certificates. -use p256::{pkcs8::DecodePrivateKey, NistP256}; +use p256::{NistP256, pkcs8::DecodePrivateKey}; use rand_core::{CryptoRngCore, OsRng}; use snafu::{ResultExt, Snafu}; use tracing::instrument; diff --git a/crates/stackable-certs/src/keys/rsa.rs b/crates/stackable-certs/src/keys/rsa.rs index dc70ccd0e..2bcd018ee 100644 --- a/crates/stackable-certs/src/keys/rsa.rs +++ b/crates/stackable-certs/src/keys/rsa.rs @@ -2,7 +2,7 @@ //! which abstract away the generation of RSA keys used for signing of CAs //! and other certificates. use rand_core::{CryptoRngCore, OsRng}; -use rsa::{pkcs8::DecodePrivateKey, RsaPrivateKey}; +use rsa::{RsaPrivateKey, pkcs8::DecodePrivateKey}; use signature::Keypair; use snafu::{ResultExt, Snafu}; use tracing::instrument; diff --git a/crates/stackable-certs/src/lib.rs b/crates/stackable-certs/src/lib.rs index cb4324453..5b9c87327 100644 --- a/crates/stackable-certs/src/lib.rs +++ b/crates/stackable-certs/src/lib.rs @@ -22,7 +22,7 @@ use std::ops::Deref; use snafu::Snafu; -use x509_cert::{spki::EncodePublicKey, Certificate}; +use x509_cert::{Certificate, spki::EncodePublicKey}; #[cfg(feature = "rustls")] use { p256::pkcs8::EncodePrivateKey, diff --git a/crates/stackable-operator-derive/src/fragment.rs b/crates/stackable-operator-derive/src/fragment.rs index 82d532f05..6b2a9fae7 100644 --- a/crates/stackable-operator-derive/src/fragment.rs +++ b/crates/stackable-operator-derive/src/fragment.rs @@ -1,9 +1,9 @@ -use darling::{ast::Data, FromDeriveInput, FromField, FromMeta, FromVariant}; +use darling::{FromDeriveInput, FromField, FromMeta, FromVariant, ast::Data}; use proc_macro2::{Ident, TokenStream, TokenTree}; -use quote::{format_ident, quote, ToTokens}; +use quote::{ToTokens, format_ident, quote}; use syn::{ - parse_quote, Attribute, DeriveInput, Generics, Meta, MetaList, Path, Type, Visibility, - WherePredicate, + Attribute, DeriveInput, Generics, Meta, MetaList, Path, Type, Visibility, WherePredicate, + parse_quote, }; #[derive(FromMeta)] @@ -125,7 +125,7 @@ pub fn derive(input: DeriveInput) -> TokenStream { Data::Enum(_) => { return quote! { compile_error!("`#[derive(Fragment)]` does not currently support enums"); - } + }; } Data::Struct(fields) => fields.fields, }; diff --git a/crates/stackable-operator-derive/src/merge.rs b/crates/stackable-operator-derive/src/merge.rs index 1b3952872..d66310087 100644 --- a/crates/stackable-operator-derive/src/merge.rs +++ b/crates/stackable-operator-derive/src/merge.rs @@ -1,10 +1,10 @@ use darling::{ - ast::{Data, Fields}, FromDeriveInput, FromField, FromMeta, FromVariant, + ast::{Data, Fields}, }; use proc_macro2::{Ident, Span, TokenStream}; use quote::{format_ident, quote}; -use syn::{parse_quote, DeriveInput, Generics, Index, Path, WherePredicate}; +use syn::{DeriveInput, Generics, Index, Path, WherePredicate, parse_quote}; #[derive(FromMeta)] struct PathOverrides { @@ -67,13 +67,10 @@ pub fn derive(input: DeriveInput) -> TokenStream { let (ty, variants) = match data { // Structs are almost single-variant enums, so we can reuse most of the same matching code for both cases - Data::Struct(fields) => ( - InputType::Struct, - vec![MergeVariant { - ident: Ident::new("__placeholder", Span::call_site()), - fields, - }], - ), + Data::Struct(fields) => (InputType::Struct, vec![MergeVariant { + ident: Ident::new("__placeholder", Span::call_site()), + fields, + }]), Data::Enum(variants) => (InputType::Enum, variants), }; let merge_variants = variants diff --git a/crates/stackable-operator/src/builder/pdb.rs b/crates/stackable-operator/src/builder/pdb.rs index 89bb94891..0a5f2f70c 100644 --- a/crates/stackable-operator/src/builder/pdb.rs +++ b/crates/stackable-operator/src/builder/pdb.rs @@ -205,7 +205,7 @@ mod tests { api::policy::v1::{PodDisruptionBudget, PodDisruptionBudgetSpec}, apimachinery::pkg::{apis::meta::v1::LabelSelector, util::intstr::IntOrString}, }; - use kube::{core::ObjectMeta, CustomResource}; + use kube::{CustomResource, core::ObjectMeta}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -229,28 +229,22 @@ mod tests { .with_min_available(42) .build(); - assert_eq!( - pdb, - PodDisruptionBudget { - metadata: ObjectMeta { - name: Some("trino".to_string()), - namespace: Some("default".to_string()), - ..Default::default() - }, - spec: Some(PodDisruptionBudgetSpec { - min_available: Some(IntOrString::Int(42)), - selector: Some(LabelSelector { - match_expressions: None, - match_labels: Some(BTreeMap::from([( - "foo".to_string(), - "bar".to_string() - )])), - }), - ..Default::default() + assert_eq!(pdb, PodDisruptionBudget { + metadata: ObjectMeta { + name: Some("trino".to_string()), + namespace: Some("default".to_string()), + ..Default::default() + }, + spec: Some(PodDisruptionBudgetSpec { + min_available: Some(IntOrString::Int(42)), + selector: Some(LabelSelector { + match_expressions: None, + match_labels: Some(BTreeMap::from([("foo".to_string(), "bar".to_string())])), }), ..Default::default() - } - ) + }), + ..Default::default() + }) } #[test] @@ -289,55 +283,54 @@ mod tests { .with_max_unavailable(2) .build(); - assert_eq!( - pdb, - PodDisruptionBudget { - metadata: ObjectMeta { - name: Some("simple-trino-worker".to_string()), - namespace: Some("default".to_string()), - labels: Some(BTreeMap::from([ + assert_eq!(pdb, PodDisruptionBudget { + metadata: ObjectMeta { + name: Some("simple-trino-worker".to_string()), + namespace: Some("default".to_string()), + labels: Some(BTreeMap::from([ + ("app.kubernetes.io/name".to_string(), "trino".to_string()), + ( + "app.kubernetes.io/instance".to_string(), + "simple-trino".to_string() + ), + ( + "app.kubernetes.io/managed-by".to_string(), + "trino.stackable.tech_trino-operator-trino-controller".to_string() + ), + ( + "app.kubernetes.io/component".to_string(), + "worker".to_string() + ) + ])), + owner_references: Some(vec![ + OwnerReferenceBuilder::new() + .initialize_from_resource(&trino) + .block_owner_deletion_opt(None) + .controller_opt(Some(true)) + .build() + .unwrap() + ]), + ..Default::default() + }, + spec: Some(PodDisruptionBudgetSpec { + max_unavailable: Some(IntOrString::Int(2)), + selector: Some(LabelSelector { + match_expressions: None, + match_labels: Some(BTreeMap::from([ ("app.kubernetes.io/name".to_string(), "trino".to_string()), ( "app.kubernetes.io/instance".to_string(), "simple-trino".to_string() ), - ( - "app.kubernetes.io/managed-by".to_string(), - "trino.stackable.tech_trino-operator-trino-controller".to_string() - ), ( "app.kubernetes.io/component".to_string(), "worker".to_string() ) ])), - owner_references: Some(vec![OwnerReferenceBuilder::new() - .initialize_from_resource(&trino) - .block_owner_deletion_opt(None) - .controller_opt(Some(true)) - .build() - .unwrap()]), - ..Default::default() - }, - spec: Some(PodDisruptionBudgetSpec { - max_unavailable: Some(IntOrString::Int(2)), - selector: Some(LabelSelector { - match_expressions: None, - match_labels: Some(BTreeMap::from([ - ("app.kubernetes.io/name".to_string(), "trino".to_string()), - ( - "app.kubernetes.io/instance".to_string(), - "simple-trino".to_string() - ), - ( - "app.kubernetes.io/component".to_string(), - "worker".to_string() - ) - ])), - }), - ..Default::default() }), ..Default::default() - } - ) + }), + ..Default::default() + }) } } diff --git a/crates/stackable-operator/src/builder/pod/container.rs b/crates/stackable-operator/src/builder/pod/container.rs index 7997ecc60..fc5cafeca 100644 --- a/crates/stackable-operator/src/builder/pod/container.rs +++ b/crates/stackable-operator/src/builder/pod/container.rs @@ -121,16 +121,13 @@ impl ContainerBuilder { name: impl Into, field_path: FieldPathEnvVar, ) -> &mut Self { - self.add_env_var_from_source( - name, - EnvVarSource { - field_ref: Some(ObjectFieldSelector { - field_path: field_path.to_string(), - ..ObjectFieldSelector::default() - }), - ..EnvVarSource::default() - }, - ); + self.add_env_var_from_source(name, EnvVarSource { + field_ref: Some(ObjectFieldSelector { + field_path: field_path.to_string(), + ..ObjectFieldSelector::default() + }), + ..EnvVarSource::default() + }); self } @@ -141,17 +138,14 @@ impl ContainerBuilder { secret_name: impl Into, secret_key: impl Into, ) -> &mut Self { - self.add_env_var_from_source( - name, - EnvVarSource { - secret_key_ref: Some(SecretKeySelector { - name: secret_name.into(), - key: secret_key.into(), - ..Default::default() - }), + self.add_env_var_from_source(name, EnvVarSource { + secret_key_ref: Some(SecretKeySelector { + name: secret_name.into(), + key: secret_key.into(), ..Default::default() - }, - ); + }), + ..Default::default() + }); self } @@ -162,17 +156,14 @@ impl ContainerBuilder { config_map_name: impl Into, config_map_key: impl Into, ) -> &mut Self { - self.add_env_var_from_source( - name, - EnvVarSource { - config_map_key_ref: Some(ConfigMapKeySelector { - name: config_map_name.into(), - key: config_map_key.into(), - ..Default::default() - }), + self.add_env_var_from_source(name, EnvVarSource { + config_map_key_ref: Some(ConfigMapKeySelector { + name: config_map_name.into(), + key: config_map_key.into(), ..Default::default() - }, - ); + }), + ..Default::default() + }); self } @@ -469,9 +460,11 @@ mod tests { .expect("add volume mount") .add_container_port(container_port_name, container_port) .resources(resources.clone()) - .add_container_ports(vec![ContainerPortBuilder::new(container_port_1) - .name(container_port_name_1) - .build()]) + .add_container_ports(vec![ + ContainerPortBuilder::new(container_port_1) + .name(container_port_name_1) + .build(), + ]) .build(); assert_eq!(container.name, "testcontainer"); diff --git a/crates/stackable-operator/src/builder/pod/mod.rs b/crates/stackable-operator/src/builder/pod/mod.rs index 2140066dc..03aab690b 100644 --- a/crates/stackable-operator/src/builder/pod/mod.rs +++ b/crates/stackable-operator/src/builder/pod/mod.rs @@ -21,8 +21,8 @@ use crate::{ affinity::StackableAffinity, product_image_selection::ResolvedProductImage, resources::{ - ComputeResource, ResourceRequirementsExt, ResourceRequirementsType, - LIMIT_REQUEST_RATIO_CPU, LIMIT_REQUEST_RATIO_MEMORY, + ComputeResource, LIMIT_REQUEST_RATIO_CPU, LIMIT_REQUEST_RATIO_MEMORY, + ResourceRequirementsExt, ResourceRequirementsType, }, }, kvp::Labels, @@ -558,7 +558,9 @@ impl PodBuilder { /// or [`Deployment`](`k8s_openapi::api::apps::v1::Deployment`) pub fn build_template(&self) -> PodTemplateSpec { if self.status.is_some() { - tracing::warn!("Tried building a PodTemplate for a PodBuilder with a status, the status will be ignored..."); + tracing::warn!( + "Tried building a PodTemplate for a PodBuilder with a status, the status will be ignored..." + ); } PodTemplateSpec { @@ -767,12 +769,11 @@ mod tests { .build() .unwrap(); - assert_eq!( - pod.spec.unwrap().image_pull_secrets.unwrap(), - vec![LocalObjectReference { + assert_eq!(pod.spec.unwrap().image_pull_secrets.unwrap(), vec![ + LocalObjectReference { name: "company-registry-secret".to_string() - }] - ); + } + ]); } #[rstest] diff --git a/crates/stackable-operator/src/builder/pod/security.rs b/crates/stackable-operator/src/builder/pod/security.rs index 72426cf05..fe33a933e 100644 --- a/crates/stackable-operator/src/builder/pod/security.rs +++ b/crates/stackable-operator/src/builder/pod/security.rs @@ -365,51 +365,48 @@ mod tests { .win_run_as_user_name("winuser") .build(); - assert_eq!( - context, - PodSecurityContext { - fs_group: Some(1000), - fs_group_change_policy: Some("policy".to_string()), - run_as_user: Some(1001), - run_as_group: Some(1001), - run_as_non_root: Some(true), - supplemental_groups: Some(vec![1002, 1003]), - se_linux_options: Some(SELinuxOptions { - level: Some("level".to_string()), - role: Some("role".to_string()), - type_: Some("type".to_string()), - user: Some("user".to_string()), - }), - seccomp_profile: Some(SeccompProfile { - localhost_profile: Some("localhost".to_string()), - type_: "type".to_string(), - }), - sysctls: Some(vec![ - Sysctl { - name: "param1".to_string(), - value: "value1".to_string(), - }, - Sysctl { - name: "param2".to_string(), - value: "value2".to_string(), - }, - ]), - windows_options: Some(WindowsSecurityContextOptions { - gmsa_credential_spec: Some("spec".to_string()), - gmsa_credential_spec_name: Some("name".to_string()), - run_as_user_name: Some("winuser".to_string()), - ..Default::default() - }), - // This attribute is supported starting with Kubernetes 1.30. - // Because we support older Kubernetes versions as well, we can - // not use it for now, as we would not work on older Kubernetes - // clusters. - app_armor_profile: None, - // This attribute is supported starting with Kubernetes 1.31. - supplemental_groups_policy: None, - // This attribute is supported starting with Kubernetes 1.32. - se_linux_change_policy: None, - } - ); + assert_eq!(context, PodSecurityContext { + fs_group: Some(1000), + fs_group_change_policy: Some("policy".to_string()), + run_as_user: Some(1001), + run_as_group: Some(1001), + run_as_non_root: Some(true), + supplemental_groups: Some(vec![1002, 1003]), + se_linux_options: Some(SELinuxOptions { + level: Some("level".to_string()), + role: Some("role".to_string()), + type_: Some("type".to_string()), + user: Some("user".to_string()), + }), + seccomp_profile: Some(SeccompProfile { + localhost_profile: Some("localhost".to_string()), + type_: "type".to_string(), + }), + sysctls: Some(vec![ + Sysctl { + name: "param1".to_string(), + value: "value1".to_string(), + }, + Sysctl { + name: "param2".to_string(), + value: "value2".to_string(), + }, + ]), + windows_options: Some(WindowsSecurityContextOptions { + gmsa_credential_spec: Some("spec".to_string()), + gmsa_credential_spec_name: Some("name".to_string()), + run_as_user_name: Some("winuser".to_string()), + ..Default::default() + }), + // This attribute is supported starting with Kubernetes 1.30. + // Because we support older Kubernetes versions as well, we can + // not use it for now, as we would not work on older Kubernetes + // clusters. + app_armor_profile: None, + // This attribute is supported starting with Kubernetes 1.31. + supplemental_groups_policy: None, + // This attribute is supported starting with Kubernetes 1.32. + se_linux_change_policy: None, + }); } } diff --git a/crates/stackable-operator/src/cli.rs b/crates/stackable-operator/src/cli.rs index 2a53184c1..a6b93acf1 100644 --- a/crates/stackable-operator/src/cli.rs +++ b/crates/stackable-operator/src/cli.rs @@ -366,13 +366,10 @@ mod tests { if let Err(Error::RequiredFileMissing { search_path }) = resolve_path(None, &[DEPLOY_FILE_PATH, DEFAULT_FILE_PATH]) { - assert_eq!( - search_path, - vec![ - PathBuf::from(DEPLOY_FILE_PATH), - PathBuf::from(DEFAULT_FILE_PATH) - ] - ) + assert_eq!(search_path, vec![ + PathBuf::from(DEPLOY_FILE_PATH), + PathBuf::from(DEFAULT_FILE_PATH) + ]) } else { panic!("must return RequiredFileMissing when file was not found") } @@ -381,7 +378,7 @@ mod tests { #[test] fn product_operator_run_watch_namespace() { // clean env var to not interfere if already set - env::remove_var(WATCH_NAMESPACE); + unsafe { env::remove_var(WATCH_NAMESPACE) }; // cli with namespace let opts = ProductOperatorRun::parse_from([ @@ -391,39 +388,30 @@ mod tests { "--watch-namespace", "foo", ]); - assert_eq!( - opts, - ProductOperatorRun { - product_config: ProductConfigPath::from("bar".as_ref()), - watch_namespace: WatchNamespace::One("foo".to_string()), - tracing_target: TracingTarget::None, - cluster_info_opts: Default::default(), - } - ); + assert_eq!(opts, ProductOperatorRun { + product_config: ProductConfigPath::from("bar".as_ref()), + watch_namespace: WatchNamespace::One("foo".to_string()), + tracing_target: TracingTarget::None, + cluster_info_opts: Default::default(), + }); // no cli / no env let opts = ProductOperatorRun::parse_from(["run", "--product-config", "bar"]); - assert_eq!( - opts, - ProductOperatorRun { - product_config: ProductConfigPath::from("bar".as_ref()), - watch_namespace: WatchNamespace::All, - tracing_target: TracingTarget::None, - cluster_info_opts: Default::default(), - } - ); + assert_eq!(opts, ProductOperatorRun { + product_config: ProductConfigPath::from("bar".as_ref()), + watch_namespace: WatchNamespace::All, + tracing_target: TracingTarget::None, + cluster_info_opts: Default::default(), + }); // env with namespace - env::set_var(WATCH_NAMESPACE, "foo"); + unsafe { env::set_var(WATCH_NAMESPACE, "foo") }; let opts = ProductOperatorRun::parse_from(["run", "--product-config", "bar"]); - assert_eq!( - opts, - ProductOperatorRun { - product_config: ProductConfigPath::from("bar".as_ref()), - watch_namespace: WatchNamespace::One("foo".to_string()), - tracing_target: TracingTarget::None, - cluster_info_opts: Default::default(), - } - ); + assert_eq!(opts, ProductOperatorRun { + product_config: ProductConfigPath::from("bar".as_ref()), + watch_namespace: WatchNamespace::One("foo".to_string()), + tracing_target: TracingTarget::None, + cluster_info_opts: Default::default(), + }); } } diff --git a/crates/stackable-operator/src/client.rs b/crates/stackable-operator/src/client.rs index 594c06af2..5a9ded61d 100644 --- a/crates/stackable-operator/src/client.rs +++ b/crates/stackable-operator/src/client.rs @@ -6,16 +6,16 @@ use std::{ use either::Either; use futures::StreamExt; use k8s_openapi::{ - apimachinery::pkg::apis::meta::v1::LabelSelector, ClusterResourceScope, NamespaceResourceScope, + ClusterResourceScope, NamespaceResourceScope, apimachinery::pkg::apis::meta::v1::LabelSelector, }; use kube::{ + Api, Config, api::{DeleteParams, ListParams, Patch, PatchParams, PostParams, Resource, ResourceExt}, client::Client as KubeClient, core::Status, - runtime::{wait::delete::delete_and_finalize, watcher, WatchStreamExt}, - Api, Config, + runtime::{WatchStreamExt, wait::delete::delete_and_finalize, watcher}, }; -use serde::{de::DeserializeOwned, Serialize}; +use serde::{Serialize, de::DeserializeOwned}; use snafu::{OptionExt, ResultExt, Snafu}; use tracing::trace; diff --git a/crates/stackable-operator/src/cluster_resources.rs b/crates/stackable-operator/src/cluster_resources.rs index 937c2f1df..44daa3c4e 100644 --- a/crates/stackable-operator/src/cluster_resources.rs +++ b/crates/stackable-operator/src/cluster_resources.rs @@ -8,6 +8,7 @@ use std::{ #[cfg(doc)] use k8s_openapi::api::core::v1::{NodeSelector, Pod}; use k8s_openapi::{ + NamespaceResourceScope, api::{ apps::v1::{ DaemonSet, DaemonSetSpec, Deployment, DeploymentSpec, StatefulSet, StatefulSetSpec, @@ -20,10 +21,9 @@ use k8s_openapi::{ rbac::v1::RoleBinding, }, apimachinery::pkg::apis::meta::v1::{LabelSelector, LabelSelectorRequirement}, - NamespaceResourceScope, }; -use kube::{core::ErrorResponse, Resource, ResourceExt}; -use serde::{de::DeserializeOwned, Serialize}; +use kube::{Resource, ResourceExt, core::ErrorResponse}; +use serde::{Serialize, de::DeserializeOwned}; use snafu::{OptionExt, ResultExt, Snafu}; use strum::Display; use tracing::{debug, info, warn}; @@ -34,13 +34,13 @@ use crate::{ cluster_operation::ClusterOperation, listener::Listener, resources::{ - ComputeResource, ResourceRequirementsExt, ResourceRequirementsType, - LIMIT_REQUEST_RATIO_CPU, LIMIT_REQUEST_RATIO_MEMORY, + ComputeResource, LIMIT_REQUEST_RATIO_CPU, LIMIT_REQUEST_RATIO_MEMORY, + ResourceRequirementsExt, ResourceRequirementsType, }, }, kvp::{ - consts::{K8S_APP_INSTANCE_KEY, K8S_APP_MANAGED_BY_KEY, K8S_APP_NAME_KEY}, Label, LabelError, Labels, + consts::{K8S_APP_INSTANCE_KEY, K8S_APP_MANAGED_BY_KEY, K8S_APP_NAME_KEY}, }, utils::format_full_controller_name, }; @@ -58,7 +58,9 @@ pub enum Error { #[snafu(display("label {label:?} is missing"))] MissingLabel { label: &'static str }, - #[snafu(display("label {label:?} contains unexpected values - expected {expected_content:?}, got {actual_content:?}"))] + #[snafu(display( + "label {label:?} contains unexpected values - expected {expected_content:?}, got {actual_content:?}" + ))] UnexpectedLabelContent { label: &'static str, expected_content: String, diff --git a/crates/stackable-operator/src/commons/affinity.rs b/crates/stackable-operator/src/commons/affinity.rs index 188b366a9..78289e07e 100644 --- a/crates/stackable-operator/src/commons/affinity.rs +++ b/crates/stackable-operator/src/commons/affinity.rs @@ -183,73 +183,68 @@ mod tests { role_affinity.merge(&default_affinity); let merged_affinity: StackableAffinity = fragment::validate(role_affinity).unwrap(); - assert_eq!( - merged_affinity, - StackableAffinity { - pod_affinity: Some(PodAffinity { - preferred_during_scheduling_ignored_during_execution: None, - required_during_scheduling_ignored_during_execution: Some(vec![ - PodAffinityTerm { + assert_eq!(merged_affinity, StackableAffinity { + pod_affinity: Some(PodAffinity { + preferred_during_scheduling_ignored_during_execution: None, + required_during_scheduling_ignored_during_execution: Some(vec![PodAffinityTerm { + label_selector: Some(LabelSelector { + match_expressions: Some(vec![LabelSelectorRequirement { + key: "app.kubernetes.io/name".to_string(), + operator: "In".to_string(), + values: Some(vec!["foo".to_string(), "bar".to_string()]) + }]), + match_labels: None, + }), + topology_key: "".to_string(), + ..Default::default() + }]) + }), + pod_anti_affinity: Some(PodAntiAffinity { + preferred_during_scheduling_ignored_during_execution: Some(vec![ + WeightedPodAffinityTerm { + pod_affinity_term: PodAffinityTerm { label_selector: Some(LabelSelector { - match_expressions: Some(vec![LabelSelectorRequirement { - key: "app.kubernetes.io/name".to_string(), - operator: "In".to_string(), - values: Some(vec!["foo".to_string(), "bar".to_string()]) - }]), - match_labels: None, + match_expressions: None, + match_labels: Some(BTreeMap::from([ + ("app.kubernetes.io/name".to_string(), "kafka".to_string(),), + ( + "app.kubernetes.io/instance".to_string(), + "simple-kafka".to_string(), + ), + ( + "app.kubernetes.io/component".to_string(), + "broker".to_string(), + ) + ])) }), - topology_key: "".to_string(), + topology_key: TOPOLOGY_KEY_HOSTNAME.to_string(), ..Default::default() - } - ]) - }), - pod_anti_affinity: Some(PodAntiAffinity { - preferred_during_scheduling_ignored_during_execution: Some(vec![ - WeightedPodAffinityTerm { - pod_affinity_term: PodAffinityTerm { - label_selector: Some(LabelSelector { - match_expressions: None, - match_labels: Some(BTreeMap::from([ - ("app.kubernetes.io/name".to_string(), "kafka".to_string(),), - ( - "app.kubernetes.io/instance".to_string(), - "simple-kafka".to_string(), - ), - ( - "app.kubernetes.io/component".to_string(), - "broker".to_string(), - ) - ])) - }), - topology_key: TOPOLOGY_KEY_HOSTNAME.to_string(), - ..Default::default() - }, - weight: 70 - } - ]), - required_during_scheduling_ignored_during_execution: None, - }), - node_affinity: Some(NodeAffinity { - preferred_during_scheduling_ignored_during_execution: None, - required_during_scheduling_ignored_during_execution: Some(NodeSelector { - node_selector_terms: vec![NodeSelectorTerm { - match_expressions: Some(vec![NodeSelectorRequirement { - key: "topology.kubernetes.io/zone".to_string(), - operator: "In".to_string(), - values: Some(vec![ - "antarctica-east1".to_string(), - "antarctica-west1".to_string() - ]), - }]), - match_fields: None, - }] - }), - }), - node_selector: Some(StackableNodeSelector { - node_selector: BTreeMap::from([("disktype".to_string(), "ssd".to_string())]) + }, + weight: 70 + } + ]), + required_during_scheduling_ignored_during_execution: None, + }), + node_affinity: Some(NodeAffinity { + preferred_during_scheduling_ignored_during_execution: None, + required_during_scheduling_ignored_during_execution: Some(NodeSelector { + node_selector_terms: vec![NodeSelectorTerm { + match_expressions: Some(vec![NodeSelectorRequirement { + key: "topology.kubernetes.io/zone".to_string(), + operator: "In".to_string(), + values: Some(vec![ + "antarctica-east1".to_string(), + "antarctica-west1".to_string() + ]), + }]), + match_fields: None, + }] }), - } - ); + }), + node_selector: Some(StackableNodeSelector { + node_selector: BTreeMap::from([("disktype".to_string(), "ssd".to_string())]) + }), + }); } #[test] @@ -284,50 +279,11 @@ mod tests { role_affinity.merge(&default_affinity); let merged_affinity: StackableAffinity = fragment::validate(role_affinity).unwrap(); - assert_eq!( - merged_affinity, - StackableAffinity { - pod_affinity: None, - pod_anti_affinity: Some(PodAntiAffinity { - preferred_during_scheduling_ignored_during_execution: None, - required_during_scheduling_ignored_during_execution: Some(vec![ - PodAffinityTerm { - label_selector: Some(LabelSelector { - match_expressions: None, - match_labels: Some(BTreeMap::from([ - ("app.kubernetes.io/name".to_string(), "kafka".to_string(),), - ( - "app.kubernetes.io/instance".to_string(), - "simple-kafka".to_string(), - ), - ( - "app.kubernetes.io/component".to_string(), - "broker".to_string(), - ) - ])) - }), - topology_key: "topology.kubernetes.io/zone".to_string(), - ..Default::default() - } - ]), - }), - node_affinity: None, - node_selector: None, - } - ); - } - - #[test] - fn between_role_pods() { - let app_name = "kafka"; - let cluster_name = "simple-kafka"; - let role = "broker"; - - let anti_affinity = affinity_between_role_pods(app_name, cluster_name, role, 70); - assert_eq!( - anti_affinity, - WeightedPodAffinityTerm { - pod_affinity_term: PodAffinityTerm { + assert_eq!(merged_affinity, StackableAffinity { + pod_affinity: None, + pod_anti_affinity: Some(PodAntiAffinity { + preferred_during_scheduling_ignored_during_execution: None, + required_during_scheduling_ignored_during_execution: Some(vec![PodAffinityTerm { label_selector: Some(LabelSelector { match_expressions: None, match_labels: Some(BTreeMap::from([ @@ -342,12 +298,43 @@ mod tests { ) ])) }), - topology_key: TOPOLOGY_KEY_HOSTNAME.to_string(), + topology_key: "topology.kubernetes.io/zone".to_string(), ..Default::default() - }, - weight: 70 - } - ); + }]), + }), + node_affinity: None, + node_selector: None, + }); + } + + #[test] + fn between_role_pods() { + let app_name = "kafka"; + let cluster_name = "simple-kafka"; + let role = "broker"; + + let anti_affinity = affinity_between_role_pods(app_name, cluster_name, role, 70); + assert_eq!(anti_affinity, WeightedPodAffinityTerm { + pod_affinity_term: PodAffinityTerm { + label_selector: Some(LabelSelector { + match_expressions: None, + match_labels: Some(BTreeMap::from([ + ("app.kubernetes.io/name".to_string(), "kafka".to_string(),), + ( + "app.kubernetes.io/instance".to_string(), + "simple-kafka".to_string(), + ), + ( + "app.kubernetes.io/component".to_string(), + "broker".to_string(), + ) + ])) + }), + topology_key: TOPOLOGY_KEY_HOSTNAME.to_string(), + ..Default::default() + }, + weight: 70 + }); } #[test] @@ -356,25 +343,22 @@ mod tests { let cluster_name = "simple-kafka"; let anti_affinity = affinity_between_cluster_pods(app_name, cluster_name, 20); - assert_eq!( - anti_affinity, - WeightedPodAffinityTerm { - pod_affinity_term: PodAffinityTerm { - label_selector: Some(LabelSelector { - match_expressions: None, - match_labels: Some(BTreeMap::from([ - ("app.kubernetes.io/name".to_string(), "kafka".to_string(),), - ( - "app.kubernetes.io/instance".to_string(), - "simple-kafka".to_string(), - ) - ])) - }), - topology_key: TOPOLOGY_KEY_HOSTNAME.to_string(), - ..Default::default() - }, - weight: 20 - } - ); + assert_eq!(anti_affinity, WeightedPodAffinityTerm { + pod_affinity_term: PodAffinityTerm { + label_selector: Some(LabelSelector { + match_expressions: None, + match_labels: Some(BTreeMap::from([ + ("app.kubernetes.io/name".to_string(), "kafka".to_string(),), + ( + "app.kubernetes.io/instance".to_string(), + "simple-kafka".to_string(), + ) + ])) + }), + topology_key: TOPOLOGY_KEY_HOSTNAME.to_string(), + ..Default::default() + }, + weight: 20 + }); } } diff --git a/crates/stackable-operator/src/commons/authentication/ldap.rs b/crates/stackable-operator/src/commons/authentication/ldap.rs index 2657c05e4..676c27d7b 100644 --- a/crates/stackable-operator/src/commons/authentication/ldap.rs +++ b/crates/stackable-operator/src/commons/authentication/ldap.rs @@ -7,7 +7,7 @@ use url::{ParseError, Url}; use crate::{ builder::{ self, - pod::{container::ContainerBuilder, volume::VolumeMountBuilder, PodBuilder}, + pod::{PodBuilder, container::ContainerBuilder, volume::VolumeMountBuilder}, }, commons::{ authentication::SECRET_BASE_PATH, @@ -286,23 +286,18 @@ mod tests { ); let (tls_volumes, tls_mounts) = ldap.tls.volumes_and_mounts().unwrap(); - assert_eq!( - tls_volumes, - vec![SecretClassVolume { + assert_eq!(tls_volumes, vec![ + SecretClassVolume { secret_class: "ldap-ca-cert".to_string(), scope: None, } .to_volume("ldap-ca-cert-ca-cert") - .unwrap()] - ); - assert_eq!( - tls_mounts, - vec![VolumeMountBuilder::new( - "ldap-ca-cert-ca-cert", - "/stackable/secrets/ldap-ca-cert" - ) - .build()] - ); + .unwrap() + ]); + assert_eq!(tls_mounts, vec![ + VolumeMountBuilder::new("ldap-ca-cert-ca-cert", "/stackable/secrets/ldap-ca-cert") + .build() + ]); assert!(ldap.has_bind_credentials()); assert_eq!( @@ -314,34 +309,28 @@ mod tests { ); let (ldap_volumes, ldap_mounts) = ldap.volumes_and_mounts().unwrap(); - assert_eq!( - ldap_volumes, - vec![ - SecretClassVolume { - secret_class: "openldap-bind-credentials".to_string(), - scope: None, - } - .to_volume("openldap-bind-credentials-bind-credentials") - .unwrap(), - SecretClassVolume { - secret_class: "ldap-ca-cert".to_string(), - scope: None, - } - .to_volume("ldap-ca-cert-ca-cert") - .unwrap() - ] - ); - assert_eq!( - ldap_mounts, - vec![ - VolumeMountBuilder::new( - "openldap-bind-credentials-bind-credentials", - "/stackable/secrets/openldap-bind-credentials" - ) - .build(), - VolumeMountBuilder::new("ldap-ca-cert-ca-cert", "/stackable/secrets/ldap-ca-cert") - .build() - ] - ); + assert_eq!(ldap_volumes, vec![ + SecretClassVolume { + secret_class: "openldap-bind-credentials".to_string(), + scope: None, + } + .to_volume("openldap-bind-credentials-bind-credentials") + .unwrap(), + SecretClassVolume { + secret_class: "ldap-ca-cert".to_string(), + scope: None, + } + .to_volume("ldap-ca-cert-ca-cert") + .unwrap() + ]); + assert_eq!(ldap_mounts, vec![ + VolumeMountBuilder::new( + "openldap-bind-credentials-bind-credentials", + "/stackable/secrets/openldap-bind-credentials" + ) + .build(), + VolumeMountBuilder::new("ldap-ca-cert-ca-cert", "/stackable/secrets/ldap-ca-cert") + .build() + ]); } } diff --git a/crates/stackable-operator/src/commons/authentication/mod.rs b/crates/stackable-operator/src/commons/authentication/mod.rs index bf5563b92..e462b28e1 100644 --- a/crates/stackable-operator/src/commons/authentication/mod.rs +++ b/crates/stackable-operator/src/commons/authentication/mod.rs @@ -18,7 +18,9 @@ type Result = std::result::Result; #[derive(Debug, PartialEq, Snafu)] pub enum Error { - #[snafu(display("authentication details for OIDC were not specified. The AuthenticationClass {auth_class_name:?} uses an OIDC provider, you need to specify OIDC authentication details (such as client credentials) as well"))] + #[snafu(display( + "authentication details for OIDC were not specified. The AuthenticationClass {auth_class_name:?} uses an OIDC provider, you need to specify OIDC authentication details (such as client credentials) as well" + ))] OidcAuthenticationDetailsNotSpecified { auth_class_name: String }, } @@ -180,7 +182,7 @@ impl ClientAuthenticationDetails { #[cfg(test)] mod tests { use crate::commons::authentication::{ - tls::AuthenticationProvider, AuthenticationClassProvider, + AuthenticationClassProvider, tls::AuthenticationProvider, }; #[test] diff --git a/crates/stackable-operator/src/commons/networking.rs b/crates/stackable-operator/src/commons/networking.rs index 1dd1079d9..742065764 100644 --- a/crates/stackable-operator/src/commons/networking.rs +++ b/crates/stackable-operator/src/commons/networking.rs @@ -79,8 +79,8 @@ impl JsonSchema for HostName { "HostName".to_owned() } - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - String::json_schema(gen) + fn json_schema(generator: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema { + String::json_schema(generator) } } diff --git a/crates/stackable-operator/src/commons/opa.rs b/crates/stackable-operator/src/commons/opa.rs index 1adb11f8c..2eaa6044a 100644 --- a/crates/stackable-operator/src/commons/opa.rs +++ b/crates/stackable-operator/src/commons/opa.rs @@ -45,7 +45,7 @@ //! ``` use std::sync::LazyLock; -use k8s_openapi::{api::core::v1::ConfigMap, NamespaceResourceScope}; +use k8s_openapi::{NamespaceResourceScope, api::core::v1::ConfigMap}; use kube::{Resource, ResourceExt}; use regex::Regex; use schemars::{self, JsonSchema}; diff --git a/crates/stackable-operator/src/commons/resources.rs b/crates/stackable-operator/src/commons/resources.rs index e25bdf856..eb6f1361c 100644 --- a/crates/stackable-operator/src/commons/resources.rs +++ b/crates/stackable-operator/src/commons/resources.rs @@ -111,7 +111,9 @@ pub enum Error { resource_type: ResourceRequirementsType, }, - #[snafu(display("{resource_key:?} max limit to request ratio for Container {container_name:?} is {allowed_ration:?}, but ratio was exceeded or request and limit where not set explicitly"))] + #[snafu(display( + "{resource_key:?} max limit to request ratio for Container {container_name:?} is {allowed_ration:?}, but ratio was exceeded or request and limit where not set explicitly" + ))] LimitToRequestRatioExceeded { container_name: String, resource_key: String, diff --git a/crates/stackable-operator/src/commons/s3/helpers.rs b/crates/stackable-operator/src/commons/s3/helpers.rs index 1cb13eac3..97efc1919 100644 --- a/crates/stackable-operator/src/commons/s3/helpers.rs +++ b/crates/stackable-operator/src/commons/s3/helpers.rs @@ -5,7 +5,7 @@ use snafu::ResultExt; use url::Url; use crate::{ - builder::pod::{container::ContainerBuilder, volume::VolumeMountBuilder, PodBuilder}, + builder::pod::{PodBuilder, container::ContainerBuilder, volume::VolumeMountBuilder}, client::Client, commons::{ authentication::SECRET_BASE_PATH, diff --git a/crates/stackable-operator/src/commons/tls_verification.rs b/crates/stackable-operator/src/commons/tls_verification.rs index 0123a6bad..47a17c751 100644 --- a/crates/stackable-operator/src/commons/tls_verification.rs +++ b/crates/stackable-operator/src/commons/tls_verification.rs @@ -6,7 +6,7 @@ use snafu::{ResultExt, Snafu}; use crate::{ builder::{ self, - pod::{container::ContainerBuilder, volume::VolumeMountBuilder, PodBuilder}, + pod::{PodBuilder, container::ContainerBuilder, volume::VolumeMountBuilder}, }, commons::{ authentication::SECRET_BASE_PATH, diff --git a/crates/stackable-operator/src/config/fragment.rs b/crates/stackable-operator/src/config/fragment.rs index 64c1ab968..9fd3b14c3 100644 --- a/crates/stackable-operator/src/config/fragment.rs +++ b/crates/stackable-operator/src/config/fragment.rs @@ -207,20 +207,17 @@ impl FromFragment for PodTemplateSpec { /// /// When validating a [`RoleGroup`]'s configuration, consider using [`RoleGroup::validate_config`] instead. pub fn validate(fragment: T::Fragment) -> Result { - T::from_fragment( - fragment, - Validator { - ident: None, - parent: None, - }, - ) + T::from_fragment(fragment, Validator { + ident: None, + parent: None, + }) } #[cfg(test)] mod tests { - use schemars::{schema_for, JsonSchema}; + use schemars::{JsonSchema, schema_for}; - use super::{validate, Fragment}; + use super::{Fragment, validate}; #[derive(Fragment, Debug, PartialEq, Eq)] #[fragment(path_overrides(fragment = "super"))] diff --git a/crates/stackable-operator/src/config/merge.rs b/crates/stackable-operator/src/config/merge.rs index 7c67e7986..be1c137ef 100644 --- a/crates/stackable-operator/src/config/merge.rs +++ b/crates/stackable-operator/src/config/merge.rs @@ -1,14 +1,14 @@ //! Automatically merges objects *deeply*, especially fragments. use std::{ - collections::{btree_map, hash_map, BTreeMap, HashMap}, + collections::{BTreeMap, HashMap, btree_map, hash_map}, hash::Hash, }; use k8s_openapi::{ + DeepMerge, api::core::v1::{NodeAffinity, PodAffinity, PodAntiAffinity, PodTemplateSpec}, apimachinery::pkg::{api::resource::Quantity, apis::meta::v1::LabelSelector}, - DeepMerge, }; pub use stackable_operator_derive::Merge; @@ -166,7 +166,7 @@ mod tests { use k8s_openapi::api::core::v1::{PodSpec, PodTemplateSpec}; - use super::{merge, Merge}; + use super::{Merge, merge}; #[derive(Debug, PartialEq, Eq, Clone)] struct Accumulator(u8); diff --git a/crates/stackable-operator/src/config/mod.rs b/crates/stackable-operator/src/config/mod.rs index 3cbb464e9..9c17f6048 100644 --- a/crates/stackable-operator/src/config/mod.rs +++ b/crates/stackable-operator/src/config/mod.rs @@ -166,7 +166,7 @@ pub mod fragment; pub mod merge; #[cfg(doc)] -use fragment::{validate, Fragment, FromFragment}; +use fragment::{Fragment, FromFragment, validate}; #[cfg(doc)] use merge::{Atomic, Merge}; diff --git a/crates/stackable-operator/src/cpu.rs b/crates/stackable-operator/src/cpu.rs index 1ee5735a6..5af279daa 100644 --- a/crates/stackable-operator/src/cpu.rs +++ b/crates/stackable-operator/src/cpu.rs @@ -6,14 +6,16 @@ use std::{ }; use k8s_openapi::apimachinery::pkg::api::resource::Quantity; -use serde::{de::Visitor, Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Visitor}; use snafu::{ResultExt, Snafu}; pub type Result = std::result::Result; #[derive(Debug, PartialEq, Snafu)] pub enum Error { - #[snafu(display("unsupported precision {value:?}. Kubernetes doesn't allow you to specify CPU resources with a precision finer than 1m. Because of this, it's useful to specify CPU units less than 1.0 or 1000m using the milliCPU form; for example, 5m rather than 0.005"))] + #[snafu(display( + "unsupported precision {value:?}. Kubernetes doesn't allow you to specify CPU resources with a precision finer than 1m. Because of this, it's useful to specify CPU units less than 1.0 or 1000m using the milliCPU form; for example, 5m rather than 0.005" + ))] UnsupportedCpuQuantityPrecision { value: String }, #[snafu(display("invalid cpu integer quantity {value:?}"))] diff --git a/crates/stackable-operator/src/helm/mod.rs b/crates/stackable-operator/src/helm/mod.rs index 5c3d551ea..93582fd2a 100644 --- a/crates/stackable-operator/src/helm/mod.rs +++ b/crates/stackable-operator/src/helm/mod.rs @@ -78,7 +78,7 @@ mod tests { use std::path::PathBuf; use rstest::rstest; - use stackable_shared::yaml::{serialize as ser, SerializeOptions}; + use stackable_shared::yaml::{SerializeOptions, serialize as ser}; use super::*; diff --git a/crates/stackable-operator/src/iter.rs b/crates/stackable-operator/src/iter.rs index e6911e081..b3e0f7f44 100644 --- a/crates/stackable-operator/src/iter.rs +++ b/crates/stackable-operator/src/iter.rs @@ -110,14 +110,12 @@ mod tests { #[test] fn reverse_if_marble_test() { let values = [0, 1, 2, 3]; - assert_eq!( - reverse_if(false, values.iter()).collect::>(), - [&0, &1, &2, &3] - ); - assert_eq!( - reverse_if(true, values.iter()).collect::>(), - [&3, &2, &1, &0] - ); + assert_eq!(reverse_if(false, values.iter()).collect::>(), [ + &0, &1, &2, &3 + ]); + assert_eq!(reverse_if(true, values.iter()).collect::>(), [ + &3, &2, &1, &0 + ]); } #[test] @@ -128,10 +126,14 @@ mod tests { Err(5), Ok(vec![Ok(6)]), ]; - assert_eq!( - try_flatten(stream).collect::>(), - vec![Ok(1), Err(2), Ok(3), Err(4), Err(5), Ok(6)], - ); + assert_eq!(try_flatten(stream).collect::>(), vec![ + Ok(1), + Err(2), + Ok(3), + Err(4), + Err(5), + Ok(6) + ],); } #[test] diff --git a/crates/stackable-operator/src/kvp/key.rs b/crates/stackable-operator/src/kvp/key.rs index 6275689bd..c82790905 100644 --- a/crates/stackable-operator/src/kvp/key.rs +++ b/crates/stackable-operator/src/kvp/key.rs @@ -1,7 +1,7 @@ use std::{fmt::Display, ops::Deref, str::FromStr, sync::LazyLock}; use regex::Regex; -use snafu::{ensure, ResultExt, Snafu}; +use snafu::{ResultExt, Snafu, ensure}; const KEY_PREFIX_MAX_LEN: usize = 253; const KEY_NAME_MAX_LEN: usize = 63; @@ -183,7 +183,9 @@ pub enum KeyPrefixError { /// Indicates that the key prefix segment exceeds the mamximum length of /// 253 ASCII characters. It additionally reports how many characters were /// encountered during parsing / validation. - #[snafu(display("prefix segment of key exceeds the maximum length - expected 253 characters or less, got {length}"))] + #[snafu(display( + "prefix segment of key exceeds the maximum length - expected 253 characters or less, got {length}" + ))] PrefixTooLong { length: usize }, /// Indidcates that the key prefix segment contains non-ASCII characters @@ -214,12 +216,9 @@ impl FromStr for KeyPrefix { ensure!(!input.is_empty(), PrefixEmptySnafu); // The length of the prefix cannot exceed 253 characters - ensure!( - input.len() <= KEY_PREFIX_MAX_LEN, - PrefixTooLongSnafu { - length: input.len() - } - ); + ensure!(input.len() <= KEY_PREFIX_MAX_LEN, PrefixTooLongSnafu { + length: input.len() + }); // The prefix cannot contain non-ascii characters ensure!(input.is_ascii(), PrefixNotAsciiSnafu); @@ -265,7 +264,9 @@ pub enum KeyNameError { /// Indicates that the key name sgement exceeds the maximum length of 63 /// ASCII characters. It additionally reports how many characters were /// encountered during parsing / validation. - #[snafu(display("name segment of key exceeds the maximum length - expected 63 characters or less, got {length}"))] + #[snafu(display( + "name segment of key exceeds the maximum length - expected 63 characters or less, got {length}" + ))] NameTooLong { length: usize }, /// Indidcates that the key name segment contains non-ASCII characters @@ -296,12 +297,9 @@ impl FromStr for KeyName { ensure!(!input.is_empty(), NameEmptySnafu); // The length of the name cannot exceed 63 characters - ensure!( - input.len() <= KEY_NAME_MAX_LEN, - NameTooLongSnafu { - length: input.len() - } - ); + ensure!(input.len() <= KEY_NAME_MAX_LEN, NameTooLongSnafu { + length: input.len() + }); // The name cannot contain non-ascii characters ensure!(input.is_ascii(), NameNotAsciiSnafu); diff --git a/crates/stackable-operator/src/kvp/label/mod.rs b/crates/stackable-operator/src/kvp/label/mod.rs index 5aa74ca5a..15411a198 100644 --- a/crates/stackable-operator/src/kvp/label/mod.rs +++ b/crates/stackable-operator/src/kvp/label/mod.rs @@ -20,12 +20,12 @@ use kube::{Resource, ResourceExt}; use crate::{ iter::TryFromIterator, kvp::{ + Key, KeyValuePair, KeyValuePairError, KeyValuePairs, KeyValuePairsError, ObjectLabels, consts::{ K8S_APP_COMPONENT_KEY, K8S_APP_INSTANCE_KEY, K8S_APP_MANAGED_BY_KEY, K8S_APP_NAME_KEY, K8S_APP_ROLE_GROUP_KEY, K8S_APP_VERSION_KEY, STACKABLE_VENDOR_KEY, STACKABLE_VENDOR_VALUE, }, - Key, KeyValuePair, KeyValuePairError, KeyValuePairs, KeyValuePairsError, ObjectLabels, }, utils::format_full_controller_name, }; diff --git a/crates/stackable-operator/src/kvp/label/value.rs b/crates/stackable-operator/src/kvp/label/value.rs index e47ef2db4..0220a1b58 100644 --- a/crates/stackable-operator/src/kvp/label/value.rs +++ b/crates/stackable-operator/src/kvp/label/value.rs @@ -1,7 +1,7 @@ use std::{fmt::Display, ops::Deref, str::FromStr, sync::LazyLock}; use regex::Regex; -use snafu::{ensure, Snafu}; +use snafu::{Snafu, ensure}; use crate::kvp::Value; @@ -56,12 +56,9 @@ impl FromStr for LabelValue { fn from_str(input: &str) -> Result { // The length of the value cannot exceed 63 characters, but can be // empty - ensure!( - input.len() <= LABEL_VALUE_MAX_LEN, - ValueTooLongSnafu { - length: input.len() - } - ); + ensure!(input.len() <= LABEL_VALUE_MAX_LEN, ValueTooLongSnafu { + length: input.len() + }); // The value cannot contain non-ascii characters ensure!(input.is_ascii(), ValueNotAsciiSnafu); diff --git a/crates/stackable-operator/src/kvp/mod.rs b/crates/stackable-operator/src/kvp/mod.rs index 45c9379bb..f5aab1b83 100644 --- a/crates/stackable-operator/src/kvp/mod.rs +++ b/crates/stackable-operator/src/kvp/mod.rs @@ -7,7 +7,7 @@ use std::{ str::FromStr, }; -use snafu::{ensure, ResultExt, Snafu}; +use snafu::{ResultExt, Snafu, ensure}; use crate::iter::TryFromIterator; diff --git a/crates/stackable-operator/src/logging/controller.rs b/crates/stackable-operator/src/logging/controller.rs index bec0f0173..31a3d4d19 100644 --- a/crates/stackable-operator/src/logging/controller.rs +++ b/crates/stackable-operator/src/logging/controller.rs @@ -5,13 +5,13 @@ use std::error::Error; use kube::{ + Resource, core::DynamicObject, runtime::{ controller::{self, Action}, events::Recorder, reflector::ObjectRef, }, - Resource, }; use tracing; diff --git a/crates/stackable-operator/src/logging/k8s_events.rs b/crates/stackable-operator/src/logging/k8s_events.rs index a4f3f392c..874998df5 100644 --- a/crates/stackable-operator/src/logging/k8s_events.rs +++ b/crates/stackable-operator/src/logging/k8s_events.rs @@ -141,7 +141,7 @@ mod tests { use snafu::Snafu; use strum::EnumDiscriminants; - use super::{error_to_event, ReconcilerError}; + use super::{ReconcilerError, error_to_event}; #[derive(Snafu, Debug, EnumDiscriminants)] #[strum_discriminants(derive(strum::IntoStaticStr))] diff --git a/crates/stackable-operator/src/logging/mod.rs b/crates/stackable-operator/src/logging/mod.rs index 6f6678838..7b08643fe 100644 --- a/crates/stackable-operator/src/logging/mod.rs +++ b/crates/stackable-operator/src/logging/mod.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use tracing; use tracing_appender::rolling::{RollingFileAppender, Rotation}; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry}; +use tracing_subscriber::{EnvFilter, Registry, layer::SubscriberExt, util::SubscriberInitExt}; pub mod controller; mod k8s_events; diff --git a/crates/stackable-operator/src/memory.rs b/crates/stackable-operator/src/memory.rs index c5124db88..09226a9e7 100644 --- a/crates/stackable-operator/src/memory.rs +++ b/crates/stackable-operator/src/memory.rs @@ -16,7 +16,7 @@ use std::{ }; use k8s_openapi::apimachinery::pkg::api::resource::Quantity; -use serde::{de::Visitor, Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Visitor}; use snafu::{OptionExt, ResultExt, Snafu}; pub type Result = std::result::Result; diff --git a/crates/stackable-operator/src/product_config_utils.rs b/crates/stackable-operator/src/product_config_utils.rs index 2063c709a..cf6ea8709 100644 --- a/crates/stackable-operator/src/product_config_utils.rs +++ b/crates/stackable-operator/src/product_config_utils.rs @@ -1,6 +1,6 @@ use std::collections::{BTreeMap, HashMap}; -use product_config::{types::PropertyNameKind, ProductConfigManager, PropertyValidationResult}; +use product_config::{ProductConfigManager, PropertyValidationResult, types::PropertyNameKind}; use schemars::JsonSchema; use serde::Serialize; use snafu::{ResultExt, Snafu}; @@ -28,7 +28,9 @@ pub enum Error { #[snafu(display("missing role {role:?}. This should not happen. Will requeue."))] MissingRole { role: String }, - #[snafu(display("missing roleGroup {role_group:?} for role {role:?}. This might happen after custom resource changes. Will requeue."))] + #[snafu(display( + "missing roleGroup {role_group:?} for role {role:?}. This might happen after custom resource changes. Will requeue." + ))] MissingRoleGroup { role: String, role_group: String }, // We need this for product specific errors that implement the Configuration trait and are not related to the @@ -140,7 +142,7 @@ pub fn config_for_role_and_group<'a>( return MissingRoleSnafu { role: role.to_string(), } - .fail() + .fail(); } Some(group_config) => match group_config.get(group) { None => { @@ -148,7 +150,7 @@ pub fn config_for_role_and_group<'a>( role: role.to_string(), role_group: group.to_string(), } - .fail() + .fail(); } Some(config_by_property_kind) => config_by_property_kind, }, @@ -304,7 +306,10 @@ fn process_validation_result( for (key, result) in validation_result.iter() { match result { PropertyValidationResult::Default(value) => { - debug!("Property [{}] is not explicitly set, will set and rely to the default instead ([{}])", key, value); + debug!( + "Property [{}] is not explicitly set, will set and rely to the default instead ([{}])", + key, value + ); properties.insert(key.clone(), value.clone()); } PropertyValidationResult::RecommendedDefault(value) => { @@ -326,13 +331,19 @@ fn process_validation_result( properties.insert(key.clone(), value.clone()); } PropertyValidationResult::Warn(value, err) => { - warn!("Property [{}] is set to value [{}] which causes a warning, `ignore_warn` is {}: {:?}", key, value, ignore_warn, err); + warn!( + "Property [{}] is set to value [{}] which causes a warning, `ignore_warn` is {}: {:?}", + key, value, ignore_warn, err + ); if ignore_warn { properties.insert(key.clone(), value.clone()); } } PropertyValidationResult::Error(value, err) => { - error!("Property [{}] is set to value [{}] which causes an error, `ignore_err` is {}: {:?}", key, value, ignore_err, err); + error!( + "Property [{}] is set to value [{}] which causes an error, `ignore_err` is {}: {:?}", + key, value, ignore_err, err + ); if ignore_err { properties.insert(key.clone(), value.clone()); } else { @@ -521,11 +532,11 @@ where mod tests { macro_rules! collection { // map-like - ($($k:expr => $v:expr),* $(,)?) => { + ($($k:expr_2021 => $v:expr_2021),* $(,)?) => { [$(($k, $v),)*].into() }; // set-like - ($($v:expr),* $(,)?) => { + ($($v:expr_2021),* $(,)?) => { [$($v,)*].into() }; } diff --git a/crates/stackable-operator/src/product_logging/framework.rs b/crates/stackable-operator/src/product_logging/framework.rs index 4d946609b..3aebc47ae 100644 --- a/crates/stackable-operator/src/product_logging/framework.rs +++ b/crates/stackable-operator/src/product_logging/framework.rs @@ -1555,12 +1555,9 @@ mod tests { #[test] fn log4j2_config() { let log_config = AutomaticContainerLogConfig { - loggers: vec![( - "ROOT".to_string(), - LoggerConfig { - level: LogLevel::INFO, - }, - )] + loggers: vec![("ROOT".to_string(), LoggerConfig { + level: LogLevel::INFO, + })] .into_iter() .collect::>(), console: Some(AppenderConfig { @@ -1590,24 +1587,15 @@ mod tests { fn log4j2_config_with_additional_loggers() { let log_config = AutomaticContainerLogConfig { loggers: vec![ - ( - "ROOT".to_string(), - LoggerConfig { - level: LogLevel::INFO, - }, - ), - ( - "test".to_string(), - LoggerConfig { - level: LogLevel::INFO, - }, - ), - ( - "test_2".to_string(), - LoggerConfig { - level: LogLevel::DEBUG, - }, - ), + ("ROOT".to_string(), LoggerConfig { + level: LogLevel::INFO, + }), + ("test".to_string(), LoggerConfig { + level: LogLevel::INFO, + }), + ("test_2".to_string(), LoggerConfig { + level: LogLevel::DEBUG, + }), ] .into_iter() .collect::>(), diff --git a/crates/stackable-operator/src/role_utils.rs b/crates/stackable-operator/src/role_utils.rs index 7e41e5d54..4cc8861ff 100644 --- a/crates/stackable-operator/src/role_utils.rs +++ b/crates/stackable-operator/src/role_utils.rs @@ -87,7 +87,7 @@ use std::{ use educe::Educe; use k8s_openapi::api::core::v1::PodTemplateSpec; -use kube::{runtime::reflector::ObjectRef, Resource}; +use kube::{Resource, runtime::reflector::ObjectRef}; use regex::Regex; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -353,23 +353,20 @@ where .role_groups .into_iter() .map(|(name, group)| { - ( - name, - RoleGroup { - config: CommonConfiguration { - config: Box::new(group.config.config) - as Box>, - config_overrides: group.config.config_overrides, - env_overrides: group.config.env_overrides, - cli_overrides: group.config.cli_overrides, - pod_overrides: group.config.pod_overrides, - product_specific_common_config: group - .config - .product_specific_common_config, - }, - replicas: group.replicas, + (name, RoleGroup { + config: CommonConfiguration { + config: Box::new(group.config.config) + as Box>, + config_overrides: group.config.config_overrides, + env_overrides: group.config.env_overrides, + cli_overrides: group.config.cli_overrides, + pod_overrides: group.config.pod_overrides, + product_specific_common_config: group + .config + .product_specific_common_config, }, - ) + replicas: group.replicas, + }) }) .collect(), } @@ -548,14 +545,11 @@ mod tests { "-Dhttps.proxyPort=1234".to_owned(), ]); - assert_eq!( - merged_jvm_argument_overrides, - JvmArgumentOverrides { - add: expected.clone(), - remove: HashSet::new(), - remove_regex: Vec::new() - } - ); + assert_eq!(merged_jvm_argument_overrides, JvmArgumentOverrides { + add: expected.clone(), + remove: HashSet::new(), + remove_regex: Vec::new() + }); assert_eq!( merged_jvm_argument_overrides.effective_jvm_config_after_merging(), diff --git a/crates/stackable-operator/src/status/condition/daemonset.rs b/crates/stackable-operator/src/status/condition/daemonset.rs index a9fc46f79..1e08bac78 100644 --- a/crates/stackable-operator/src/status/condition/daemonset.rs +++ b/crates/stackable-operator/src/status/condition/daemonset.rs @@ -92,8 +92,8 @@ mod tests { use k8s_openapi::api::apps::v1::{DaemonSet, DaemonSetStatus}; use crate::status::condition::{ - daemonset::DaemonSetConditionBuilder, ClusterCondition, ClusterConditionStatus, - ClusterConditionType, ConditionBuilder, + ClusterCondition, ClusterConditionStatus, ClusterConditionType, ConditionBuilder, + daemonset::DaemonSetConditionBuilder, }; fn build_ds(number_ready: i32) -> DaemonSet { diff --git a/crates/stackable-operator/src/status/condition/deployment.rs b/crates/stackable-operator/src/status/condition/deployment.rs index c70180a93..7b4c1cde2 100644 --- a/crates/stackable-operator/src/status/condition/deployment.rs +++ b/crates/stackable-operator/src/status/condition/deployment.rs @@ -96,8 +96,8 @@ mod tests { use k8s_openapi::api::apps::v1::{Deployment, DeploymentSpec, DeploymentStatus}; use crate::status::condition::{ - deployment::DeploymentConditionBuilder, ClusterCondition, ClusterConditionStatus, - ClusterConditionType, ConditionBuilder, + ClusterCondition, ClusterConditionStatus, ClusterConditionType, ConditionBuilder, + deployment::DeploymentConditionBuilder, }; fn build_deployment(spec_replicas: i32, available_replicas: i32) -> Deployment { diff --git a/crates/stackable-operator/src/status/condition/statefulset.rs b/crates/stackable-operator/src/status/condition/statefulset.rs index b75308289..6a51f0d39 100644 --- a/crates/stackable-operator/src/status/condition/statefulset.rs +++ b/crates/stackable-operator/src/status/condition/statefulset.rs @@ -96,8 +96,8 @@ mod tests { use k8s_openapi::api::apps::v1::{StatefulSet, StatefulSetSpec, StatefulSetStatus}; use crate::status::condition::{ - statefulset::StatefulSetConditionBuilder, ClusterCondition, ClusterConditionStatus, - ClusterConditionType, ConditionBuilder, + ClusterCondition, ClusterConditionStatus, ClusterConditionType, ConditionBuilder, + statefulset::StatefulSetConditionBuilder, }; fn build_sts(spec_replicas: i32, available_replicas: i32) -> StatefulSet { diff --git a/crates/stackable-operator/src/status/rollout.rs b/crates/stackable-operator/src/status/rollout.rs index 7640d2257..b90d63353 100644 --- a/crates/stackable-operator/src/status/rollout.rs +++ b/crates/stackable-operator/src/status/rollout.rs @@ -12,7 +12,9 @@ pub enum StatefulSetRolloutInProgress { /// Indicates that the latest version of the [`StatefulSet`] has not yet been observed by Kubernetes' StatefulSet controller. /// /// Kubernetes' controllers run asynchronously in the background, so this is expected when the `spec` has just been modified. - #[snafu(display("generation {current_generation:?} not yet observed by statefulset controller, last seen was {observed_generation:?}"))] + #[snafu(display( + "generation {current_generation:?} not yet observed by statefulset controller, last seen was {observed_generation:?}" + ))] NotYetObserved { current_generation: Option, observed_generation: Option, diff --git a/crates/stackable-operator/src/time/duration.rs b/crates/stackable-operator/src/time/duration.rs index 8f70d93b9..75cf47cce 100644 --- a/crates/stackable-operator/src/time/duration.rs +++ b/crates/stackable-operator/src/time/duration.rs @@ -115,7 +115,7 @@ impl FromStr for Duration { previous: last_unit, current: unit, } - .fail() + .fail(); } Ordering::Equal => return DuplicateUnitSnafu { unit }.fail(), _ => (), @@ -170,8 +170,8 @@ impl JsonSchema for Duration { "Duration".to_string() } - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - String::json_schema(gen) + fn json_schema(generator: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema { + String::json_schema(generator) } } diff --git a/crates/stackable-operator/src/time/serde_impl.rs b/crates/stackable-operator/src/time/serde_impl.rs index 98a70100d..c365b9456 100644 --- a/crates/stackable-operator/src/time/serde_impl.rs +++ b/crates/stackable-operator/src/time/serde_impl.rs @@ -1,4 +1,4 @@ -use serde::{de::Visitor, Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::Visitor}; use crate::time::Duration; diff --git a/crates/stackable-operator/src/utils/crds.rs b/crates/stackable-operator/src/utils/crds.rs index 299ef9296..5470b8adc 100644 --- a/crates/stackable-operator/src/utils/crds.rs +++ b/crates/stackable-operator/src/utils/crds.rs @@ -1,6 +1,6 @@ use schemars::schema::Schema; -pub fn raw_object_schema(_: &mut schemars::gen::SchemaGenerator) -> Schema { +pub fn raw_object_schema(_: &mut schemars::r#gen::SchemaGenerator) -> Schema { serde_json::from_value(serde_json::json!({ "type": "object", "x-kubernetes-preserve-unknown-fields": true, @@ -8,7 +8,7 @@ pub fn raw_object_schema(_: &mut schemars::gen::SchemaGenerator) -> Schema { .expect("Failed to parse JSON of custom raw object schema") } -pub fn raw_optional_object_schema(_: &mut schemars::gen::SchemaGenerator) -> Schema { +pub fn raw_optional_object_schema(_: &mut schemars::r#gen::SchemaGenerator) -> Schema { serde_json::from_value(serde_json::json!({ "type": "object", "nullable": true, @@ -17,7 +17,7 @@ pub fn raw_optional_object_schema(_: &mut schemars::gen::SchemaGenerator) -> Sch .expect("Failed to parse JSON of custom optional raw object schema") } -pub fn raw_object_list_schema(_: &mut schemars::gen::SchemaGenerator) -> Schema { +pub fn raw_object_list_schema(_: &mut schemars::r#gen::SchemaGenerator) -> Schema { serde_json::from_value(serde_json::json!({ "type": "array", "items": { diff --git a/crates/stackable-operator/src/validation.rs b/crates/stackable-operator/src/validation.rs index 524d4f7d9..263f972ee 100644 --- a/crates/stackable-operator/src/validation.rs +++ b/crates/stackable-operator/src/validation.rs @@ -190,17 +190,12 @@ fn validate_all(validations: impl IntoIterator>) -> Res pub fn is_domain(value: &str) -> Result { validate_all([ validate_str_length(value, DOMAIN_MAX_LENGTH), - validate_str_regex( - value, - &DOMAIN_REGEX, - DOMAIN_ERROR_MSG, - &[ - "example.com", - "example.com.", - "cluster.local", - "cluster.local.", - ], - ), + validate_str_regex(value, &DOMAIN_REGEX, DOMAIN_ERROR_MSG, &[ + "example.com", + "example.com.", + "cluster.local", + "cluster.local.", + ]), ]) } @@ -222,12 +217,10 @@ pub fn is_rfc_1123_subdomain(value: &str) -> Result { pub fn is_rfc_1123_label(value: &str) -> Result { validate_all([ validate_str_length(value, RFC_1123_LABEL_MAX_LENGTH), - validate_str_regex( - value, - &RFC_1123_LABEL_REGEX, - RFC_1123_LABEL_ERROR_MSG, - &["example-label", "1-label-1"], - ), + validate_str_regex(value, &RFC_1123_LABEL_REGEX, RFC_1123_LABEL_ERROR_MSG, &[ + "example-label", + "1-label-1", + ]), ]) } @@ -235,12 +228,9 @@ pub fn is_rfc_1123_label(value: &str) -> Result { pub fn is_rfc_1035_label(value: &str) -> Result { validate_all([ validate_str_length(value, RFC_1035_LABEL_MAX_LENGTH), - validate_str_regex( - value, - &RFC_1035_LABEL_REGEX, - RFC_1035_LABEL_ERROR_MSG, - &["my-name", "abc-123"], - ), + validate_str_regex(value, &RFC_1035_LABEL_REGEX, RFC_1035_LABEL_ERROR_MSG, &[ + "my-name", "abc-123", + ]), ]) } diff --git a/crates/stackable-telemetry/src/instrumentation/axum/extractor.rs b/crates/stackable-telemetry/src/instrumentation/axum/extractor.rs index 98e6439e7..aad512f41 100644 --- a/crates/stackable-telemetry/src/instrumentation/axum/extractor.rs +++ b/crates/stackable-telemetry/src/instrumentation/axum/extractor.rs @@ -1,5 +1,5 @@ use axum::http::{HeaderMap, HeaderName}; -use opentelemetry::{propagation::Extractor, Context}; +use opentelemetry::{Context, propagation::Extractor}; /// Extracts the [`TextMapPropagator`][1] to access trace parent information in /// HTTP headers. diff --git a/crates/stackable-telemetry/src/instrumentation/axum/injector.rs b/crates/stackable-telemetry/src/instrumentation/axum/injector.rs index a9700d51e..71bccfdf3 100644 --- a/crates/stackable-telemetry/src/instrumentation/axum/injector.rs +++ b/crates/stackable-telemetry/src/instrumentation/axum/injector.rs @@ -1,5 +1,5 @@ use axum::http::{HeaderMap, HeaderName, HeaderValue}; -use opentelemetry::{propagation::Injector, Context}; +use opentelemetry::{Context, propagation::Injector}; /// Injects the [`TextMapPropagator`][1] to propagate trace parent information /// in HTTP headers. diff --git a/crates/stackable-telemetry/src/instrumentation/axum/mod.rs b/crates/stackable-telemetry/src/instrumentation/axum/mod.rs index 7ef2fc22f..244d0cd88 100644 --- a/crates/stackable-telemetry/src/instrumentation/axum/mod.rs +++ b/crates/stackable-telemetry/src/instrumentation/axum/mod.rs @@ -15,20 +15,20 @@ use std::{future::Future, net::SocketAddr, num::ParseIntError, task::Poll}; use axum::{ extract::{ConnectInfo, MatchedPath, Request}, http::{ - header::{HOST, USER_AGENT}, HeaderMap, + header::{HOST, USER_AGENT}, }, response::Response, }; use futures_util::ready; use opentelemetry::{ - trace::{SpanKind, TraceContextExt}, Context, + trace::{SpanKind, TraceContextExt}, }; use pin_project::pin_project; use snafu::{ResultExt, Snafu}; use tower::{Layer, Service}; -use tracing::{field::Empty, Span}; +use tracing::{Span, field::Empty}; use tracing_opentelemetry::OpenTelemetrySpanExt; mod extractor; @@ -568,7 +568,7 @@ impl SpanExt for Span { #[cfg(test)] mod test { - use axum::{routing::get, Router}; + use axum::{Router, routing::get}; use super::*; diff --git a/crates/stackable-telemetry/src/tracing/mod.rs b/crates/stackable-telemetry/src/tracing/mod.rs index d53f43979..6cb07edc4 100644 --- a/crates/stackable-telemetry/src/tracing/mod.rs +++ b/crates/stackable-telemetry/src/tracing/mod.rs @@ -9,15 +9,16 @@ use opentelemetry::KeyValue; use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; use opentelemetry_sdk::{ + Resource, logs::{self, LoggerProvider}, propagation::TraceContextPropagator, - trace, Resource, + trace, }; use opentelemetry_semantic_conventions::resource; use snafu::{ResultExt as _, Snafu}; use tracing::subscriber::SetGlobalDefaultError; use tracing_appender::rolling::{InitError, RollingFileAppender}; -use tracing_subscriber::{filter::Directive, layer::SubscriberExt, EnvFilter, Layer, Registry}; +use tracing_subscriber::{EnvFilter, Layer, Registry, filter::Directive, layer::SubscriberExt}; use crate::tracing::settings::*; @@ -730,28 +731,22 @@ mod test { log_format: Default::default() } ); - assert_eq!( - trace_guard.file_log_settings, - FileLogSettings::Enabled { - common_settings: Settings { - environment_variable: "ABC_FILE", - default_level: LevelFilter::INFO - }, - file_log_dir: PathBuf::from("/abc_file_dir"), - rotation_period: Rotation::NEVER, - filename_suffix: "tracing-rs.json".to_owned(), - max_log_files: None, - } - ); - assert_eq!( - trace_guard.otlp_log_settings, - OtlpLogSettings::Enabled { - common_settings: Settings { - environment_variable: "ABC_OTLP_LOG", - default_level: LevelFilter::DEBUG - }, - } - ); + assert_eq!(trace_guard.file_log_settings, FileLogSettings::Enabled { + common_settings: Settings { + environment_variable: "ABC_FILE", + default_level: LevelFilter::INFO + }, + file_log_dir: PathBuf::from("/abc_file_dir"), + rotation_period: Rotation::NEVER, + filename_suffix: "tracing-rs.json".to_owned(), + max_log_files: None, + }); + assert_eq!(trace_guard.otlp_log_settings, OtlpLogSettings::Enabled { + common_settings: Settings { + environment_variable: "ABC_OTLP_LOG", + default_level: LevelFilter::DEBUG + }, + }); assert_eq!( trace_guard.otlp_trace_settings, OtlpTraceSettings::Enabled { diff --git a/crates/stackable-versioned-macros/src/attrs/common.rs b/crates/stackable-versioned-macros/src/attrs/common.rs index f4720f147..0d2768fe6 100644 --- a/crates/stackable-versioned-macros/src/attrs/common.rs +++ b/crates/stackable-versioned-macros/src/attrs/common.rs @@ -1,6 +1,6 @@ use darling::{ - util::{Flag, Override, SpannedValue}, Error, FromMeta, Result, + util::{Flag, Override, SpannedValue}, }; use itertools::Itertools; use k8s_version::Version; diff --git a/crates/stackable-versioned-macros/src/attrs/container.rs b/crates/stackable-versioned-macros/src/attrs/container.rs index b7a0c0f9b..25e934801 100644 --- a/crates/stackable-versioned-macros/src/attrs/container.rs +++ b/crates/stackable-versioned-macros/src/attrs/container.rs @@ -1,4 +1,4 @@ -use darling::{util::Flag, Error, FromAttributes, FromMeta, Result}; +use darling::{Error, FromAttributes, FromMeta, Result, util::Flag}; use crate::attrs::{ common::{CommonOptions, CommonRootArguments, SkipArguments}, @@ -18,7 +18,9 @@ pub(crate) struct StandaloneContainerAttributes { impl StandaloneContainerAttributes { fn validate(self) -> Result { if self.kubernetes_arguments.is_some() && cfg!(not(feature = "k8s")) { - return Err(Error::custom("the `#[versioned(k8s())]` attribute can only be used when the `k8s` feature is enabled")); + return Err(Error::custom( + "the `#[versioned(k8s())]` attribute can only be used when the `k8s` feature is enabled", + )); } Ok(self) @@ -53,7 +55,9 @@ pub(crate) struct NestedContainerAttributes { impl NestedContainerAttributes { fn validate(self) -> Result { if self.kubernetes_arguments.is_some() && cfg!(not(feature = "k8s")) { - return Err(Error::custom("the `#[versioned(k8s())]` attribute can only be used when the `k8s` feature is enabled")); + return Err(Error::custom( + "the `#[versioned(k8s())]` attribute can only be used when the `k8s` feature is enabled", + )); } Ok(self) diff --git a/crates/stackable-versioned-macros/src/attrs/item/mod.rs b/crates/stackable-versioned-macros/src/attrs/item/mod.rs index e9b19f4e6..34dbb3986 100644 --- a/crates/stackable-versioned-macros/src/attrs/item/mod.rs +++ b/crates/stackable-versioned-macros/src/attrs/item/mod.rs @@ -1,10 +1,10 @@ use std::{collections::BTreeMap, ops::Deref}; -use darling::{util::SpannedValue, Error, FromMeta, Result}; +use darling::{Error, FromMeta, Result, util::SpannedValue}; use k8s_version::Version; use proc_macro2::Span; use quote::format_ident; -use syn::{spanned::Spanned, Attribute, Path, Type}; +use syn::{Attribute, Path, Type, spanned::Spanned}; use crate::{ codegen::{ItemStatus, VersionDefinition}, @@ -163,8 +163,8 @@ impl CommonItemAttributes { // Now, iterate over all changes and ensure that their versions are // between the added and deprecated version. if !self.changes.iter().all(|r| { - added_version.map_or(true, |a| a < *r.since) - && deprecated_version.map_or(true, |d| d > *r.since) + added_version.is_none_or(|a| a < *r.since) + && deprecated_version.is_none_or(|d| d > *r.since) }) { return Err(Error::custom( "all changes must use versions higher than `added` and lower than `deprecated`", @@ -293,14 +293,11 @@ impl CommonItemAttributes { let mut actions = BTreeMap::new(); - actions.insert( - *deprecated.since, - ItemStatus::Deprecation { - previous_ident: ident.clone(), - ident: deprecated_ident.clone(), - note: deprecated.note.as_deref().cloned(), - }, - ); + actions.insert(*deprecated.since, ItemStatus::Deprecation { + previous_ident: ident.clone(), + ident: deprecated_ident.clone(), + note: deprecated.note.as_deref().cloned(), + }); for change in self.changes.iter().rev() { let from_ident = if let Some(from) = change.from_name.as_deref() { @@ -317,16 +314,13 @@ impl CommonItemAttributes { .map(|sv| sv.deref().clone()) .unwrap_or(ty.clone()); - actions.insert( - *change.since, - ItemStatus::Change { - convert_with: change.convert_with.as_deref().cloned(), - from_ident: from_ident.clone(), - from_type: from_ty.clone(), - to_ident: ident, - to_type: ty, - }, - ); + actions.insert(*change.since, ItemStatus::Change { + convert_with: change.convert_with.as_deref().cloned(), + from_ident: from_ident.clone(), + from_type: from_ty.clone(), + to_ident: ident, + to_type: ty, + }); ident = from_ident; ty = from_ty; @@ -335,14 +329,11 @@ impl CommonItemAttributes { // After the last iteration above (if any) we use the ident for the // added action if there is any. if let Some(added) = self.added { - actions.insert( - *added.since, - ItemStatus::Addition { - default_fn: added.default_fn.deref().clone(), - ident, - ty, - }, - ); + actions.insert(*added.since, ItemStatus::Addition { + default_fn: added.default_fn.deref().clone(), + ident, + ty, + }); } Some(actions) @@ -367,16 +358,13 @@ impl CommonItemAttributes { .map(|sv| sv.deref().clone()) .unwrap_or(ty.clone()); - actions.insert( - *change.since, - ItemStatus::Change { - convert_with: change.convert_with.as_deref().cloned(), - from_ident: from_ident.clone(), - from_type: from_ty.clone(), - to_ident: ident, - to_type: ty, - }, - ); + actions.insert(*change.since, ItemStatus::Change { + convert_with: change.convert_with.as_deref().cloned(), + from_ident: from_ident.clone(), + from_type: from_ty.clone(), + to_ident: ident, + to_type: ty, + }); ident = from_ident; ty = from_ty; @@ -385,14 +373,11 @@ impl CommonItemAttributes { // After the last iteration above (if any) we use the ident for the // added action if there is any. if let Some(added) = self.added { - actions.insert( - *added.since, - ItemStatus::Addition { - default_fn: added.default_fn.deref().clone(), - ident, - ty, - }, - ); + actions.insert(*added.since, ItemStatus::Addition { + default_fn: added.default_fn.deref().clone(), + ident, + ty, + }); } Some(actions) @@ -400,14 +385,11 @@ impl CommonItemAttributes { if let Some(added) = self.added { let mut actions = BTreeMap::new(); - actions.insert( - *added.since, - ItemStatus::Addition { - default_fn: added.default_fn.deref().clone(), - ident: ident.deref().clone(), - ty, - }, - ); + actions.insert(*added.since, ItemStatus::Addition { + default_fn: added.default_fn.deref().clone(), + ident: ident.deref().clone(), + ty, + }); return Some(actions); } diff --git a/crates/stackable-versioned-macros/src/attrs/k8s.rs b/crates/stackable-versioned-macros/src/attrs/k8s.rs index b98210612..c241b17f7 100644 --- a/crates/stackable-versioned-macros/src/attrs/k8s.rs +++ b/crates/stackable-versioned-macros/src/attrs/k8s.rs @@ -1,4 +1,4 @@ -use darling::{util::Flag, FromMeta}; +use darling::{FromMeta, util::Flag}; use syn::Path; /// This struct contains supported Kubernetes arguments. diff --git a/crates/stackable-versioned-macros/src/attrs/module.rs b/crates/stackable-versioned-macros/src/attrs/module.rs index df4cb25c3..869d24a13 100644 --- a/crates/stackable-versioned-macros/src/attrs/module.rs +++ b/crates/stackable-versioned-macros/src/attrs/module.rs @@ -1,4 +1,4 @@ -use darling::{util::Flag, FromMeta}; +use darling::{FromMeta, util::Flag}; use crate::attrs::common::{CommonOptions, CommonRootArguments, SkipArguments}; diff --git a/crates/stackable-versioned-macros/src/codegen/changes.rs b/crates/stackable-versioned-macros/src/codegen/changes.rs index 428a7f2f0..b7c5be052 100644 --- a/crates/stackable-versioned-macros/src/codegen/changes.rs +++ b/crates/stackable-versioned-macros/src/codegen/changes.rs @@ -115,34 +115,27 @@ impl ChangesetExt for BTreeMap { from_ident, from_type, .. - } => self.insert( - version.inner, - ItemStatus::NoChange { - previously_deprecated: false, - ident: from_ident.clone(), - ty: from_type.clone(), - }, - ), - ItemStatus::Deprecation { previous_ident, .. } => self.insert( - version.inner, - ItemStatus::NoChange { + } => self.insert(version.inner, ItemStatus::NoChange { + previously_deprecated: false, + ident: from_ident.clone(), + ty: from_type.clone(), + }), + ItemStatus::Deprecation { previous_ident, .. } => { + self.insert(version.inner, ItemStatus::NoChange { previously_deprecated: false, ident: previous_ident.clone(), ty: ty.clone(), - }, - ), + }) + } ItemStatus::NoChange { previously_deprecated, ident, ty, - } => self.insert( - version.inner, - ItemStatus::NoChange { - previously_deprecated: *previously_deprecated, - ident: ident.clone(), - ty: ty.clone(), - }, - ), + } => self.insert(version.inner, ItemStatus::NoChange { + previously_deprecated: *previously_deprecated, + ident: ident.clone(), + ty: ty.clone(), + }), ItemStatus::NotPresent => unreachable!(), }, (Some(status), None) => { @@ -161,14 +154,11 @@ impl ChangesetExt for BTreeMap { ItemStatus::NotPresent => unreachable!(), }; - self.insert( - version.inner, - ItemStatus::NoChange { - previously_deprecated, - ident: ident.clone(), - ty: ty.clone(), - }, - ) + self.insert(version.inner, ItemStatus::NoChange { + previously_deprecated, + ident: ident.clone(), + ty: ty.clone(), + }) } (Some(status), Some(_)) => { let (ident, ty, previously_deprecated) = match status { @@ -187,14 +177,11 @@ impl ChangesetExt for BTreeMap { _ => unreachable!(), }; - self.insert( - version.inner, - ItemStatus::NoChange { - previously_deprecated, - ident: ident.clone(), - ty: ty.clone(), - }, - ) + self.insert(version.inner, ItemStatus::NoChange { + previously_deprecated, + ident: ident.clone(), + ty: ty.clone(), + }) } _ => unreachable!(), }; diff --git a/crates/stackable-versioned-macros/src/codegen/container/enum.rs b/crates/stackable-versioned-macros/src/codegen/container/enum.rs index b9c7de9af..da28cc785 100644 --- a/crates/stackable-versioned-macros/src/codegen/container/enum.rs +++ b/crates/stackable-versioned-macros/src/codegen/container/enum.rs @@ -1,6 +1,6 @@ use std::ops::Not; -use darling::{util::IdentString, FromAttributes, Result}; +use darling::{FromAttributes, Result, util::IdentString}; use proc_macro2::TokenStream; use quote::quote; use syn::{Generics, ItemEnum}; @@ -8,10 +8,10 @@ use syn::{Generics, ItemEnum}; use crate::{ attrs::container::NestedContainerAttributes, codegen::{ + ItemStatus, StandaloneContainerAttributes, VersionDefinition, changes::Neighbors, container::{CommonContainerData, Container, ContainerIdents, ContainerOptions}, item::VersionedVariant, - ItemStatus, StandaloneContainerAttributes, VersionDefinition, }, }; diff --git a/crates/stackable-versioned-macros/src/codegen/container/mod.rs b/crates/stackable-versioned-macros/src/codegen/container/mod.rs index 8ae136851..fbbff4006 100644 --- a/crates/stackable-versioned-macros/src/codegen/container/mod.rs +++ b/crates/stackable-versioned-macros/src/codegen/container/mod.rs @@ -1,9 +1,9 @@ use std::ops::Deref; -use darling::{util::IdentString, Result}; +use darling::{Result, util::IdentString}; use proc_macro2::{Span, TokenStream}; -use quote::{quote, ToTokens}; -use syn::{parse_quote, Attribute, Ident, ItemEnum, ItemStruct, Path, Visibility}; +use quote::{ToTokens, quote}; +use syn::{Attribute, Ident, ItemEnum, ItemStruct, Path, Visibility, parse_quote}; use crate::{ attrs::{ @@ -11,8 +11,8 @@ use crate::{ k8s::{KubernetesArguments, KubernetesCrateArguments}, }, codegen::{ - container::{r#enum::Enum, r#struct::Struct}, VersionDefinition, + container::{r#enum::Enum, r#struct::Struct}, }, utils::ContainerIdentExt, }; diff --git a/crates/stackable-versioned-macros/src/codegen/container/struct.rs b/crates/stackable-versioned-macros/src/codegen/container/struct.rs index 9f0352750..584a293b1 100644 --- a/crates/stackable-versioned-macros/src/codegen/container/struct.rs +++ b/crates/stackable-versioned-macros/src/codegen/container/struct.rs @@ -1,17 +1,17 @@ use std::ops::Not; -use darling::{util::IdentString, Error, FromAttributes, Result}; +use darling::{Error, FromAttributes, Result, util::IdentString}; use proc_macro2::TokenStream; -use quote::{quote, ToTokens}; -use syn::{parse_quote, Generics, ItemStruct, Path, Visibility}; +use quote::{ToTokens, quote}; +use syn::{Generics, ItemStruct, Path, Visibility, parse_quote}; use crate::{ attrs::container::NestedContainerAttributes, codegen::{ + ItemStatus, StandaloneContainerAttributes, VersionDefinition, changes::Neighbors, container::{CommonContainerData, Container, ContainerIdents, ContainerOptions}, item::VersionedField, - ItemStatus, StandaloneContainerAttributes, VersionDefinition, }, utils::VersionExt, }; diff --git a/crates/stackable-versioned-macros/src/codegen/item/field.rs b/crates/stackable-versioned-macros/src/codegen/item/field.rs index 413a50b21..1dcda06cc 100644 --- a/crates/stackable-versioned-macros/src/codegen/item/field.rs +++ b/crates/stackable-versioned-macros/src/codegen/item/field.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use darling::{util::IdentString, FromField, Result}; +use darling::{FromField, Result, util::IdentString}; use k8s_version::Version; use proc_macro2::TokenStream; use quote::quote; @@ -9,8 +9,8 @@ use syn::{Attribute, Field, Type}; use crate::{ attrs::item::FieldAttributes, codegen::{ - changes::{BTreeMapExt, ChangesetExt}, ItemStatus, VersionDefinition, + changes::{BTreeMapExt, ChangesetExt}, }, utils::FieldIdent, }; diff --git a/crates/stackable-versioned-macros/src/codegen/item/variant.rs b/crates/stackable-versioned-macros/src/codegen/item/variant.rs index db42da520..a65168c57 100644 --- a/crates/stackable-versioned-macros/src/codegen/item/variant.rs +++ b/crates/stackable-versioned-macros/src/codegen/item/variant.rs @@ -1,16 +1,16 @@ use std::collections::BTreeMap; -use darling::{util::IdentString, FromVariant, Result}; +use darling::{FromVariant, Result, util::IdentString}; use k8s_version::Version; use proc_macro2::{Span, TokenStream}; use quote::{format_ident, quote}; -use syn::{token::Not, Attribute, Fields, Type, TypeNever, Variant}; +use syn::{Attribute, Fields, Type, TypeNever, Variant, token::Not}; use crate::{ attrs::item::VariantAttributes, codegen::{ - changes::{BTreeMapExt, ChangesetExt}, ItemStatus, VersionDefinition, + changes::{BTreeMapExt, ChangesetExt}, }, utils::VariantIdent, }; diff --git a/crates/stackable-versioned-macros/src/codegen/module.rs b/crates/stackable-versioned-macros/src/codegen/module.rs index e2d54b4fa..217dacced 100644 --- a/crates/stackable-versioned-macros/src/codegen/module.rs +++ b/crates/stackable-versioned-macros/src/codegen/module.rs @@ -1,13 +1,13 @@ use std::{collections::HashMap, ops::Not}; -use darling::{util::IdentString, Error, Result}; +use darling::{Error, Result, util::IdentString}; use proc_macro2::TokenStream; use quote::quote; -use syn::{token::Pub, Ident, Item, ItemMod, ItemUse, Visibility}; +use syn::{Ident, Item, ItemMod, ItemUse, Visibility, token::Pub}; use crate::{ - codegen::{container::Container, VersionDefinition}, ModuleAttributes, + codegen::{VersionDefinition, container::Container}, }; pub(crate) type KubernetesItems = (Vec, Vec, Vec); diff --git a/crates/stackable-versioned-macros/src/lib.rs b/crates/stackable-versioned-macros/src/lib.rs index 0d67b8ef7..0c4fba634 100644 --- a/crates/stackable-versioned-macros/src/lib.rs +++ b/crates/stackable-versioned-macros/src/lib.rs @@ -1,6 +1,6 @@ -use darling::{ast::NestedMeta, FromMeta}; +use darling::{FromMeta, ast::NestedMeta}; use proc_macro::TokenStream; -use syn::{spanned::Spanned, Error, Item}; +use syn::{Error, Item, spanned::Spanned}; use crate::{ attrs::{container::StandaloneContainerAttributes, module::ModuleAttributes}, diff --git a/crates/stackable-versioned-macros/src/utils.rs b/crates/stackable-versioned-macros/src/utils.rs index d2003c7b2..1109884cd 100644 --- a/crates/stackable-versioned-macros/src/utils.rs +++ b/crates/stackable-versioned-macros/src/utils.rs @@ -3,8 +3,8 @@ use std::ops::Deref; use convert_case::{Case, Casing}; use darling::util::IdentString; use k8s_version::Version; -use quote::{format_ident, ToTokens}; -use syn::{spanned::Spanned, Ident}; +use quote::{ToTokens, format_ident}; +use syn::{Ident, spanned::Spanned}; pub(crate) trait VersionExt { fn as_variant_ident(&self) -> IdentString; diff --git a/crates/stackable-webhook/src/lib.rs b/crates/stackable-webhook/src/lib.rs index e7b023282..e1bb001a9 100644 --- a/crates/stackable-webhook/src/lib.rs +++ b/crates/stackable-webhook/src/lib.rs @@ -23,11 +23,11 @@ //! enable complete controll over these details if needed. //! //! [1]: crate::servers::ConversionWebhookServer -use axum::{routing::get, Router}; -use futures_util::{pin_mut, select, FutureExt as _}; +use axum::{Router, routing::get}; +use futures_util::{FutureExt as _, pin_mut, select}; use snafu::{ResultExt, Snafu}; use stackable_telemetry::AxumTraceLayer; -use tokio::signal::unix::{signal, SignalKind}; +use tokio::signal::unix::{SignalKind, signal}; use tower::ServiceBuilder; // use tower_http::trace::TraceLayer; diff --git a/crates/stackable-webhook/src/servers/conversion.rs b/crates/stackable-webhook/src/servers/conversion.rs index e8a823744..922a9b431 100644 --- a/crates/stackable-webhook/src/servers/conversion.rs +++ b/crates/stackable-webhook/src/servers/conversion.rs @@ -1,6 +1,6 @@ use std::fmt::Debug; -use axum::{extract::State, routing::post, Json, Router}; +use axum::{Json, Router, extract::State, routing::post}; // Re-export this type because users of the conversion webhook server require // this type to write the handler function. Instead of importing this type from // kube directly, consumers can use this type instead. This also eliminates @@ -8,7 +8,7 @@ use axum::{extract::State, routing::post, Json, Router}; pub use kube::core::conversion::ConversionReview; use tracing::instrument; -use crate::{options::Options, StatefulWebhookHandler, WebhookHandler, WebhookServer}; +use crate::{StatefulWebhookHandler, WebhookHandler, WebhookServer, options::Options}; impl WebhookHandler for F where diff --git a/crates/stackable-webhook/src/tls.rs b/crates/stackable-webhook/src/tls.rs index af22df052..f3bbef959 100644 --- a/crates/stackable-webhook/src/tls.rs +++ b/crates/stackable-webhook/src/tls.rs @@ -2,25 +2,25 @@ //! server, which can be used in combination with an Axum [`Router`]. use std::{net::SocketAddr, sync::Arc}; -use axum::{extract::Request, Router}; +use axum::{Router, extract::Request}; use futures_util::pin_mut; use hyper::{body::Incoming, service::service_fn}; use hyper_util::rt::{TokioExecutor, TokioIo}; use opentelemetry::trace::{FutureExt, SpanKind}; use snafu::{ResultExt, Snafu}; -use stackable_certs::{ca::CertificateAuthority, keys::rsa, CertificatePairError}; +use stackable_certs::{CertificatePairError, ca::CertificateAuthority, keys::rsa}; use stackable_operator::time::Duration; use tokio::net::TcpListener; use tokio_rustls::{ + TlsAcceptor, rustls::{ + ServerConfig, crypto::aws_lc_rs::default_provider, version::{TLS12, TLS13}, - ServerConfig, }, - TlsAcceptor, }; use tower::{Service, ServiceExt}; -use tracing::{field::Empty, instrument, Instrument, Span}; +use tracing::{Instrument, Span, field::Empty, instrument}; use tracing_opentelemetry::OpenTelemetrySpanExt; pub type Result = std::result::Result; @@ -30,9 +30,7 @@ pub enum Error { #[snafu(display("failed to construct TLS server config, bad certificate/key"))] InvalidTlsPrivateKey { source: tokio_rustls::rustls::Error }, - #[snafu(display( - "failed to create TCP listener by binding to socket address {socket_addr:?}" - ))] + #[snafu(display("failed to create TCP listener by binding to socket address {socket_addr:?}"))] BindTcpListener { source: std::io::Error, socket_addr: SocketAddr, diff --git a/rust-toolchain.toml b/rust-toolchain.toml index fcb78ec56..c1bc0a694 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.84.1" +channel = "1.85.0" diff --git a/rustfmt.toml b/rustfmt.toml index b9884b78e..4731b22c8 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,5 @@ +# https://doc.rust-lang.org/nightly/edition-guide/rust-2024/rustfmt-style-edition.html +style_edition = "2024" imports_granularity = "Crate" group_imports = "StdExternalCrate" reorder_impl_items = true