From df70316e6cf851edd229bd62284e20ab49842fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natalie=20Klestrup=20R=C3=B6ijezon?= Date: Mon, 26 May 2025 16:02:26 +0200 Subject: [PATCH] Bump nightly rust op-rs mirror to https://github.com/stackabletech/operator-templating/pull/524, because I'm tired of constantly keeping score between the two fighting rustfmts. --- .github/workflows/pr_pre-commit.yaml | 2 +- .pre-commit-config.yaml | 2 +- .vscode/settings.json | 4 +- crates/stackable-operator-derive/src/merge.rs | 11 +- crates/stackable-operator/src/builder/pdb.rs | 111 ++++---- .../src/builder/pod/container.rs | 51 ++-- .../stackable-operator/src/builder/pod/mod.rs | 9 +- .../src/builder/pod/security.rs | 89 ++++--- crates/stackable-operator/src/cli.rs | 56 ++-- .../src/commons/affinity.rs | 248 ++++++++++-------- .../stackable-operator/src/config/fragment.rs | 11 +- .../crd/authentication/ldap/v1alpha1_impl.rs | 82 +++--- crates/stackable-operator/src/iter.rs | 26 +- crates/stackable-operator/src/kvp/key.rs | 18 +- .../stackable-operator/src/kvp/label/value.rs | 9 +- .../src/product_logging/framework.rs | 36 ++- crates/stackable-operator/src/role_utils.rs | 42 +-- crates/stackable-operator/src/validation.rs | 36 ++- crates/stackable-telemetry/src/tracing/mod.rs | 59 +++-- .../src/attrs/item/mod.rs | 90 ++++--- .../src/codegen/changes.rs | 61 +++-- 21 files changed, 598 insertions(+), 455 deletions(-) diff --git a/.github/workflows/pr_pre-commit.yaml b/.github/workflows/pr_pre-commit.yaml index f778dc29c..a46636b80 100644 --- a/.github/workflows/pr_pre-commit.yaml +++ b/.github/workflows/pr_pre-commit.yaml @@ -7,7 +7,7 @@ on: env: CARGO_TERM_COLOR: always - RUST_TOOLCHAIN_VERSION: "nightly-2025-01-15" + RUST_TOOLCHAIN_VERSION: "nightly-2025-05-26" permissions: {} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ed3c7b4f9..7a01a5971 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -56,6 +56,6 @@ repos: name: rustfmt language: system # Pinning to a specific rustc version, so that we get consistent formatting - entry: cargo +nightly-2025-01-15 fmt --all -- --check + entry: cargo +nightly-2025-05-26 fmt --all -- --check stages: [pre-commit] pass_filenames: false diff --git a/.vscode/settings.json b/.vscode/settings.json index 031c62f57..8d9323a24 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "rust-analyzer.cargo.features": "all", "rust-analyzer.rustfmt.overrideCommand": [ "rustfmt", - "+nightly-2025-01-15", + "+nightly-2025-05-26", "--" - ], + ] } diff --git a/crates/stackable-operator-derive/src/merge.rs b/crates/stackable-operator-derive/src/merge.rs index d66310087..0598b275f 100644 --- a/crates/stackable-operator-derive/src/merge.rs +++ b/crates/stackable-operator-derive/src/merge.rs @@ -67,10 +67,13 @@ 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 0a5f2f70c..4232b2d78 100644 --- a/crates/stackable-operator/src/builder/pdb.rs +++ b/crates/stackable-operator/src/builder/pdb.rs @@ -229,22 +229,28 @@ 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())])), + 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() - }), - ..Default::default() - }) + } + ) } #[test] @@ -283,54 +289,57 @@ 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([ - ("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([ + 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/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 ea9631782..9c954d020 100644 --- a/crates/stackable-operator/src/builder/pod/container.rs +++ b/crates/stackable-operator/src/builder/pod/container.rs @@ -120,13 +120,16 @@ 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 } @@ -137,14 +140,17 @@ 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(), + 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() - }), - ..Default::default() - }); + }, + ); self } @@ -155,14 +161,17 @@ 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(), + 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() - }), - ..Default::default() - }); + }, + ); self } diff --git a/crates/stackable-operator/src/builder/pod/mod.rs b/crates/stackable-operator/src/builder/pod/mod.rs index 197a8517b..7fe2760a1 100644 --- a/crates/stackable-operator/src/builder/pod/mod.rs +++ b/crates/stackable-operator/src/builder/pod/mod.rs @@ -767,11 +767,12 @@ 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 fe33a933e..72426cf05 100644 --- a/crates/stackable-operator/src/builder/pod/security.rs +++ b/crates/stackable-operator/src/builder/pod/security.rs @@ -365,48 +365,51 @@ 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 f3a505eb0..50f36421e 100644 --- a/crates/stackable-operator/src/cli.rs +++ b/crates/stackable-operator/src/cli.rs @@ -364,10 +364,13 @@ mod tests { if let Err(Error::RequiredFileMissing { search_path }) = ProductConfigPath::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") } @@ -386,30 +389,39 @@ mod tests { "--watch-namespace", "foo", ]); - assert_eq!(opts, ProductOperatorRun { - product_config: ProductConfigPath::from("bar".as_ref()), - watch_namespace: WatchNamespace::One("foo".to_string()), - cluster_info_opts: Default::default(), - telemetry_arguments: Default::default(), - }); + assert_eq!( + opts, + ProductOperatorRun { + product_config: ProductConfigPath::from("bar".as_ref()), + watch_namespace: WatchNamespace::One("foo".to_string()), + cluster_info_opts: Default::default(), + telemetry_arguments: 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, - cluster_info_opts: Default::default(), - telemetry_arguments: Default::default(), - }); + assert_eq!( + opts, + ProductOperatorRun { + product_config: ProductConfigPath::from("bar".as_ref()), + watch_namespace: WatchNamespace::All, + cluster_info_opts: Default::default(), + telemetry_arguments: Default::default(), + } + ); // env with namespace 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()), - cluster_info_opts: Default::default(), - telemetry_arguments: Default::default(), - }); + assert_eq!( + opts, + ProductOperatorRun { + product_config: ProductConfigPath::from("bar".as_ref()), + watch_namespace: WatchNamespace::One("foo".to_string()), + cluster_info_opts: Default::default(), + telemetry_arguments: Default::default(), + } + ); } } diff --git a/crates/stackable-operator/src/commons/affinity.rs b/crates/stackable-operator/src/commons/affinity.rs index 78289e07e..188b366a9 100644 --- a/crates/stackable-operator/src/commons/affinity.rs +++ b/crates/stackable-operator/src/commons/affinity.rs @@ -183,68 +183,73 @@ 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 { - 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 { + 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: 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(), - ) - ])) + 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: TOPOLOGY_KEY_HOSTNAME.to_string(), + topology_key: "".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())]) - }), - }); + 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())]) + }), + } + ); } #[test] @@ -279,11 +284,50 @@ 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 { + 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 { label_selector: Some(LabelSelector { match_expressions: None, match_labels: Some(BTreeMap::from([ @@ -298,43 +342,12 @@ mod tests { ) ])) }), - topology_key: "topology.kubernetes.io/zone".to_string(), + topology_key: TOPOLOGY_KEY_HOSTNAME.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 { - 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 - }); + }, + weight: 70 + } + ); } #[test] @@ -343,22 +356,25 @@ 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/config/fragment.rs b/crates/stackable-operator/src/config/fragment.rs index 9fd3b14c3..23cd4e488 100644 --- a/crates/stackable-operator/src/config/fragment.rs +++ b/crates/stackable-operator/src/config/fragment.rs @@ -207,10 +207,13 @@ 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)] diff --git a/crates/stackable-operator/src/crd/authentication/ldap/v1alpha1_impl.rs b/crates/stackable-operator/src/crd/authentication/ldap/v1alpha1_impl.rs index 1f32d23d9..7c4185f8b 100644 --- a/crates/stackable-operator/src/crd/authentication/ldap/v1alpha1_impl.rs +++ b/crates/stackable-operator/src/crd/authentication/ldap/v1alpha1_impl.rs @@ -229,18 +229,24 @@ mod tests { ); let (tls_volumes, tls_mounts) = ldap.tls.volumes_and_mounts().unwrap(); - 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() - ]); + 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() + ] + ); assert!(ldap.has_bind_credentials()); assert_eq!( @@ -252,28 +258,34 @@ 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/iter.rs b/crates/stackable-operator/src/iter.rs index b3e0f7f44..e6911e081 100644 --- a/crates/stackable-operator/src/iter.rs +++ b/crates/stackable-operator/src/iter.rs @@ -110,12 +110,14 @@ 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] @@ -126,14 +128,10 @@ 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 c82790905..98ef7cb1d 100644 --- a/crates/stackable-operator/src/kvp/key.rs +++ b/crates/stackable-operator/src/kvp/key.rs @@ -216,9 +216,12 @@ 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); @@ -297,9 +300,12 @@ 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/value.rs b/crates/stackable-operator/src/kvp/label/value.rs index 0220a1b58..7135ceef7 100644 --- a/crates/stackable-operator/src/kvp/label/value.rs +++ b/crates/stackable-operator/src/kvp/label/value.rs @@ -56,9 +56,12 @@ 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/product_logging/framework.rs b/crates/stackable-operator/src/product_logging/framework.rs index 226604f68..6abdfb0f3 100644 --- a/crates/stackable-operator/src/product_logging/framework.rs +++ b/crates/stackable-operator/src/product_logging/framework.rs @@ -1564,9 +1564,12 @@ 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 { @@ -1596,15 +1599,24 @@ 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 4cc8861ff..fcd8b4df4 100644 --- a/crates/stackable-operator/src/role_utils.rs +++ b/crates/stackable-operator/src/role_utils.rs @@ -353,20 +353,23 @@ 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, + ( + 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, }, - replicas: group.replicas, - }) + ) }) .collect(), } @@ -545,11 +548,14 @@ 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/validation.rs b/crates/stackable-operator/src/validation.rs index 263f972ee..524d4f7d9 100644 --- a/crates/stackable-operator/src/validation.rs +++ b/crates/stackable-operator/src/validation.rs @@ -190,12 +190,17 @@ 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.", + ], + ), ]) } @@ -217,10 +222,12 @@ 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"], + ), ]) } @@ -228,9 +235,12 @@ 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/tracing/mod.rs b/crates/stackable-telemetry/src/tracing/mod.rs index 63d1dc384..499e11d95 100644 --- a/crates/stackable-telemetry/src/tracing/mod.rs +++ b/crates/stackable-telemetry/src/tracing/mod.rs @@ -990,22 +990,28 @@ 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 { @@ -1057,15 +1063,18 @@ mod test { #[test] fn pre_configured() { - let tracing = Tracing::pre_configured("test", TelemetryOptions { - console_log_disabled: false, - console_log_format: Default::default(), - file_log_directory: None, - file_log_rotation_period: None, - file_log_max_files: None, - otel_trace_exporter_enabled: true, - otel_log_exporter_enabled: false, - }); + let tracing = Tracing::pre_configured( + "test", + TelemetryOptions { + console_log_disabled: false, + console_log_format: Default::default(), + file_log_directory: None, + file_log_rotation_period: None, + file_log_max_files: None, + otel_trace_exporter_enabled: true, + otel_log_exporter_enabled: false, + }, + ); assert!(tracing.otlp_trace_settings.is_enabled()); } diff --git a/crates/stackable-versioned-macros/src/attrs/item/mod.rs b/crates/stackable-versioned-macros/src/attrs/item/mod.rs index fff4396fb..e2cb041b3 100644 --- a/crates/stackable-versioned-macros/src/attrs/item/mod.rs +++ b/crates/stackable-versioned-macros/src/attrs/item/mod.rs @@ -304,11 +304,14 @@ 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() { @@ -325,14 +328,17 @@ impl CommonItemAttributes { .map(|sv| sv.deref().clone()) .unwrap_or(ty.clone()); - actions.insert(*change.since, ItemStatus::Change { - downgrade_with: change.downgrade_with.as_deref().cloned(), - upgrade_with: change.upgrade_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 { + downgrade_with: change.downgrade_with.as_deref().cloned(), + upgrade_with: change.upgrade_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; @@ -341,11 +347,14 @@ 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) @@ -370,14 +379,17 @@ impl CommonItemAttributes { .map(|sv| sv.deref().clone()) .unwrap_or(ty.clone()); - actions.insert(*change.since, ItemStatus::Change { - downgrade_with: change.downgrade_with.as_deref().cloned(), - upgrade_with: change.upgrade_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 { + downgrade_with: change.downgrade_with.as_deref().cloned(), + upgrade_with: change.upgrade_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; @@ -386,11 +398,14 @@ 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) @@ -398,11 +413,14 @@ 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/codegen/changes.rs b/crates/stackable-versioned-macros/src/codegen/changes.rs index 545e42aa5..90709c688 100644 --- a/crates/stackable-versioned-macros/src/codegen/changes.rs +++ b/crates/stackable-versioned-macros/src/codegen/changes.rs @@ -115,27 +115,34 @@ 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) => { @@ -154,11 +161,14 @@ 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 { @@ -181,11 +191,14 @@ 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!(), };