From 12aa5c2f098801d369f6e99d6fa3665e470b5ee8 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Thu, 11 Jan 2024 19:51:00 +0100 Subject: [PATCH 01/31] upgrade operator-rs and remove extra space --- Cargo.lock | 132 +++++++++++++++++++++++++++++------------------------ Cargo.toml | 4 +- 2 files changed, 74 insertions(+), 62 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8acab649..0cc7a4b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -423,6 +423,17 @@ dependencies = [ "syn 2.0.39", ] +[[package]] +name = "delegate" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e018fccbeeb50ff26562ece792ed06659b9c2dae79ece77c4456bb10d9bf79b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + [[package]] name = "derivative" version = "2.2.0" @@ -673,12 +684,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" version = "0.14.0" @@ -840,16 +845,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - [[package]] name = "indexmap" version = "2.0.0" @@ -857,7 +852,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" dependencies = [ "equivalent", - "hashbrown 0.14.0", + "hashbrown", ] [[package]] @@ -1045,7 +1040,7 @@ dependencies = [ "backoff", "derivative", "futures 0.3.28", - "hashbrown 0.14.0", + "hashbrown", "json-patch", "k8s-openapi", "kube-client", @@ -1205,71 +1200,62 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "opentelemetry" -version = "0.20.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9591d937bc0e6d2feb6f71a559540ab300ea49955229c347a517a28d27784c54" +checksum = "1e32339a5dc40459130b3bd269e9892439f55b33e772d2a9d402a789baaf4e8a" dependencies = [ - "opentelemetry_api", - "opentelemetry_sdk", + "futures-core", + "futures-sink", + "indexmap", + "js-sys", + "once_cell", + "pin-project-lite", + "thiserror", + "urlencoding", ] [[package]] name = "opentelemetry-jaeger" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "876958ba9084f390f913fcf04ddf7bbbb822898867bb0a51cc28f2b9e5c1b515" +checksum = "e617c66fd588e40e0dbbd66932fdc87393095b125d4459b1a3a10feb1712f8a1" dependencies = [ "async-trait", "futures-core", "futures-util", "opentelemetry", "opentelemetry-semantic-conventions", + "opentelemetry_sdk", "thrift", "tokio", ] [[package]] name = "opentelemetry-semantic-conventions" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73c9f9340ad135068800e7f1b24e9e09ed9e7143f5bf8518ded3d3ec69789269" +checksum = "f5774f1ef1f982ef2a447f6ee04ec383981a3ab99c8e77a1a7b30182e65bbc84" dependencies = [ "opentelemetry", ] -[[package]] -name = "opentelemetry_api" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a81f725323db1b1206ca3da8bb19874bbd3f57c3bcd59471bfb04525b265b9b" -dependencies = [ - "futures-channel", - "futures-util", - "indexmap 1.9.3", - "js-sys", - "once_cell", - "pin-project-lite", - "thiserror", - "urlencoding", -] - [[package]] name = "opentelemetry_sdk" -version = "0.20.0" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa8e705a0612d48139799fcbaba0d4a90f06277153e43dd2bdc16c6f0edd8026" +checksum = "2f16aec8a98a457a52664d69e0091bac3a0abd18ead9b641cb00202ba4e0efe4" dependencies = [ "async-trait", "crossbeam-channel", "futures-channel", "futures-executor", "futures-util", + "glob", "once_cell", - "opentelemetry_api", - "ordered-float 3.9.1", + "opentelemetry", + "ordered-float 4.2.0", "percent-encoding", "rand", - "regex", "thiserror", "tokio", "tokio-stream", @@ -1286,9 +1272,9 @@ dependencies = [ [[package]] name = "ordered-float" -version = "3.9.1" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a54938017eacd63036332b4ae5c8a49fc8c0c1d6d629893057e4f13609edd06" +checksum = "a76df7075c7d4d01fdcb46c912dd17fba5b60c78ea480b475f2b6ab6f666584e" dependencies = [ "num-traits", ] @@ -1802,7 +1788,7 @@ version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ - "indexmap 2.0.0", + "indexmap", "itoa", "ryu", "serde", @@ -1823,7 +1809,7 @@ version = "0.9.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574" dependencies = [ - "indexmap 2.0.0", + "indexmap", "itoa", "ryu", "serde", @@ -1983,12 +1969,13 @@ dependencies = [ [[package]] name = "stackable-operator" -version = "0.57.0" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.57.0#ab5c5c3f220ae9449e82f6861f44a4a9a6fb7b6b" +version = "0.60.1" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.60.1#21f98e8937dac924e374b54bd6ea1d7b2367ca69" dependencies = [ "chrono", "clap", "const_format", + "delegate", "derivative", "dockerfile-parser", "either", @@ -1999,6 +1986,7 @@ dependencies = [ "lazy_static", "opentelemetry", "opentelemetry-jaeger", + "opentelemetry_sdk", "product-config", "rand", "regex", @@ -2015,12 +2003,13 @@ dependencies = [ "tracing", "tracing-opentelemetry", "tracing-subscriber", + "url", ] [[package]] name = "stackable-operator-derive" -version = "0.57.0" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.57.0#ab5c5c3f220ae9449e82f6861f44a4a9a6fb7b6b" +version = "0.60.1" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.60.1#21f98e8937dac924e374b54bd6ea1d7b2367ca69" dependencies = [ "darling", "proc-macro2", @@ -2248,7 +2237,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.0.0", + "indexmap", "serde", "serde_spanned", "toml_datetime", @@ -2362,20 +2351,33 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + [[package]] name = "tracing-opentelemetry" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75327c6b667828ddc28f5e3f169036cb793c3f588d83bf0f262a7f062ffed3c8" +checksum = "c67ac25c5407e7b961fafc6f7e9aa5958fd297aada2d20fa2ae1737357e55596" dependencies = [ + "js-sys", "once_cell", "opentelemetry", "opentelemetry_sdk", "smallvec", "tracing", "tracing-core", - "tracing-log", + "tracing-log 0.2.0", "tracing-subscriber", + "web-time", ] [[package]] @@ -2393,7 +2395,7 @@ dependencies = [ "thread_local", "tracing", "tracing-core", - "tracing-log", + "tracing-log 0.1.3", ] [[package]] @@ -2582,6 +2584,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa30049b1c872b72c89866d458eae9f20380ab280ffd1b1e18df2d3e2d98cfe0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 24b0b1f7..43cd02df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/stackabletech/hdfs-operator" [workspace.dependencies] anyhow = "1.0" -built = { version = "0.6", features = ["chrono", "git2"] } +built = { version = "0.6", features = ["chrono", "git2"] } clap = "4.3" futures = { version = "0.3", features = ["compat"] } indoc = "2.0" @@ -21,7 +21,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_yaml = "0.9" snafu = "0.7" -stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.57.0" } +stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.60.1" } product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.6.0" } strum = { version = "0.25", features = ["derive"] } tokio = { version = "1.29", features = ["full"] } From 514995dc96e116996573906e44a9336d48382c9c Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Thu, 11 Jan 2024 19:53:26 +0100 Subject: [PATCH 02/31] remove legacy node selector code --- rust/crd/src/affinity.rs | 113 --------------------------------------- rust/crd/src/lib.rs | 33 ------------ 2 files changed, 146 deletions(-) diff --git a/rust/crd/src/affinity.rs b/rust/crd/src/affinity.rs index 9c1f2157..30f27962 100644 --- a/rust/crd/src/affinity.rs +++ b/rust/crd/src/affinity.rs @@ -132,117 +132,4 @@ spec: } ); } - - #[test] - fn test_affinity_legacy_node_selector() { - let input = r#" -apiVersion: hdfs.stackable.tech/v1alpha1 -kind: HdfsCluster -metadata: - name: simple-hdfs -spec: - image: - productVersion: 3.3.6 - clusterConfig: - zookeeperConfigMapName: hdfs-zk - journalNodes: - roleGroups: - default: - replicas: 1 - nameNodes: - roleGroups: - default: - replicas: 1 - dataNodes: - roleGroups: - default: - replicas: 1 - selector: - matchLabels: - disktype: ssd - matchExpressions: - - key: topology.kubernetes.io/zone - operator: In - values: - - antarctica-east1 - - antarctica-west1 - "#; - let hdfs: HdfsCluster = serde_yaml::from_str(input).unwrap(); - let merged_config = HdfsRole::DataNode.merged_config(&hdfs, "default").unwrap(); - - assert_eq!( - merged_config.affinity(), - &StackableAffinity { - pod_affinity: Some(PodAffinity { - 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(), "hdfs".to_string(),), - ( - "app.kubernetes.io/instance".to_string(), - "simple-hdfs".to_string(), - ), - ])) - }), - namespace_selector: None, - namespaces: None, - topology_key: "kubernetes.io/hostname".to_string(), - }, - weight: 20 - } - ]), - required_during_scheduling_ignored_during_execution: None, - }), - 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(), "hdfs".to_string(),), - ( - "app.kubernetes.io/instance".to_string(), - "simple-hdfs".to_string(), - ), - ( - "app.kubernetes.io/component".to_string(), - "datanode".to_string(), - ) - ])) - }), - namespace_selector: None, - namespaces: None, - topology_key: "kubernetes.io/hostname".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())]) - }), - } - ); - } } diff --git a/rust/crd/src/lib.rs b/rust/crd/src/lib.rs index 1f4749a5..4c27fa05 100644 --- a/rust/crd/src/lib.rs +++ b/rust/crd/src/lib.rs @@ -288,17 +288,6 @@ impl HdfsRole { .config .clone(); - if let Some(RoleGroup { - selector: Some(selector), - .. - }) = role.role_groups.get(role_group) - { - // Migrate old `selector` attribute, see ADR 26 affinities. - // TODO Can be removed after support for the old `selector` field is dropped. - #[allow(deprecated)] - role_group_config.affinity.add_legacy_selector(selector); - } - role_config.merge(&default_config); role_group_config.merge(&role_config); Ok(Box::new( @@ -327,17 +316,6 @@ impl HdfsRole { .config .clone(); - if let Some(RoleGroup { - selector: Some(selector), - .. - }) = role.role_groups.get(role_group) - { - // Migrate old `selector` attribute, see ADR 26 affinities. - // TODO Can be removed after support for the old `selector` field is dropped. - #[allow(deprecated)] - role_group_config.affinity.add_legacy_selector(selector); - } - role_config.merge(&default_config); role_group_config.merge(&role_config); Ok(Box::new( @@ -367,17 +345,6 @@ impl HdfsRole { .config .clone(); - if let Some(RoleGroup { - selector: Some(selector), - .. - }) = role.role_groups.get(role_group) - { - // Migrate old `selector` attribute, see ADR 26 affinities. - // TODO Can be removed after support for the old `selector` field is dropped. - #[allow(deprecated)] - role_group_config.affinity.add_legacy_selector(selector); - } - role_config.merge(&default_config); role_group_config.merge(&role_config); Ok(Box::new( From c0f4185ccc5b31fed119c2a97a8c47d63a1b83c8 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Fri, 12 Jan 2024 12:17:35 +0100 Subject: [PATCH 03/31] remove legacy node selector code --- rust/crd/src/affinity.rs | 5 ++--- rust/crd/src/lib.rs | 19 ------------------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/rust/crd/src/affinity.rs b/rust/crd/src/affinity.rs index 30f27962..21e53ca7 100644 --- a/rust/crd/src/affinity.rs +++ b/rust/crd/src/affinity.rs @@ -33,11 +33,10 @@ mod test { use crate::{HdfsCluster, HdfsRole}; use stackable_operator::{ - commons::affinity::{StackableAffinity, StackableNodeSelector}, + commons::affinity::StackableAffinity, k8s_openapi::{ api::core::v1::{ - NodeAffinity, NodeSelector, NodeSelectorRequirement, NodeSelectorTerm, PodAffinity, - PodAffinityTerm, PodAntiAffinity, WeightedPodAffinityTerm, + PodAffinity, PodAffinityTerm, PodAntiAffinity, WeightedPodAffinityTerm, }, apimachinery::pkg::apis::meta::v1::LabelSelector, }, diff --git a/rust/crd/src/lib.rs b/rust/crd/src/lib.rs index 4c27fa05..d5ae203e 100644 --- a/rust/crd/src/lib.rs +++ b/rust/crd/src/lib.rs @@ -386,25 +386,6 @@ impl HdfsRole { .and_then(|rg| rg.replicas), } } - - /// Return the node/label selector for a certain rolegroup. - pub fn role_group_node_selector( - &self, - hdfs: &HdfsCluster, - role_group: &str, - ) -> Option { - match self { - HdfsRole::NameNode => hdfs - .namenode_rolegroup(role_group) - .and_then(|rg| rg.selector.clone()), - HdfsRole::DataNode => hdfs - .datanode_rolegroup(role_group) - .and_then(|rg| rg.selector.clone()), - HdfsRole::JournalNode => hdfs - .journalnode_rolegroup(role_group) - .and_then(|rg| rg.selector.clone()), - } - } } impl HdfsCluster { From e33d5eff76cab0e1042b5ce4de813d76135aef64 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Fri, 12 Jan 2024 12:54:57 +0100 Subject: [PATCH 04/31] use new label builders, and change return type --- rust/crd/src/lib.rs | 34 ++++++++++++++------- rust/operator-binary/src/hdfs_controller.rs | 9 +++++- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/rust/crd/src/lib.rs b/rust/crd/src/lib.rs index d5ae203e..04131ec3 100644 --- a/rust/crd/src/lib.rs +++ b/rust/crd/src/lib.rs @@ -18,12 +18,9 @@ use stackable_operator::{ fragment::{Fragment, ValidationError}, merge::Merge, }, - k8s_openapi::{ - api::core::v1::PodTemplateSpec, - apimachinery::pkg::{api::resource::Quantity, apis::meta::v1::LabelSelector}, - }, + k8s_openapi::{api::core::v1::PodTemplateSpec, apimachinery::pkg::api::resource::Quantity}, kube::{runtime::reflector::ObjectRef, CustomResource, ResourceExt}, - labels::role_group_selector_labels, + kvp::{Label, LabelError, Labels}, product_config_utils::{ConfigError, Configuration}, product_logging, product_logging::spec::{ContainerLogConfig, Logging}, @@ -49,6 +46,8 @@ pub mod constants; pub mod security; pub mod storage; +type Result = std::result::Result; + #[derive(Snafu, Debug)] pub enum Error { #[snafu(display("Object has no associated namespace"))] @@ -59,6 +58,9 @@ pub enum Error { MissingRoleGroup { role: String, role_group: String }, #[snafu(display("fragment validation failure"))] FragmentValidationFailure { source: ValidationError }, + + #[snafu(display("failed to build label"))] + BuildLabel { source: LabelError }, } /// An HDFS cluster stacklet. This resource is managed by the Stackable operator for Apache Hadoop HDFS. @@ -395,15 +397,22 @@ impl HdfsCluster { pub fn rolegroup_selector_labels( &self, rolegroup_ref: &RoleGroupRef, - ) -> BTreeMap { - let mut group_labels = role_group_selector_labels( + ) -> Result { + let mut group_labels = Labels::role_group_selector( self, APP_NAME, &rolegroup_ref.role, &rolegroup_ref.role_group, + ) + .context(BuildLabelSnafu)?; + group_labels.insert( + Label::try_from((String::from("role"), rolegroup_ref.role.clone())) + .context(BuildLabelSnafu)?, + ); + group_labels.insert( + Label::try_from((String::from("group"), rolegroup_ref.role_group.clone())) + .context(BuildLabelSnafu)?, ); - group_labels.insert(String::from("role"), rolegroup_ref.role.clone()); - group_labels.insert(String::from("group"), rolegroup_ref.role_group.clone()); if self.spec.cluster_config.listener_class == CurrentlySupportedListenerClasses::ExternalUnstable @@ -411,10 +420,13 @@ impl HdfsCluster { // TODO: in a production environment, probably not all roles need to be exposed with one NodePort per Pod but it's // useful for development purposes. - group_labels.insert(LABEL_ENABLE.to_string(), "true".to_string()); + group_labels.insert( + Label::try_from((LABEL_ENABLE.to_string(), "true".to_string())) + .context(BuildLabelSnafu)?, + ); } - group_labels + Ok(group_labels) } /// Get a reference to the namenode [`RoleGroup`] struct if it exists. diff --git a/rust/operator-binary/src/hdfs_controller.rs b/rust/operator-binary/src/hdfs_controller.rs index 7b0ae249..6d7141ef 100644 --- a/rust/operator-binary/src/hdfs_controller.rs +++ b/rust/operator-binary/src/hdfs_controller.rs @@ -210,6 +210,9 @@ pub enum Error { #[snafu(display("failed to configure graceful shutdown"))] GracefulShutdown { source: graceful_shutdown::Error }, + + #[snafu(display("failed to build roleGroup selector labels"))] + RoleGroupSelectorLabels { source: stackable_hdfs_crd::Error }, } impl ReconcilerError for Error { @@ -455,7 +458,11 @@ fn rolegroup_service( }) .collect(), ), - selector: Some(hdfs.rolegroup_selector_labels(rolegroup_ref)), + selector: Some( + hdfs.rolegroup_selector_labels(rolegroup_ref) + .context(RoleGroupSelectorLabelsSnafu)? + .into(), + ), publish_not_ready_addresses: Some(true), ..ServiceSpec::default() }), From f1ae48123ac717ce57e4dd956034ac50589fc64b Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Fri, 12 Jan 2024 13:05:43 +0100 Subject: [PATCH 05/31] use new label builders --- rust/operator-binary/src/hdfs_controller.rs | 250 +++++++++++--------- 1 file changed, 143 insertions(+), 107 deletions(-) diff --git a/rust/operator-binary/src/hdfs_controller.rs b/rust/operator-binary/src/hdfs_controller.rs index 6d7141ef..41de1195 100644 --- a/rust/operator-binary/src/hdfs_controller.rs +++ b/rust/operator-binary/src/hdfs_controller.rs @@ -14,7 +14,10 @@ use stackable_hdfs_crd::{ constants::*, HdfsCluster, HdfsClusterStatus, HdfsPodRef, HdfsRole, MergedConfig, }; use stackable_operator::{ - builder::{ConfigMapBuilder, ObjectMetaBuilder, PodBuilder, PodSecurityContextBuilder}, + builder::{ + ConfigMapBuilder, ObjectMetaBuilder, ObjectMetaBuilderError, PodBuilder, + PodSecurityContextBuilder, + }, client::Client, cluster_resources::{ClusterResourceApplyStrategy, ClusterResources}, commons::{ @@ -34,7 +37,7 @@ use stackable_operator::{ runtime::{controller::Action, reflector::ObjectRef}, Resource, ResourceExt, }, - labels::role_group_selector_labels, + kvp::{Label, LabelError, Labels}, logging::controller::ReconcilerError, product_config_utils::{transform_all_roles_to_config, validate_all_roles_and_groups_config}, role_utils::{GenericRoleConfig, RoleGroupRef}, @@ -213,6 +216,12 @@ pub enum Error { #[snafu(display("failed to build roleGroup selector labels"))] RoleGroupSelectorLabels { source: stackable_hdfs_crd::Error }, + + #[snafu(display("failed to build label"))] + BuildLabel { source: LabelError }, + + #[snafu(display("failed to build object meta data"))] + ObjectMeta { source: ObjectMetaBuilderError }, } impl ReconcilerError for Error { @@ -296,7 +305,9 @@ pub async fn reconcile_hdfs(hdfs: Arc, ctx: Arc) -> HdfsOperat let (rbac_sa, rbac_rolebinding) = build_rbac_resources( hdfs.as_ref(), APP_NAME, - cluster_resources.get_required_labels(), + cluster_resources + .get_required_labels() + .context(BuildLabelSnafu)?, ) .context(BuildRbacResourcesSnafu)?; @@ -426,46 +437,55 @@ fn rolegroup_service( resolved_product_image: &ResolvedProductImage, ) -> HdfsOperatorResult { tracing::info!("Setting up Service for {:?}", rolegroup_ref); + + let prometheus_label = + Label::try_from(("prometheus.io/scrape", "true")).context(BuildLabelSnafu)?; + + let metadata = ObjectMetaBuilder::new() + .name_and_namespace(hdfs) + .name(&rolegroup_ref.object_name()) + .ownerreference_from_resource(hdfs, None, Some(true)) + .with_context(|_| ObjectMissingMetadataForOwnerRefSnafu { + obj_ref: ObjectRef::from_obj(hdfs), + })? + .with_recommended_labels(build_recommended_labels( + hdfs, + RESOURCE_MANAGER_HDFS_CONTROLLER, + &resolved_product_image.app_version_label, + &rolegroup_ref.role, + &rolegroup_ref.role_group, + )) + .context(ObjectMetaSnafu)? + .with_label(prometheus_label) + .build(); + + let service_spec = ServiceSpec { + // Internal communication does not need to be exposed + type_: Some("ClusterIP".to_string()), + cluster_ip: Some("None".to_string()), + ports: Some( + hdfs.ports(role) + .into_iter() + .map(|(name, value)| ServicePort { + name: Some(name), + port: i32::from(value), + protocol: Some("TCP".to_string()), + ..ServicePort::default() + }) + .collect(), + ), + selector: Some( + hdfs.rolegroup_selector_labels(rolegroup_ref) + .context(RoleGroupSelectorLabelsSnafu)? + .into(), + ), + publish_not_ready_addresses: Some(true), + ..ServiceSpec::default() + }; + Ok(Service { - metadata: ObjectMetaBuilder::new() - .name_and_namespace(hdfs) - .name(&rolegroup_ref.object_name()) - .ownerreference_from_resource(hdfs, None, Some(true)) - .with_context(|_| ObjectMissingMetadataForOwnerRefSnafu { - obj_ref: ObjectRef::from_obj(hdfs), - })? - .with_recommended_labels(build_recommended_labels( - hdfs, - RESOURCE_MANAGER_HDFS_CONTROLLER, - &resolved_product_image.app_version_label, - &rolegroup_ref.role, - &rolegroup_ref.role_group, - )) - .with_label("prometheus.io/scrape", "true") - .build(), - spec: Some(ServiceSpec { - // Internal communication does not need to be exposed - type_: Some("ClusterIP".to_string()), - cluster_ip: Some("None".to_string()), - ports: Some( - hdfs.ports(role) - .into_iter() - .map(|(name, value)| ServicePort { - name: Some(name), - port: i32::from(value), - protocol: Some("TCP".to_string()), - ..ServicePort::default() - }) - .collect(), - ), - selector: Some( - hdfs.rolegroup_selector_labels(rolegroup_ref) - .context(RoleGroupSelectorLabelsSnafu)? - .into(), - ), - publish_not_ready_addresses: Some(true), - ..ServiceSpec::default() - }), + metadata, + spec: Some(service_spec), status: None, }) } @@ -613,24 +633,25 @@ fn rolegroup_config_map( .map(|(k, v)| (k, Some(v))) .collect(); + let cm_metadata = ObjectMetaBuilder::new() + .name_and_namespace(hdfs) + .name(&rolegroup_ref.object_name()) + .ownerreference_from_resource(hdfs, None, Some(true)) + .with_context(|_| ObjectMissingMetadataForOwnerRefSnafu { + obj_ref: ObjectRef::from_obj(hdfs), + })? + .with_recommended_labels(build_recommended_labels( + hdfs, + RESOURCE_MANAGER_HDFS_CONTROLLER, + &resolved_product_image.app_version_label, + &rolegroup_ref.role, + &rolegroup_ref.role_group, + )) + .context(ObjectMetaSnafu)? + .build(); + builder - .metadata( - ObjectMetaBuilder::new() - .name_and_namespace(hdfs) - .name(&rolegroup_ref.object_name()) - .ownerreference_from_resource(hdfs, None, Some(true)) - .with_context(|_| ObjectMissingMetadataForOwnerRefSnafu { - obj_ref: ObjectRef::from_obj(hdfs), - })? - .with_recommended_labels(build_recommended_labels( - hdfs, - RESOURCE_MANAGER_HDFS_CONTROLLER, - &resolved_product_image.app_version_label, - &rolegroup_ref.role, - &rolegroup_ref.role_group, - )) - .build(), - ) + .metadata(cm_metadata) .add_data(CORE_SITE_XML.to_string(), core_site_xml) .add_data(HDFS_SITE_XML.to_string(), hdfs_site_xml) .add_data(HADOOP_POLICY_XML.to_string(), hadoop_policy_xml) @@ -678,20 +699,27 @@ fn rolegroup_statefulset( let object_name = rolegroup_ref.object_name(); // PodBuilder for StatefulSet Pod template. let mut pb = PodBuilder::new(); - pb.metadata(ObjectMeta { - labels: Some(hdfs.rolegroup_selector_labels(rolegroup_ref)), + + let pb_metadata = ObjectMeta { + labels: Some( + hdfs.rolegroup_selector_labels(rolegroup_ref) + .context(RoleGroupSelectorLabelsSnafu)? + .into(), + ), ..ObjectMeta::default() - }) - .image_pull_secrets_from_product_image(resolved_product_image) - .affinity(merged_config.affinity()) - .service_account_name(service_account_name(APP_NAME)) - .security_context( - PodSecurityContextBuilder::new() - .run_as_user(HDFS_UID) - .run_as_group(0) - .fs_group(1000) - .build(), - ); + }; + + pb.metadata(pb_metadata) + .image_pull_secrets_from_product_image(resolved_product_image) + .affinity(merged_config.affinity()) + .service_account_name(service_account_name(APP_NAME)) + .security_context( + PodSecurityContextBuilder::new() + .run_as_user(HDFS_UID) + .run_as_group(0) + .fs_group(1000) + .build(), + ); // Adds all containers and volumes to the pod builder ContainerConfig::add_containers_and_volumes( @@ -718,42 +746,50 @@ fn rolegroup_statefulset( pod_template.merge_from(pod_overrides.clone()); } + let metadata = ObjectMetaBuilder::new() + .name_and_namespace(hdfs) + .name(&rolegroup_ref.object_name()) + .ownerreference_from_resource(hdfs, None, Some(true)) + .with_context(|_| ObjectMissingMetadataForOwnerRefSnafu { + obj_ref: ObjectRef::from_obj(hdfs), + })? + .with_recommended_labels(build_recommended_labels( + hdfs, + RESOURCE_MANAGER_HDFS_CONTROLLER, + &resolved_product_image.app_version_label, + &rolegroup_ref.role, + &rolegroup_ref.role_group, + )) + .context(ObjectMetaSnafu)? + .build(); + + let match_labels = Labels::role_group_selector( + hdfs, + APP_NAME, + &rolegroup_ref.role, + &rolegroup_ref.role_group, + ) + .context(BuildLabelSnafu)?; + + let statefulset_spec = StatefulSetSpec { + pod_management_policy: Some("OrderedReady".to_string()), + replicas: role + .role_group_replicas(hdfs, &rolegroup_ref.role_group) + .map(i32::from), + selector: LabelSelector { + match_labels: Some(match_labels.into()), + ..LabelSelector::default() + }, + service_name: object_name, + template: pod_template, + + volume_claim_templates: ContainerConfig::volume_claim_templates(role, merged_config), + ..StatefulSetSpec::default() + }; + Ok(StatefulSet { - metadata: ObjectMetaBuilder::new() - .name_and_namespace(hdfs) - .name(&rolegroup_ref.object_name()) - .ownerreference_from_resource(hdfs, None, Some(true)) - .with_context(|_| ObjectMissingMetadataForOwnerRefSnafu { - obj_ref: ObjectRef::from_obj(hdfs), - })? - .with_recommended_labels(build_recommended_labels( - hdfs, - RESOURCE_MANAGER_HDFS_CONTROLLER, - &resolved_product_image.app_version_label, - &rolegroup_ref.role, - &rolegroup_ref.role_group, - )) - .build(), - spec: Some(StatefulSetSpec { - pod_management_policy: Some("OrderedReady".to_string()), - replicas: role - .role_group_replicas(hdfs, &rolegroup_ref.role_group) - .map(i32::from), - selector: LabelSelector { - match_labels: Some(role_group_selector_labels( - hdfs, - APP_NAME, - &rolegroup_ref.role, - &rolegroup_ref.role_group, - )), - ..LabelSelector::default() - }, - service_name: object_name, - template: pod_template, - - volume_claim_templates: ContainerConfig::volume_claim_templates(role, merged_config), - ..StatefulSetSpec::default() - }), + metadata, + spec: Some(statefulset_spec), status: None, }) } From 2d522e03d77178d525e254e20e3739dc41ffdb6d Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Fri, 12 Jan 2024 13:10:32 +0100 Subject: [PATCH 06/31] fix import --- rust/operator-binary/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/operator-binary/src/main.rs b/rust/operator-binary/src/main.rs index ac060338..6aa6ba0f 100644 --- a/rust/operator-binary/src/main.rs +++ b/rust/operator-binary/src/main.rs @@ -12,7 +12,7 @@ use stackable_operator::{ core::v1::{ConfigMap, Pod, Service}, }, kube::runtime::{watcher, Controller}, - labels::ObjectLabels, + kvp::ObjectLabels, logging::controller::report_controller_reconciled, namespace::WatchNamespace, CustomResourceExt, From 9fd5d008b75d6127e486af74556ffc374d45242a Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Fri, 12 Jan 2024 13:53:29 +0100 Subject: [PATCH 07/31] make discover snafu errors --- rust/operator-binary/src/discovery.rs | 59 +++++++++++++++------ rust/operator-binary/src/hdfs_controller.rs | 6 +-- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/rust/operator-binary/src/discovery.rs b/rust/operator-binary/src/discovery.rs index 7f732a0f..6e49a146 100644 --- a/rust/operator-binary/src/discovery.rs +++ b/rust/operator-binary/src/discovery.rs @@ -2,18 +2,38 @@ use crate::{ build_recommended_labels, config::{CoreSiteConfigBuilder, HdfsSiteConfigBuilder}, }; +use snafu::{ResultExt, Snafu}; use stackable_hdfs_crd::{ constants::{CORE_SITE_XML, HDFS_SITE_XML}, HdfsCluster, HdfsPodRef, HdfsRole, }; use stackable_operator::{ - builder::{ConfigMapBuilder, ObjectMetaBuilder}, + builder::{ConfigMapBuilder, ObjectMetaBuilder, ObjectMetaBuilderError}, commons::product_image_selection::ResolvedProductImage, - error::OperatorResult, k8s_openapi::api::core::v1::ConfigMap, - kube::ResourceExt, + kube::{runtime::reflector::ObjectRef, ResourceExt}, }; +type Result = std::result::Result; + +#[derive(Snafu, Debug)] +#[allow(clippy::enum_variant_names)] +pub enum Error { + #[snafu(display("object {hdfs} is missing metadata to build owner reference"))] + ObjectMissingMetadataForOwnerRef { + source: stackable_operator::error::Error, + hdfs: ObjectRef, + }, + + #[snafu(display("failed to build ConfigMap"))] + BuildConfigMap { + source: stackable_operator::error::Error, + }, + + #[snafu(display("failed to build object meta data"))] + ObjectMeta { source: ObjectMetaBuilderError }, +} + /// Creates a discovery config map containing the `hdfs-site.xml` and `core-site.xml` /// for clients. pub fn build_discovery_configmap( @@ -21,21 +41,25 @@ pub fn build_discovery_configmap( controller: &str, namenode_podrefs: &[HdfsPodRef], resolved_product_image: &ResolvedProductImage, -) -> OperatorResult { +) -> Result { + let metadata = ObjectMetaBuilder::new() + .name_and_namespace(hdfs) + .ownerreference_from_resource(hdfs, None, Some(true)) + .context(ObjectMissingMetadataForOwnerRefSnafu { + hdfs: ObjectRef::from_obj(hdfs), + })? + .with_recommended_labels(build_recommended_labels( + hdfs, + controller, + &resolved_product_image.app_version_label, + &HdfsRole::NameNode.to_string(), + "discovery", + )) + .context(ObjectMetaSnafu)? + .build(); + ConfigMapBuilder::new() - .metadata( - ObjectMetaBuilder::new() - .name_and_namespace(hdfs) - .ownerreference_from_resource(hdfs, None, Some(true))? - .with_recommended_labels(build_recommended_labels( - hdfs, - controller, - &resolved_product_image.app_version_label, - &HdfsRole::NameNode.to_string(), - "discovery", - )) - .build(), - ) + .metadata(metadata) .add_data( HDFS_SITE_XML, build_discovery_hdfs_site_xml(hdfs, hdfs.name_any(), namenode_podrefs), @@ -45,6 +69,7 @@ pub fn build_discovery_configmap( build_discovery_core_site_xml(hdfs, hdfs.name_any()), ) .build() + .context(BuildConfigMapSnafu) } fn build_discovery_hdfs_site_xml( diff --git a/rust/operator-binary/src/hdfs_controller.rs b/rust/operator-binary/src/hdfs_controller.rs index 41de1195..5ded5355 100644 --- a/rust/operator-binary/src/hdfs_controller.rs +++ b/rust/operator-binary/src/hdfs_controller.rs @@ -54,7 +54,7 @@ use crate::{ config::{CoreSiteConfigBuilder, HdfsSiteConfigBuilder}, container::ContainerConfig, container::{TLS_STORE_DIR, TLS_STORE_PASSWORD}, - discovery::build_discovery_configmap, + discovery::{self, build_discovery_configmap}, event::{build_invalid_replica_message, publish_event}, kerberos, operations::{ @@ -132,9 +132,7 @@ pub enum Error { }, #[snafu(display("Cannot build config discovery config map"))] - BuildDiscoveryConfigMap { - source: stackable_operator::error::Error, - }, + BuildDiscoveryConfigMap { source: discovery::Error }, #[snafu(display("Failed to patch service account"))] ApplyServiceAccount { From ed073fc4b36c348a863fa8a57829e97b50f44a46 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Mon, 15 Jan 2024 12:04:50 +0100 Subject: [PATCH 08/31] fix volume builders --- rust/operator-binary/src/container.rs | 31 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/rust/operator-binary/src/container.rs b/rust/operator-binary/src/container.rs index 23c5b3fb..003ef3df 100644 --- a/rust/operator-binary/src/container.rs +++ b/rust/operator-binary/src/container.rs @@ -28,18 +28,12 @@ use stackable_hdfs_crd::{ storage::DataNodeStorageConfig, DataNodeContainer, HdfsCluster, HdfsPodRef, HdfsRole, MergedConfig, NameNodeContainer, }; -use stackable_operator::{ - builder::SecretFormat, - product_logging::framework::{ - create_vector_shutdown_file_command, remove_vector_shutdown_file_command, - }, - utils::COMMON_BASH_TRAP_FUNCTIONS, -}; use stackable_operator::{ builder::{ resources::ResourceRequirementsBuilder, ContainerBuilder, PodBuilder, SecretOperatorVolumeSourceBuilder, VolumeBuilder, VolumeMountBuilder, }, + builder::{SecretFormat, SecretOperatorVolumeSourceBuilderError}, commons::product_image_selection::ResolvedProductImage, k8s_openapi::{ api::core::v1::{ @@ -51,6 +45,9 @@ use stackable_operator::{ }, kube::ResourceExt, memory::{BinaryMultiple, MemoryQuantity}, + product_logging::framework::{ + create_vector_shutdown_file_command, remove_vector_shutdown_file_command, + }, product_logging::{ self, spec::{ @@ -58,6 +55,7 @@ use stackable_operator::{ CustomContainerLogConfig, }, }, + utils::COMMON_BASH_TRAP_FUNCTIONS, }; use std::{collections::BTreeMap, str::FromStr}; use strum::{Display, EnumDiscriminants, IntoStaticStr}; @@ -65,6 +63,7 @@ use strum::{Display, EnumDiscriminants, IntoStaticStr}; pub(crate) const TLS_STORE_DIR: &str = "/stackable/tls"; pub(crate) const TLS_STORE_VOLUME_NAME: &str = "tls"; pub(crate) const TLS_STORE_PASSWORD: &str = "changeit"; +pub(crate) const KERBEROS_VOLUME_NAME: &str = "kerberos"; #[derive(Snafu, Debug, EnumDiscriminants)] #[strum_discriminants(derive(IntoStaticStr))] @@ -83,6 +82,12 @@ pub enum Error { source: stackable_operator::error::Error, name: String, }, + + #[snafu(display("failed to build secret volume for {volume_name:?}"))] + BuildSecretVolume { + source: SecretOperatorVolumeSourceBuilderError, + volume_name: String, + }, } /// ContainerConfig contains information to create all main, side and init containers for @@ -198,13 +203,16 @@ impl ContainerConfig { .with_node_scope() .with_format(SecretFormat::TlsPkcs12) .with_tls_pkcs12_password(TLS_STORE_PASSWORD) - .build(), + .build() + .context(BuildSecretVolumeSnafu { + volume_name: TLS_STORE_VOLUME_NAME, + })?, ) .build(), ); pb.add_volume( - VolumeBuilder::new("kerberos") + VolumeBuilder::new(KERBEROS_VOLUME_NAME) .ephemeral( SecretOperatorVolumeSourceBuilder::new( &authentication_config.kerberos.secret_class, @@ -212,7 +220,10 @@ impl ContainerConfig { .with_service_scope(hdfs.name_any()) .with_kerberos_service_name(role.kerberos_service_name()) .with_kerberos_service_name("HTTP") - .build(), + .build() + .context(BuildSecretVolumeSnafu { + volume_name: KERBEROS_VOLUME_NAME, + })?, ) .build(), ); From f57e14047c912154b5922d49b59b914b02d4a3b1 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Mon, 15 Jan 2024 12:31:13 +0100 Subject: [PATCH 09/31] bump operator-rs for kvp goodies --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0cc7a4b2..6532365d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1969,8 +1969,8 @@ dependencies = [ [[package]] name = "stackable-operator" -version = "0.60.1" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.60.1#21f98e8937dac924e374b54bd6ea1d7b2367ca69" +version = "0.61.0" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.61.0#ddc57addbc741e3977b1589e553164505a59f639" dependencies = [ "chrono", "clap", @@ -2008,8 +2008,8 @@ dependencies = [ [[package]] name = "stackable-operator-derive" -version = "0.60.1" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.60.1#21f98e8937dac924e374b54bd6ea1d7b2367ca69" +version = "0.61.0" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.61.0#ddc57addbc741e3977b1589e553164505a59f639" dependencies = [ "darling", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 43cd02df..5df922e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_yaml = "0.9" snafu = "0.7" -stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.60.1" } +stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.61.0" } product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.6.0" } strum = { version = "0.25", features = ["derive"] } tokio = { version = "1.29", features = ["full"] } From 02970bf52131d1fa541674a09d94cb7237382e0e Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Tue, 16 Jan 2024 10:35:26 +0100 Subject: [PATCH 10/31] upgrade rust to 1.75.0 --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 639f4f17..7897a24d 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.74.0" +channel = "1.75.0" From d4d9ddbf763498520c43b659dccbb3b799124284 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Tue, 16 Jan 2024 14:17:12 +0100 Subject: [PATCH 11/31] fix the label filter/map --- .../operator-binary/src/pod_svc_controller.rs | 79 +++++++++++-------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/rust/operator-binary/src/pod_svc_controller.rs b/rust/operator-binary/src/pod_svc_controller.rs index dc9af76f..51061766 100644 --- a/rust/operator-binary/src/pod_svc_controller.rs +++ b/rust/operator-binary/src/pod_svc_controller.rs @@ -8,12 +8,15 @@ use stackable_operator::{ builder::ObjectMetaBuilder, k8s_openapi::api::core::v1::{Pod, Service, ServicePort, ServiceSpec}, kube::runtime::controller::Action, + kvp::{LabelError, Labels}, logging::controller::ReconcilerError, time::Duration, }; use std::sync::Arc; use strum::{EnumDiscriminants, IntoStaticStr}; +type Result = std::result::Result; + #[derive(Snafu, Debug, EnumDiscriminants)] #[strum_discriminants(derive(IntoStaticStr))] pub enum Error { @@ -33,6 +36,9 @@ pub enum Error { source: stackable_operator::error::Error, name: String, }, + + #[snafu(display("failed to build label"))] + BuildLabel { source: LabelError }, } impl ReconcilerError for Error { @@ -47,21 +53,28 @@ pub struct Ctx { const APP_KUBERNETES_LABEL_BASE: &str = "app.kubernetes.io/"; -pub async fn reconcile_pod(pod: Arc, ctx: Arc) -> Result { +pub async fn reconcile_pod(pod: Arc, ctx: Arc) -> Result { tracing::info!("Starting reconcile"); let name = pod.metadata.name.clone().context(PodHasNoNameSnafu)?; - let pod_labels = pod - .metadata - .labels - .as_ref() - .with_context(|| PodHasNoLabelsSnafu { name: name.clone() })?; + let pod_labels = Labels::try_from( + pod.metadata + .labels + .as_ref() + .with_context(|| PodHasNoLabelsSnafu { name: name.clone() })?, + ) + .context(BuildLabelSnafu)?; let recommended_labels_from_pod = pod_labels .iter() - .filter(|(key, _)| key.starts_with(APP_KUBERNETES_LABEL_BASE)) - .map(|(key, value)| (key.clone(), value.clone())) + .filter(|&label| { + label + .key() + .prefix() + .is_some_and(|prefix| *prefix == APP_KUBERNETES_LABEL_BASE) + }) + .map(|label| label.clone()) .collect(); let ports: Vec<(String, i32)> = pod @@ -80,30 +93,34 @@ pub async fn reconcile_pod(pod: Arc, ctx: Arc) -> Result Date: Fri, 19 Jan 2024 15:55:39 +0100 Subject: [PATCH 12/31] bump operator-rs to 0.62.0 for labels iterator functionality (in previous commits) --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6532365d..5afc0b99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1969,8 +1969,8 @@ dependencies = [ [[package]] name = "stackable-operator" -version = "0.61.0" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.61.0#ddc57addbc741e3977b1589e553164505a59f639" +version = "0.62.0" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.62.0#407cfec12469dba32ac1795a9ce7e62077a0650b" dependencies = [ "chrono", "clap", @@ -2008,8 +2008,8 @@ dependencies = [ [[package]] name = "stackable-operator-derive" -version = "0.61.0" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.61.0#ddc57addbc741e3977b1589e553164505a59f639" +version = "0.62.0" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.62.0#407cfec12469dba32ac1795a9ce7e62077a0650b" dependencies = [ "darling", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 5df922e0..9db85aa7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_yaml = "0.9" snafu = "0.7" -stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.61.0" } +stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.62.0" } product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.6.0" } strum = { version = "0.25", features = ["derive"] } tokio = { version = "1.29", features = ["full"] } From 883ed0c0f859ec1ad614fc030f7f78f136190a3c Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Fri, 19 Jan 2024 16:03:40 +0100 Subject: [PATCH 13/31] style: convert enum variants with comments/attributes to blocks (only for the enums that was touched in this PR) --- rust/crd/src/lib.rs | 3 +++ rust/operator-binary/src/container.rs | 3 +++ rust/operator-binary/src/operations/pdb.rs | 1 + rust/operator-binary/src/pod_svc_controller.rs | 4 ++++ rust/operator-binary/src/product_logging.rs | 3 +++ 5 files changed, 14 insertions(+) diff --git a/rust/crd/src/lib.rs b/rust/crd/src/lib.rs index 04131ec3..4944cc61 100644 --- a/rust/crd/src/lib.rs +++ b/rust/crd/src/lib.rs @@ -52,10 +52,13 @@ type Result = std::result::Result; pub enum Error { #[snafu(display("Object has no associated namespace"))] NoNamespace, + #[snafu(display("Missing node role [{role}]"))] MissingRole { role: String }, + #[snafu(display("Missing role group [{role_group}] for role [{role}]"))] MissingRoleGroup { role: String, role_group: String }, + #[snafu(display("fragment validation failure"))] FragmentValidationFailure { source: ValidationError }, diff --git a/rust/operator-binary/src/container.rs b/rust/operator-binary/src/container.rs index 003ef3df..44190b57 100644 --- a/rust/operator-binary/src/container.rs +++ b/rust/operator-binary/src/container.rs @@ -70,13 +70,16 @@ pub(crate) const KERBEROS_VOLUME_NAME: &str = "kerberos"; pub enum Error { #[snafu(display("object has no namespace"))] ObjectHasNoNamespace, + #[snafu(display("Invalid java heap config for [{role}]"))] InvalidJavaHeapConfig { source: stackable_operator::error::Error, role: String, }, + #[snafu(display("Could not determine any ContainerConfig actions for [{container_name}]. Container not recognized."))] UnrecognizedContainerName { container_name: String }, + #[snafu(display("Invalid container name [{name}]"))] InvalidContainerName { source: stackable_operator::error::Error, diff --git a/rust/operator-binary/src/operations/pdb.rs b/rust/operator-binary/src/operations/pdb.rs index b9a82cbc..e49c1a76 100644 --- a/rust/operator-binary/src/operations/pdb.rs +++ b/rust/operator-binary/src/operations/pdb.rs @@ -16,6 +16,7 @@ pub enum Error { source: stackable_operator::error::Error, role: String, }, + #[snafu(display("Cannot apply role group PodDisruptionBudget [{name}]"))] ApplyPdb { source: stackable_operator::error::Error, diff --git a/rust/operator-binary/src/pod_svc_controller.rs b/rust/operator-binary/src/pod_svc_controller.rs index 51061766..6b002a35 100644 --- a/rust/operator-binary/src/pod_svc_controller.rs +++ b/rust/operator-binary/src/pod_svc_controller.rs @@ -22,15 +22,19 @@ type Result = std::result::Result; pub enum Error { #[snafu(display("Pod has no name"))] PodHasNoName, + #[snafu(display("Pod [{name}] has no labels"))] PodHasNoLabels { name: String }, + #[snafu(display("Pod [{name}] has no spec"))] PodHasNoSpec { name: String }, + #[snafu(display("Failed to build owner reference of pod [{name}]"))] PodOwnerReference { source: stackable_operator::error::Error, name: String, }, + #[snafu(display("Cannot create pod service [{name}]"))] ApplyPodServiceFailed { source: stackable_operator::error::Error, diff --git a/rust/operator-binary/src/product_logging.rs b/rust/operator-binary/src/product_logging.rs index a88cb949..ba69cca2 100644 --- a/rust/operator-binary/src/product_logging.rs +++ b/rust/operator-binary/src/product_logging.rs @@ -17,16 +17,19 @@ use stackable_operator::{ pub enum Error { #[snafu(display("object has no namespace"))] ObjectHasNoNamespace, + #[snafu(display("failed to retrieve the ConfigMap [{cm_name}]"))] ConfigMapNotFound { source: stackable_operator::error::Error, cm_name: String, }, + #[snafu(display("failed to retrieve the entry [{entry}] for ConfigMap [{cm_name}]"))] MissingConfigMapEntry { entry: &'static str, cm_name: String, }, + #[snafu(display("vectorAggregatorConfigMapName must be set"))] MissingVectorAggregatorAddress, } From 825348a14629fa4774cdcbb410e06e78d158772a Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Mon, 22 Jan 2024 10:38:00 +0100 Subject: [PATCH 14/31] style: reorder imorts (only for the enums that was touched in this PR) --- rust/operator-binary/src/container.rs | 15 ++++++++------- rust/operator-binary/src/discovery.rs | 9 +++++---- rust/operator-binary/src/pod_svc_controller.rs | 3 ++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/rust/operator-binary/src/container.rs b/rust/operator-binary/src/container.rs index 44190b57..7d3cdbf1 100644 --- a/rust/operator-binary/src/container.rs +++ b/rust/operator-binary/src/container.rs @@ -9,12 +9,7 @@ //! - Set resources //! - Add tcp probes and container ports (to the main containers) //! -use crate::product_logging::{ - FORMAT_NAMENODES_LOG4J_CONFIG_FILE, FORMAT_ZOOKEEPER_LOG4J_CONFIG_FILE, HDFS_LOG4J_CONFIG_FILE, - MAX_FORMAT_NAMENODE_LOG_FILE_SIZE, MAX_FORMAT_ZOOKEEPER_LOG_FILE_SIZE, MAX_HDFS_LOG_FILE_SIZE, - MAX_WAIT_NAMENODES_LOG_FILE_SIZE, MAX_ZKFC_LOG_FILE_SIZE, STACKABLE_LOG_DIR, - WAIT_FOR_NAMENODES_LOG4J_CONFIG_FILE, ZKFC_LOG4J_CONFIG_FILE, -}; +use std::{collections::BTreeMap, str::FromStr}; use indoc::formatdoc; use snafu::{OptionExt, ResultExt, Snafu}; @@ -57,9 +52,15 @@ use stackable_operator::{ }, utils::COMMON_BASH_TRAP_FUNCTIONS, }; -use std::{collections::BTreeMap, str::FromStr}; use strum::{Display, EnumDiscriminants, IntoStaticStr}; +use crate::product_logging::{ + FORMAT_NAMENODES_LOG4J_CONFIG_FILE, FORMAT_ZOOKEEPER_LOG4J_CONFIG_FILE, HDFS_LOG4J_CONFIG_FILE, + MAX_FORMAT_NAMENODE_LOG_FILE_SIZE, MAX_FORMAT_ZOOKEEPER_LOG_FILE_SIZE, MAX_HDFS_LOG_FILE_SIZE, + MAX_WAIT_NAMENODES_LOG_FILE_SIZE, MAX_ZKFC_LOG_FILE_SIZE, STACKABLE_LOG_DIR, + WAIT_FOR_NAMENODES_LOG4J_CONFIG_FILE, ZKFC_LOG4J_CONFIG_FILE, +}; + pub(crate) const TLS_STORE_DIR: &str = "/stackable/tls"; pub(crate) const TLS_STORE_VOLUME_NAME: &str = "tls"; pub(crate) const TLS_STORE_PASSWORD: &str = "changeit"; diff --git a/rust/operator-binary/src/discovery.rs b/rust/operator-binary/src/discovery.rs index 6e49a146..b7922499 100644 --- a/rust/operator-binary/src/discovery.rs +++ b/rust/operator-binary/src/discovery.rs @@ -1,7 +1,3 @@ -use crate::{ - build_recommended_labels, - config::{CoreSiteConfigBuilder, HdfsSiteConfigBuilder}, -}; use snafu::{ResultExt, Snafu}; use stackable_hdfs_crd::{ constants::{CORE_SITE_XML, HDFS_SITE_XML}, @@ -14,6 +10,11 @@ use stackable_operator::{ kube::{runtime::reflector::ObjectRef, ResourceExt}, }; +use crate::{ + build_recommended_labels, + config::{CoreSiteConfigBuilder, HdfsSiteConfigBuilder}, +}; + type Result = std::result::Result; #[derive(Snafu, Debug)] diff --git a/rust/operator-binary/src/pod_svc_controller.rs b/rust/operator-binary/src/pod_svc_controller.rs index 6b002a35..fc3a8fe3 100644 --- a/rust/operator-binary/src/pod_svc_controller.rs +++ b/rust/operator-binary/src/pod_svc_controller.rs @@ -1,6 +1,8 @@ //! NodePort controller for exposing individual Pods. //! //! For pods with the label `hdfs.stackable.tech/pod-service=true` a NodePort is created that exposes the local node pod. +use std::sync::Arc; + use snafu::{OptionExt, ResultExt, Snafu}; use stackable_hdfs_crd::constants::*; use stackable_hdfs_crd::HdfsRole; @@ -12,7 +14,6 @@ use stackable_operator::{ logging::controller::ReconcilerError, time::Duration, }; -use std::sync::Arc; use strum::{EnumDiscriminants, IntoStaticStr}; type Result = std::result::Result; From 4a95bb458220e2edb5ee01862caa085128139e31 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Mon, 22 Jan 2024 10:38:36 +0100 Subject: [PATCH 15/31] use cloned instead of map --- rust/operator-binary/src/pod_svc_controller.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/operator-binary/src/pod_svc_controller.rs b/rust/operator-binary/src/pod_svc_controller.rs index fc3a8fe3..54cd5538 100644 --- a/rust/operator-binary/src/pod_svc_controller.rs +++ b/rust/operator-binary/src/pod_svc_controller.rs @@ -79,7 +79,7 @@ pub async fn reconcile_pod(pod: Arc, ctx: Arc) -> Result { .prefix() .is_some_and(|prefix| *prefix == APP_KUBERNETES_LABEL_BASE) }) - .map(|label| label.clone()) + .cloned() .collect(); let ports: Vec<(String, i32)> = pod From 19bc72eab43531fdc032379fa87c664a040ffcdb Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Mon, 22 Jan 2024 10:45:57 +0100 Subject: [PATCH 16/31] update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ac840ae..820e0146 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,8 +11,14 @@ All notable changes to this project will be documented in this file. ### Changed - `operator-rs` `0.56.1` -> `0.57.0` ([#433]). +- Use new label builders ([#454]). + +### Removed + +- [BREAKING] Removed legacy node selector on roleGroups ([#454]). [#433]: https://github.com/stackabletech/hdfs-operator/pull/433 +[#454]: https://github.com/stackabletech/hdfs-operator/pull/454 ## [23.11.0] - 2023-11-24 From 78567cd78f1d8279be384a48aad6db609d58afb5 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Mon, 22 Jan 2024 10:50:53 +0100 Subject: [PATCH 17/31] use new parse_insert method --- rust/crd/src/lib.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/rust/crd/src/lib.rs b/rust/crd/src/lib.rs index 4944cc61..f44dd07d 100644 --- a/rust/crd/src/lib.rs +++ b/rust/crd/src/lib.rs @@ -408,14 +408,12 @@ impl HdfsCluster { &rolegroup_ref.role_group, ) .context(BuildLabelSnafu)?; - group_labels.insert( - Label::try_from((String::from("role"), rolegroup_ref.role.clone())) - .context(BuildLabelSnafu)?, - ); - group_labels.insert( - Label::try_from((String::from("group"), rolegroup_ref.role_group.clone())) - .context(BuildLabelSnafu)?, - ); + group_labels + .parse_insert((String::from("role"), rolegroup_ref.role.clone())) + .context(BuildLabelSnafu)?; + group_labels + .parse_insert((String::from("group"), rolegroup_ref.role_group.clone())) + .context(BuildLabelSnafu)?; if self.spec.cluster_config.listener_class == CurrentlySupportedListenerClasses::ExternalUnstable @@ -423,10 +421,9 @@ impl HdfsCluster { // TODO: in a production environment, probably not all roles need to be exposed with one NodePort per Pod but it's // useful for development purposes. - group_labels.insert( - Label::try_from((LABEL_ENABLE.to_string(), "true".to_string())) - .context(BuildLabelSnafu)?, - ); + group_labels + .parse_insert((LABEL_ENABLE.to_string(), "true".to_string())) + .context(BuildLabelSnafu)?; } Ok(group_labels) From 6a3095f64f3b7ebb467bc2d5aadd6236500c1f7c Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Mon, 22 Jan 2024 12:54:12 +0100 Subject: [PATCH 18/31] fix error handling after merge --- rust/crd/src/lib.rs | 2 +- rust/operator-binary/src/hdfs_controller.rs | 20 +++++++------ rust/operator-binary/src/kerberos.rs | 33 ++++++++++++--------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/rust/crd/src/lib.rs b/rust/crd/src/lib.rs index 529c98c2..60cb2b8a 100644 --- a/rust/crd/src/lib.rs +++ b/rust/crd/src/lib.rs @@ -20,7 +20,7 @@ use stackable_operator::{ }, k8s_openapi::{api::core::v1::PodTemplateSpec, apimachinery::pkg::api::resource::Quantity}, kube::{runtime::reflector::ObjectRef, CustomResource, ResourceExt}, - kvp::{Label, LabelError, Labels}, + kvp::{LabelError, Labels}, product_config_utils::{ConfigError, Configuration}, product_logging, product_logging::spec::{ContainerLogConfig, Logging}, diff --git a/rust/operator-binary/src/hdfs_controller.rs b/rust/operator-binary/src/hdfs_controller.rs index b12ca1c1..58033226 100644 --- a/rust/operator-binary/src/hdfs_controller.rs +++ b/rust/operator-binary/src/hdfs_controller.rs @@ -121,9 +121,6 @@ pub enum Error { #[snafu(display("Object has no name"))] ObjectHasNoName { obj_ref: ObjectRef }, - #[snafu(display("Object has no namespace"))] - ObjectHasNoNamespace { obj_ref: ObjectRef }, - #[snafu(display("Cannot build config map for role [{role}] and role group [{role_group}]"))] BuildRoleGroupConfigMap { source: stackable_operator::error::Error, @@ -218,8 +215,11 @@ pub enum Error { #[snafu(display("failed to build label"))] BuildLabel { source: LabelError }, - #[snafu(display("failed to build object meta data"))] + #[snafu(display("failed to build object meta data"))] ObjectMeta { source: ObjectMetaBuilderError }, + + #[snafu(display("failed to build security config"))] + Xxx { source: kerberos::Error }, } impl ReconcilerError for Error { @@ -243,8 +243,8 @@ pub async fn reconcile_hdfs(hdfs: Arc, ctx: Arc) -> HdfsOperat .spec .image .resolve(DOCKER_IMAGE_BASE_NAME, crate::built_info::CARGO_PKG_VERSION); - if hdfs.has_kerberos_enabled() { - kerberos::check_if_supported(&resolved_product_image)?; + if hdfs.has_kerberos_enabled() && kerberos::check_if_supported(&resolved_product_image) { + return KerberosNotSupportedSnafu.fail(); } let vector_aggregator_address = resolve_vector_aggregator_address(&hdfs, client) @@ -287,7 +287,8 @@ pub async fn reconcile_hdfs(hdfs: Arc, ctx: Arc) -> HdfsOperat HDFS_CONTROLLER, &namenode_podrefs, &resolved_product_image, - )?; + ) + .context(BuildDiscoveryConfigMapSnafu)?; // The discovery CM is linked to the cluster lifecycle via ownerreference. // Therefore, must not be added to the "orphaned" cluster resources @@ -442,7 +443,7 @@ fn rolegroup_service( .name_and_namespace(hdfs) .name(&rolegroup_ref.object_name()) .ownerreference_from_resource(hdfs, None, Some(true)) - .with_context(|_| ObjectMissingMetadataForOwnerRefSnafu { + .context(ObjectMissingMetadataForOwnerRefSnafu { obj_ref: ObjectRef::from_obj(hdfs), })? .with_recommended_labels(build_recommended_labels( @@ -552,7 +553,8 @@ fn rolegroup_config_map( core_site_xml = CoreSiteConfigBuilder::new(hdfs_name.to_string()) .fs_default_fs() .ha_zookeeper_quorum() - .security_config(hdfs)? + .security_config(hdfs) + .context(XxxSnafu)? // the extend with config must come last in order to have overrides working!!! .extend(config) .build_as_xml(); diff --git a/rust/operator-binary/src/kerberos.rs b/rust/operator-binary/src/kerberos.rs index d36463cc..eb02b2ab 100644 --- a/rust/operator-binary/src/kerberos.rs +++ b/rust/operator-binary/src/kerberos.rs @@ -1,3 +1,4 @@ +use snafu::{ResultExt, Snafu}; use stackable_hdfs_crd::{ constants::{SSL_CLIENT_XML, SSL_SERVER_XML}, HdfsCluster, @@ -7,21 +8,25 @@ use stackable_operator::{ kube::{runtime::reflector::ObjectRef, ResourceExt}, }; -use crate::{ - config::{CoreSiteConfigBuilder, HdfsSiteConfigBuilder}, - hdfs_controller::Error, -}; +use crate::config::{CoreSiteConfigBuilder, HdfsSiteConfigBuilder}; -pub fn check_if_supported(resolved_product_image: &ResolvedProductImage) -> Result<(), Error> { - // We only support Kerberos for HDFS >= 3.3.x - // With HDFS 3.2.2 we got weird errors, which *might* be caused by DNS lookup issues - // The Stacktrace is documented in rust/operator/src/kerberos_hdfs_3.2_stacktrace.txt +type Result = std::result::Result; - if resolved_product_image.product_version.starts_with("3.2.") { - Err(Error::KerberosNotSupported {}) - } else { - Ok(()) - } +#[derive(Snafu, Debug)] +#[allow(clippy::enum_variant_names)] +pub enum Error { + #[snafu(display("Object has no namespace"))] + ObjectHasNoNamespace { + source: stackable_hdfs_crd::Error, + obj_ref: ObjectRef, + }, +} + +/// We only support Kerberos for HDFS >= 3.3.x +/// With HDFS 3.2.2 we got weird errors, which *might* be caused by DNS lookup issues +/// The Stacktrace is documented in rust/operator/src/kerberos_hdfs_3.2_stacktrace.txt +pub fn check_if_supported(resolved_product_image: &ResolvedProductImage) -> bool { + resolved_product_image.product_version.starts_with("3.2.") } impl HdfsSiteConfigBuilder { @@ -151,7 +156,7 @@ fn principal_host_part(hdfs: &HdfsCluster) -> Result { let hdfs_name = hdfs.name_any(); let hdfs_namespace = hdfs .namespace_or_error() - .map_err(|_| Error::ObjectHasNoNamespace { + .context(ObjectHasNoNamespaceSnafu { obj_ref: ObjectRef::from_obj(hdfs), })?; Ok(format!( From 30d975229ae8189ee388c6261331e7cb8d4e268a Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Mon, 22 Jan 2024 13:00:05 +0100 Subject: [PATCH 19/31] use module Result typedef for module level errors --- rust/operator-binary/src/kerberos.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rust/operator-binary/src/kerberos.rs b/rust/operator-binary/src/kerberos.rs index eb02b2ab..09064579 100644 --- a/rust/operator-binary/src/kerberos.rs +++ b/rust/operator-binary/src/kerberos.rs @@ -60,7 +60,7 @@ impl HdfsSiteConfigBuilder { } impl CoreSiteConfigBuilder { - pub fn security_config(&mut self, hdfs: &HdfsCluster) -> Result<&mut Self, Error> { + pub fn security_config(&mut self, hdfs: &HdfsCluster) -> Result<&mut Self> { if hdfs.authentication_config().is_some() { let principal_host_part = principal_host_part(hdfs)?; @@ -111,7 +111,7 @@ impl CoreSiteConfigBuilder { Ok(self) } - pub fn security_discovery_config(&mut self, hdfs: &HdfsCluster) -> Result<&mut Self, Error> { + pub fn security_discovery_config(&mut self, hdfs: &HdfsCluster) -> Result<&mut Self> { if hdfs.has_kerberos_enabled() { let principal_host_part = principal_host_part(hdfs)?; @@ -152,7 +152,7 @@ impl CoreSiteConfigBuilder { /// ``` /// /// After we have switched to using the following principals everything worked without problems -fn principal_host_part(hdfs: &HdfsCluster) -> Result { +fn principal_host_part(hdfs: &HdfsCluster) -> Result { let hdfs_name = hdfs.name_any(); let hdfs_namespace = hdfs .namespace_or_error() From 084689e4b416b27511205bd4773b7542ac3c0575 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Mon, 22 Jan 2024 13:05:33 +0100 Subject: [PATCH 20/31] make regenerate-charts --- deploy/helm/hdfs-operator/crds/crds.yaml | 99 +----------------------- 1 file changed, 3 insertions(+), 96 deletions(-) diff --git a/deploy/helm/hdfs-operator/crds/crds.yaml b/deploy/helm/hdfs-operator/crds/crds.yaml index 5784ceb5..13a8b6dc 100644 --- a/deploy/helm/hdfs-operator/crds/crds.yaml +++ b/deploy/helm/hdfs-operator/crds/crds.yaml @@ -97,7 +97,7 @@ spec: type: boolean type: object dataNodes: - description: This struct represents a role - e.g. HDFS datanodes or Trino workers. It has a [`HashMap`] containing all the roleGroups that are part of this role. Additionally, there is a `config`, which is configurable at the role *and* roleGroup level. Everything at roleGroup level is merged on top of what is configured on role level using the [`Merge`] trait. There is also a second form of config, which can only be configured at role level, the `roleConfig`. + description: This struct represents a role - e.g. HDFS datanodes or Trino workers. It has a key-value-map containing all the roleGroups that are part of this role. Additionally, there is a `config`, which is configurable at the role *and* roleGroup level. Everything at roleGroup level is merged on top of what is configured on role level. There is also a second form of config, which can only be configured at role level, the `roleConfig`. You can learn more about this in the [Roles and role group concept documentation](https://docs.stackable.tech/home/nightly/concepts/roles-and-role-groups). nullable: true properties: cliOverrides: @@ -7086,37 +7086,6 @@ spec: minimum: 0.0 nullable: true type: integer - selector: - description: A label selector is a label query over a set of resources. The result of matchLabels and matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects. - nullable: true - properties: - matchExpressions: - description: matchExpressions is a list of label selector requirements. The requirements are ANDed. - items: - description: A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. - properties: - key: - description: key is the label key that the selector applies to. - type: string - operator: - description: operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist. - type: string - values: - description: values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. - items: - type: string - type: array - required: - - key - - operator - type: object - type: array - matchLabels: - additionalProperties: - type: string - description: matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed. - type: object - type: object type: object type: object required: @@ -7169,7 +7138,7 @@ spec: type: string type: object journalNodes: - description: This struct represents a role - e.g. HDFS datanodes or Trino workers. It has a [`HashMap`] containing all the roleGroups that are part of this role. Additionally, there is a `config`, which is configurable at the role *and* roleGroup level. Everything at roleGroup level is merged on top of what is configured on role level using the [`Merge`] trait. There is also a second form of config, which can only be configured at role level, the `roleConfig`. + description: This struct represents a role - e.g. HDFS datanodes or Trino workers. It has a key-value-map containing all the roleGroups that are part of this role. Additionally, there is a `config`, which is configurable at the role *and* roleGroup level. Everything at roleGroup level is merged on top of what is configured on role level. There is also a second form of config, which can only be configured at role level, the `roleConfig`. You can learn more about this in the [Roles and role group concept documentation](https://docs.stackable.tech/home/nightly/concepts/roles-and-role-groups). nullable: true properties: cliOverrides: @@ -14140,44 +14109,13 @@ spec: minimum: 0.0 nullable: true type: integer - selector: - description: A label selector is a label query over a set of resources. The result of matchLabels and matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects. - nullable: true - properties: - matchExpressions: - description: matchExpressions is a list of label selector requirements. The requirements are ANDed. - items: - description: A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. - properties: - key: - description: key is the label key that the selector applies to. - type: string - operator: - description: operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist. - type: string - values: - description: values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. - items: - type: string - type: array - required: - - key - - operator - type: object - type: array - matchLabels: - additionalProperties: - type: string - description: matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed. - type: object - type: object type: object type: object required: - roleGroups type: object nameNodes: - description: This struct represents a role - e.g. HDFS datanodes or Trino workers. It has a [`HashMap`] containing all the roleGroups that are part of this role. Additionally, there is a `config`, which is configurable at the role *and* roleGroup level. Everything at roleGroup level is merged on top of what is configured on role level using the [`Merge`] trait. There is also a second form of config, which can only be configured at role level, the `roleConfig`. + description: This struct represents a role - e.g. HDFS datanodes or Trino workers. It has a key-value-map containing all the roleGroups that are part of this role. Additionally, there is a `config`, which is configurable at the role *and* roleGroup level. Everything at roleGroup level is merged on top of what is configured on role level. There is also a second form of config, which can only be configured at role level, the `roleConfig`. You can learn more about this in the [Roles and role group concept documentation](https://docs.stackable.tech/home/nightly/concepts/roles-and-role-groups). nullable: true properties: cliOverrides: @@ -21148,37 +21086,6 @@ spec: minimum: 0.0 nullable: true type: integer - selector: - description: A label selector is a label query over a set of resources. The result of matchLabels and matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects. - nullable: true - properties: - matchExpressions: - description: matchExpressions is a list of label selector requirements. The requirements are ANDed. - items: - description: A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. - properties: - key: - description: key is the label key that the selector applies to. - type: string - operator: - description: operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist. - type: string - values: - description: values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. - items: - type: string - type: array - required: - - key - - operator - type: object - type: array - matchLabels: - additionalProperties: - type: string - description: matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed. - type: object - type: object type: object type: object required: From 5c0aa6375a05f0941c6d668ea09b28b15452c619 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Mon, 22 Jan 2024 13:22:06 +0100 Subject: [PATCH 21/31] ci: upgrade toolchain (stackabletech/operator-templating#310) --- .github/workflows/build.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5bec00c0..a37f9031 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,7 +44,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: recursive - - uses: dtolnay/rust-toolchain@1.74.0 + - uses: dtolnay/rust-toolchain@1.75.0 - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 with: key: udeps @@ -122,7 +122,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: recursive - - uses: dtolnay/rust-toolchain@1.74.0 + - uses: dtolnay/rust-toolchain@1.75.0 with: components: rustfmt - run: cargo fmt --all -- --check @@ -139,7 +139,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: recursive - - uses: dtolnay/rust-toolchain@1.74.0 + - uses: dtolnay/rust-toolchain@1.75.0 with: components: clippy - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 @@ -174,7 +174,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: recursive - - uses: dtolnay/rust-toolchain@1.74.0 + - uses: dtolnay/rust-toolchain@1.75.0 with: components: rustfmt - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 @@ -195,7 +195,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: recursive - - uses: dtolnay/rust-toolchain@1.74.0 + - uses: dtolnay/rust-toolchain@1.75.0 - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 with: key: test @@ -258,7 +258,7 @@ jobs: with: version: v3.13.3 - name: Set up cargo - uses: dtolnay/rust-toolchain@1.74.0 + uses: dtolnay/rust-toolchain@1.75.0 - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 with: key: charts @@ -318,7 +318,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: recursive - - uses: dtolnay/rust-toolchain@1.74.0 + - uses: dtolnay/rust-toolchain@1.75.0 with: components: rustfmt # This step checks if the current run was triggered by a push to a pr (or a pr being created). From ee4331ce9f6782873ea6d734ffca96201629827a Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Mon, 22 Jan 2024 13:27:40 +0100 Subject: [PATCH 22/31] fix poor error variant name --- rust/operator-binary/src/hdfs_controller.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/operator-binary/src/hdfs_controller.rs b/rust/operator-binary/src/hdfs_controller.rs index 58033226..2a539178 100644 --- a/rust/operator-binary/src/hdfs_controller.rs +++ b/rust/operator-binary/src/hdfs_controller.rs @@ -219,7 +219,7 @@ pub enum Error { ObjectMeta { source: ObjectMetaBuilderError }, #[snafu(display("failed to build security config"))] - Xxx { source: kerberos::Error }, + BuildSecurityConfig { source: kerberos::Error }, } impl ReconcilerError for Error { @@ -554,7 +554,7 @@ fn rolegroup_config_map( .fs_default_fs() .ha_zookeeper_quorum() .security_config(hdfs) - .context(XxxSnafu)? + .context(BuildSecurityConfigSnafu)? // the extend with config must come last in order to have overrides working!!! .extend(config) .build_as_xml(); From f2d4333aced89e2136f366b51edf71f0848fea91 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 23 Jan 2024 11:11:37 +0100 Subject: [PATCH 23/31] Apply suggestions from code review Co-authored-by: Natalie --- rust/operator-binary/src/kerberos.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/operator-binary/src/kerberos.rs b/rust/operator-binary/src/kerberos.rs index 09064579..a0183ae5 100644 --- a/rust/operator-binary/src/kerberos.rs +++ b/rust/operator-binary/src/kerberos.rs @@ -156,7 +156,7 @@ fn principal_host_part(hdfs: &HdfsCluster) -> Result { let hdfs_name = hdfs.name_any(); let hdfs_namespace = hdfs .namespace_or_error() - .context(ObjectHasNoNamespaceSnafu { + .with_context(|_| ObjectHasNoNamespaceSnafu { obj_ref: ObjectRef::from_obj(hdfs), })?; Ok(format!( From 6bf0af7e90a49c6f5b8f642608202ecdf7da2a00 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Tue, 23 Jan 2024 11:12:22 +0100 Subject: [PATCH 24/31] remove outdated operator-rs version entry --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc519373..45ba9dc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,6 @@ All notable changes to this project will be documented in this file. ### Changed -- `operator-rs` `0.56.1` -> `0.57.0` ([#433]). - Use new label builders ([#454]). ### Removed @@ -23,7 +22,6 @@ All notable changes to this project will be documented in this file. - Include hdfs principals `dfs.journalnode.kerberos.principal`, `dfs.namenode.kerberos.principal` and `dfs.datanode.kerberos.principal` in the discovery ConfigMap in case Kerberos is enabled ([#451]). -[#433]: https://github.com/stackabletech/hdfs-operator/pull/433 [#454]: https://github.com/stackabletech/hdfs-operator/pull/454 [#451]: https://github.com/stackabletech/hdfs-operator/pull/451 [#458]: https://github.com/stackabletech/hdfs-operator/pull/458 From 8b25f33ab422c3fd908dc1de226e6896f185e4d3 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Tue, 23 Jan 2024 11:14:23 +0100 Subject: [PATCH 25/31] rename kerberos::check_if_supported to kerberos::is_supported --- rust/operator-binary/src/hdfs_controller.rs | 2 +- rust/operator-binary/src/kerberos.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/operator-binary/src/hdfs_controller.rs b/rust/operator-binary/src/hdfs_controller.rs index 3db40a0e..9687ad6a 100644 --- a/rust/operator-binary/src/hdfs_controller.rs +++ b/rust/operator-binary/src/hdfs_controller.rs @@ -243,7 +243,7 @@ pub async fn reconcile_hdfs(hdfs: Arc, ctx: Arc) -> HdfsOperat .spec .image .resolve(DOCKER_IMAGE_BASE_NAME, crate::built_info::CARGO_PKG_VERSION); - if hdfs.has_kerberos_enabled() && kerberos::check_if_supported(&resolved_product_image) { + if hdfs.has_kerberos_enabled() && kerberos::is_supported(&resolved_product_image) { return KerberosNotSupportedSnafu.fail(); } diff --git a/rust/operator-binary/src/kerberos.rs b/rust/operator-binary/src/kerberos.rs index a0183ae5..0740d5b5 100644 --- a/rust/operator-binary/src/kerberos.rs +++ b/rust/operator-binary/src/kerberos.rs @@ -25,7 +25,7 @@ pub enum Error { /// We only support Kerberos for HDFS >= 3.3.x /// With HDFS 3.2.2 we got weird errors, which *might* be caused by DNS lookup issues /// The Stacktrace is documented in rust/operator/src/kerberos_hdfs_3.2_stacktrace.txt -pub fn check_if_supported(resolved_product_image: &ResolvedProductImage) -> bool { +pub fn is_supported(resolved_product_image: &ResolvedProductImage) -> bool { resolved_product_image.product_version.starts_with("3.2.") } From e7160ad97d7beb9d96e057a07b3e0d87e993805e Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Tue, 23 Jan 2024 12:40:59 +0100 Subject: [PATCH 26/31] fix kerberos::is_supported bool --- rust/operator-binary/src/kerberos.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/operator-binary/src/kerberos.rs b/rust/operator-binary/src/kerberos.rs index 0740d5b5..480faa3c 100644 --- a/rust/operator-binary/src/kerberos.rs +++ b/rust/operator-binary/src/kerberos.rs @@ -26,7 +26,7 @@ pub enum Error { /// With HDFS 3.2.2 we got weird errors, which *might* be caused by DNS lookup issues /// The Stacktrace is documented in rust/operator/src/kerberos_hdfs_3.2_stacktrace.txt pub fn is_supported(resolved_product_image: &ResolvedProductImage) -> bool { - resolved_product_image.product_version.starts_with("3.2.") + !resolved_product_image.product_version.starts_with("3.2.") } impl HdfsSiteConfigBuilder { From 1bcc4909e764f51e1c6cc1dbb1de7c1054bde67e Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Wed, 24 Jan 2024 10:00:11 +0100 Subject: [PATCH 27/31] update nixpkgs to get rust 1.75 ``` This is version 0.0.0-dev, built for x86_64-unknown-linux-gnu by rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball) at Wed, 24 Jan 2024 08:59:02 +0000 ``` --- nix/sources.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nix/sources.json b/nix/sources.json index 92a53221..77a4d125 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -17,10 +17,10 @@ "homepage": "", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3f21a22b5aafefa1845dec6f4a378a8f53d8681c", - "sha256": "15y8k3hazg91kscbmn7dy6m0q6zvmhlvvhg97gcl5kw87y0svzxk", + "rev": "5f5210aa20e343b7e35f40c033000db0ef80d7b9", + "sha256": "0yc83iqbzj1gd651x6p2wx7a76wfpifaq7jxz4srbinaglfwfb07", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/3f21a22b5aafefa1845dec6f4a378a8f53d8681c.tar.gz", + "url": "https://github.com/NixOS/nixpkgs/archive/5f5210aa20e343b7e35f40c033000db0ef80d7b9.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } From 9e978fe55661990795df5bad8af0c6d25d70e9f2 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Wed, 24 Jan 2024 19:55:24 +0100 Subject: [PATCH 28/31] double deref --- rust/operator-binary/src/pod_svc_controller.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rust/operator-binary/src/pod_svc_controller.rs b/rust/operator-binary/src/pod_svc_controller.rs index 54cd5538..0f2f3889 100644 --- a/rust/operator-binary/src/pod_svc_controller.rs +++ b/rust/operator-binary/src/pod_svc_controller.rs @@ -77,7 +77,9 @@ pub async fn reconcile_pod(pod: Arc, ctx: Arc) -> Result { label .key() .prefix() - .is_some_and(|prefix| *prefix == APP_KUBERNETES_LABEL_BASE) + .map(std::ops::Deref::deref) + .map(std::ops::Deref::deref) + == Some(APP_KUBERNETES_LABEL_BASE) }) .cloned() .collect(); From af6efe38c77bd6f573448d0892f452f71e2588bf Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Fri, 26 Jan 2024 13:03:43 +0100 Subject: [PATCH 29/31] disambiguate label errors --- rust/crd/src/lib.rs | 18 +++++++++--------- rust/operator-binary/src/hdfs_controller.rs | 16 +++++++++++----- rust/operator-binary/src/pod_svc_controller.rs | 6 +++--- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/rust/crd/src/lib.rs b/rust/crd/src/lib.rs index 05cc426c..a5f80b7d 100644 --- a/rust/crd/src/lib.rs +++ b/rust/crd/src/lib.rs @@ -67,8 +67,8 @@ pub enum Error { #[snafu(display("fragment validation failure"))] FragmentValidationFailure { source: ValidationError }, - #[snafu(display("failed to build label"))] - BuildLabel { source: LabelError }, + #[snafu(display("failed to build role-group selector label"))] + BuildRoleGroupSelectorLabel { source: LabelError }, } /// An HDFS cluster stacklet. This resource is managed by the Stackable operator for Apache Hadoop HDFS. @@ -472,13 +472,13 @@ impl HdfsCluster { &rolegroup_ref.role, &rolegroup_ref.role_group, ) - .context(BuildLabelSnafu)?; + .context(BuildRoleGroupSelectorLabelSnafu)?; group_labels - .parse_insert((String::from("role"), rolegroup_ref.role.clone())) - .context(BuildLabelSnafu)?; + .parse_insert(("role", rolegroup_ref.role.deref())) + .context(BuildRoleGroupSelectorLabelSnafu)?; group_labels - .parse_insert((String::from("group"), rolegroup_ref.role_group.clone())) - .context(BuildLabelSnafu)?; + .parse_insert(("group", rolegroup_ref.role_group.deref())) + .context(BuildRoleGroupSelectorLabelSnafu)?; if self.spec.cluster_config.listener_class == CurrentlySupportedListenerClasses::ExternalUnstable @@ -487,8 +487,8 @@ impl HdfsCluster { // useful for development purposes. group_labels - .parse_insert((LABEL_ENABLE.to_string(), "true".to_string())) - .context(BuildLabelSnafu)?; + .parse_insert((LABEL_ENABLE, "true")) + .context(BuildRoleGroupSelectorLabelSnafu)?; } Ok(group_labels) diff --git a/rust/operator-binary/src/hdfs_controller.rs b/rust/operator-binary/src/hdfs_controller.rs index 9687ad6a..17b05541 100644 --- a/rust/operator-binary/src/hdfs_controller.rs +++ b/rust/operator-binary/src/hdfs_controller.rs @@ -212,8 +212,14 @@ pub enum Error { #[snafu(display("failed to build roleGroup selector labels"))] RoleGroupSelectorLabels { source: stackable_hdfs_crd::Error }, - #[snafu(display("failed to build label"))] - BuildLabel { source: LabelError }, + #[snafu(display("failed to build prometheus label"))] + BuildPrometheusLabel { source: LabelError }, + + #[snafu(display("failed to build cluster resources label"))] + BuildClusterResourcesLabel { source: LabelError }, + + #[snafu(display("failed to build role-group selector label"))] + BuildRoleGroupSelectorLabel { source: LabelError }, #[snafu(display("failed to build object meta data"))] ObjectMeta { source: ObjectMetaBuilderError }, @@ -305,7 +311,7 @@ pub async fn reconcile_hdfs(hdfs: Arc, ctx: Arc) -> HdfsOperat APP_NAME, cluster_resources .get_required_labels() - .context(BuildLabelSnafu)?, + .context(BuildClusterResourcesLabelSnafu)?, ) .context(BuildRbacResourcesSnafu)?; @@ -437,7 +443,7 @@ fn rolegroup_service( tracing::info!("Setting up Service for {:?}", rolegroup_ref); let prometheus_label = - Label::try_from(("prometheus.io/scrape", "true")).context(BuildLabelSnafu)?; + Label::try_from(("prometheus.io/scrape", "true")).context(BuildPrometheusLabelSnafu)?; let metadata = ObjectMetaBuilder::new() .name_and_namespace(hdfs) @@ -775,7 +781,7 @@ fn rolegroup_statefulset( &rolegroup_ref.role, &rolegroup_ref.role_group, ) - .context(BuildLabelSnafu)?; + .context(BuildRoleGroupSelectorLabelSnafu)?; let statefulset_spec = StatefulSetSpec { pod_management_policy: Some("OrderedReady".to_string()), diff --git a/rust/operator-binary/src/pod_svc_controller.rs b/rust/operator-binary/src/pod_svc_controller.rs index 0f2f3889..8350233e 100644 --- a/rust/operator-binary/src/pod_svc_controller.rs +++ b/rust/operator-binary/src/pod_svc_controller.rs @@ -42,8 +42,8 @@ pub enum Error { name: String, }, - #[snafu(display("failed to build label"))] - BuildLabel { source: LabelError }, + #[snafu(display("failed to build new labels from pod labels"))] + NewLabelsFromPodLabels { source: LabelError }, } impl ReconcilerError for Error { @@ -69,7 +69,7 @@ pub async fn reconcile_pod(pod: Arc, ctx: Arc) -> Result { .as_ref() .with_context(|| PodHasNoLabelsSnafu { name: name.clone() })?, ) - .context(BuildLabelSnafu)?; + .context(NewLabelsFromPodLabelsSnafu)?; let recommended_labels_from_pod = pod_labels .iter() From 2353cc71c91ee3a18147b11ee313c63cdc12e2ae Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Fri, 26 Jan 2024 13:12:58 +0100 Subject: [PATCH 30/31] fix: kerberos::is_not_supported --- rust/operator-binary/src/hdfs_controller.rs | 2 +- rust/operator-binary/src/kerberos.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/rust/operator-binary/src/hdfs_controller.rs b/rust/operator-binary/src/hdfs_controller.rs index 17b05541..41da28af 100644 --- a/rust/operator-binary/src/hdfs_controller.rs +++ b/rust/operator-binary/src/hdfs_controller.rs @@ -249,7 +249,7 @@ pub async fn reconcile_hdfs(hdfs: Arc, ctx: Arc) -> HdfsOperat .spec .image .resolve(DOCKER_IMAGE_BASE_NAME, crate::built_info::CARGO_PKG_VERSION); - if hdfs.has_kerberos_enabled() && kerberos::is_supported(&resolved_product_image) { + if hdfs.has_kerberos_enabled() && kerberos::is_not_supported(&resolved_product_image) { return KerberosNotSupportedSnafu.fail(); } diff --git a/rust/operator-binary/src/kerberos.rs b/rust/operator-binary/src/kerberos.rs index 480faa3c..1bf66b3a 100644 --- a/rust/operator-binary/src/kerberos.rs +++ b/rust/operator-binary/src/kerberos.rs @@ -22,11 +22,13 @@ pub enum Error { }, } +/// Checks for unsupported Kerberos versions +/// /// We only support Kerberos for HDFS >= 3.3.x /// With HDFS 3.2.2 we got weird errors, which *might* be caused by DNS lookup issues /// The Stacktrace is documented in rust/operator/src/kerberos_hdfs_3.2_stacktrace.txt -pub fn is_supported(resolved_product_image: &ResolvedProductImage) -> bool { - !resolved_product_image.product_version.starts_with("3.2.") +pub fn is_not_supported(resolved_product_image: &ResolvedProductImage) -> bool { + resolved_product_image.product_version.starts_with("3.2.") } impl HdfsSiteConfigBuilder { From 0e928ae0771bc43e73b9e4f8f3174085c18d4716 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Thu, 1 Feb 2024 17:15:16 +0100 Subject: [PATCH 31/31] style: error text lower case, remove square brackets --- rust/operator-binary/src/container.rs | 6 +-- rust/operator-binary/src/event.rs | 2 +- rust/operator-binary/src/hdfs_controller.rs | 40 +++++++++---------- rust/operator-binary/src/kerberos.rs | 2 +- .../src/operations/graceful_shutdown.rs | 2 +- rust/operator-binary/src/operations/pdb.rs | 4 +- rust/operator-binary/src/product_logging.rs | 4 +- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/rust/operator-binary/src/container.rs b/rust/operator-binary/src/container.rs index c1104d59..5fe61492 100644 --- a/rust/operator-binary/src/container.rs +++ b/rust/operator-binary/src/container.rs @@ -76,16 +76,16 @@ pub enum Error { #[snafu(display("object has no namespace"))] ObjectHasNoNamespace, - #[snafu(display("Invalid java heap config for [{role}]"))] + #[snafu(display("invalid java heap config for {role:?}"))] InvalidJavaHeapConfig { source: stackable_operator::error::Error, role: String, }, - #[snafu(display("Could not determine any ContainerConfig actions for [{container_name}]. Container not recognized."))] + #[snafu(display("could not determine any ContainerConfig actions for {container_name:?}. Container not recognized."))] UnrecognizedContainerName { container_name: String }, - #[snafu(display("Invalid container name [{name}]"))] + #[snafu(display("invalid container name {name:?}"))] InvalidContainerName { source: stackable_operator::error::Error, name: String, diff --git a/rust/operator-binary/src/event.rs b/rust/operator-binary/src/event.rs index cdfa7c1b..46ff0b12 100644 --- a/rust/operator-binary/src/event.rs +++ b/rust/operator-binary/src/event.rs @@ -12,7 +12,7 @@ use strum::{EnumDiscriminants, IntoStaticStr}; #[derive(Snafu, Debug, EnumDiscriminants)] #[strum_discriminants(derive(IntoStaticStr))] pub enum Error { - #[snafu(display("Failed to publish event"))] + #[snafu(display("failed to publish event"))] PublishEvent { source: stackable_operator::kube::Error, }, diff --git a/rust/operator-binary/src/hdfs_controller.rs b/rust/operator-binary/src/hdfs_controller.rs index ccee4281..b65e52c3 100644 --- a/rust/operator-binary/src/hdfs_controller.rs +++ b/rust/operator-binary/src/hdfs_controller.rs @@ -72,92 +72,92 @@ const DOCKER_IMAGE_BASE_NAME: &str = "hadoop"; #[derive(Snafu, Debug, EnumDiscriminants)] #[strum_discriminants(derive(IntoStaticStr))] pub enum Error { - #[snafu(display("Invalid role configuration"))] + #[snafu(display("invalid role configuration"))] InvalidRoleConfig { source: stackable_operator::product_config_utils::ConfigError, }, - #[snafu(display("Invalid product configuration"))] + #[snafu(display("invalid product configuration"))] InvalidProductConfig { source: stackable_operator::error::Error, }, - #[snafu(display("Cannot create rolegroup service [{name}]"))] + #[snafu(display("cannot create rolegroup service {name:?}"))] ApplyRoleGroupService { source: stackable_operator::error::Error, name: String, }, - #[snafu(display("Cannot create role group config map [{name}]"))] + #[snafu(display("cannot create role group config map {name:?}"))] ApplyRoleGroupConfigMap { source: stackable_operator::error::Error, name: String, }, - #[snafu(display("Cannot create role group stateful set [{name}]"))] + #[snafu(display("cannot create role group stateful set {name:?}"))] ApplyRoleGroupStatefulSet { source: stackable_operator::error::Error, name: String, }, - #[snafu(display("Cannot create discovery config map [{name}]"))] + #[snafu(display("cannot create discovery config map {name:?}"))] ApplyDiscoveryConfigMap { source: stackable_operator::error::Error, name: String, }, - #[snafu(display("No metadata for [{obj_ref}]"))] + #[snafu(display("no metadata for {obj_ref:?}"))] ObjectMissingMetadataForOwnerRef { source: stackable_operator::error::Error, obj_ref: ObjectRef, }, - #[snafu(display("Invalid role [{role}]"))] + #[snafu(display("invalid role {role:?}"))] InvalidRole { source: strum::ParseError, role: String, }, - #[snafu(display("Object has no name"))] + #[snafu(display("object has no name"))] ObjectHasNoName { obj_ref: ObjectRef }, - #[snafu(display("Cannot build config map for role [{role}] and role group [{role_group}]"))] + #[snafu(display("cannot build config map for role {role:?} and role group {role_group:?}"))] BuildRoleGroupConfigMap { source: stackable_operator::error::Error, role: String, role_group: String, }, - #[snafu(display("Cannot collect discovery configuration"))] + #[snafu(display("cannot collect discovery configuration"))] CollectDiscoveryConfig { source: stackable_hdfs_crd::Error }, - #[snafu(display("Cannot build config discovery config map"))] + #[snafu(display("cannot build config discovery config map"))] BuildDiscoveryConfigMap { source: discovery::Error }, - #[snafu(display("Failed to patch service account"))] + #[snafu(display("failed to patch service account"))] ApplyServiceAccount { source: stackable_operator::error::Error, }, - #[snafu(display("Failed to patch role binding"))] + #[snafu(display("failed to patch role binding"))] ApplyRoleBinding { source: stackable_operator::error::Error, }, - #[snafu(display("Failed to create cluster resources"))] + #[snafu(display("failed to create cluster resources"))] CreateClusterResources { source: stackable_operator::error::Error, }, - #[snafu(display("Failed to delete orphaned resources"))] + #[snafu(display("failed to delete orphaned resources"))] DeleteOrphanedResources { source: stackable_operator::error::Error, }, - #[snafu(display("Failed to create pod references"))] + #[snafu(display("failed to create pod references"))] CreatePodReferences { source: stackable_hdfs_crd::Error }, - #[snafu(display("Failed to build role properties"))] + #[snafu(display("failed to build role properties"))] BuildRoleProperties { source: stackable_hdfs_crd::Error }, #[snafu(display("failed to resolve the Vector aggregator address"))] @@ -165,7 +165,7 @@ pub enum Error { source: crate::product_logging::Error, }, - #[snafu(display("failed to add the logging configuration to the ConfigMap [{cm_name}]"))] + #[snafu(display("failed to add the logging configuration to the ConfigMap {cm_name:?}"))] InvalidLoggingConfig { source: crate::product_logging::Error, cm_name: String, @@ -201,7 +201,7 @@ pub enum Error { KerberosNotSupported, #[snafu(display( - "failed to serialize [{JVM_SECURITY_PROPERTIES_FILE}] for {}", + "failed to serialize {JVM_SECURITY_PROPERTIES_FILE:?} for {}", rolegroup ))] JvmSecurityProperties { diff --git a/rust/operator-binary/src/kerberos.rs b/rust/operator-binary/src/kerberos.rs index 1bf66b3a..095b0cd7 100644 --- a/rust/operator-binary/src/kerberos.rs +++ b/rust/operator-binary/src/kerberos.rs @@ -15,7 +15,7 @@ type Result = std::result::Result; #[derive(Snafu, Debug)] #[allow(clippy::enum_variant_names)] pub enum Error { - #[snafu(display("Object has no namespace"))] + #[snafu(display("object has no namespace"))] ObjectHasNoNamespace { source: stackable_hdfs_crd::Error, obj_ref: ObjectRef, diff --git a/rust/operator-binary/src/operations/graceful_shutdown.rs b/rust/operator-binary/src/operations/graceful_shutdown.rs index dfb9440e..d35b9e29 100644 --- a/rust/operator-binary/src/operations/graceful_shutdown.rs +++ b/rust/operator-binary/src/operations/graceful_shutdown.rs @@ -4,7 +4,7 @@ use stackable_operator::builder::PodBuilder; #[derive(Debug, Snafu)] pub enum Error { - #[snafu(display("Failed to set terminationGracePeriod"))] + #[snafu(display("failed to set terminationGracePeriod"))] SetTerminationGracePeriod { source: stackable_operator::builder::pod::Error, }, diff --git a/rust/operator-binary/src/operations/pdb.rs b/rust/operator-binary/src/operations/pdb.rs index e49c1a76..0418d382 100644 --- a/rust/operator-binary/src/operations/pdb.rs +++ b/rust/operator-binary/src/operations/pdb.rs @@ -11,13 +11,13 @@ use crate::{hdfs_controller::RESOURCE_MANAGER_HDFS_CONTROLLER, OPERATOR_NAME}; #[derive(Snafu, Debug)] pub enum Error { - #[snafu(display("Cannot create PodDisruptionBudget for role [{role}]"))] + #[snafu(display("cannot create PodDisruptionBudget for role {role:?}"))] CreatePdb { source: stackable_operator::error::Error, role: String, }, - #[snafu(display("Cannot apply role group PodDisruptionBudget [{name}]"))] + #[snafu(display("cannot apply role group PodDisruptionBudget {name:?}"))] ApplyPdb { source: stackable_operator::error::Error, name: String, diff --git a/rust/operator-binary/src/product_logging.rs b/rust/operator-binary/src/product_logging.rs index 5ff8377e..cc1d29b7 100644 --- a/rust/operator-binary/src/product_logging.rs +++ b/rust/operator-binary/src/product_logging.rs @@ -20,13 +20,13 @@ pub enum Error { #[snafu(display("object has no namespace"))] ObjectHasNoNamespace, - #[snafu(display("failed to retrieve the ConfigMap [{cm_name}]"))] + #[snafu(display("failed to retrieve the ConfigMap {cm_name:?}"))] ConfigMapNotFound { source: stackable_operator::error::Error, cm_name: String, }, - #[snafu(display("failed to retrieve the entry [{entry}] for ConfigMap [{cm_name}]"))] + #[snafu(display("failed to retrieve the entry {entry:?} for ConfigMap {cm_name:?}"))] MissingConfigMapEntry { entry: &'static str, cm_name: String,