From 4d68587e7d9b426e10710c1a1575fe627d354c99 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Fri, 14 Mar 2025 10:12:45 +0100 Subject: [PATCH 1/5] feat: Add Region::is_default_config function --- crates/stackable-operator/CHANGELOG.md | 4 +++ .../stackable-operator/src/commons/s3/crd.rs | 25 ++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index 2e69864c6..c92bd660f 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added + +- Add a `Region::is_default_config` function to determine if a region sticks to the default config ([#XXX]). + ## [0.87.2] - 2025-03-10 ### Changed diff --git a/crates/stackable-operator/src/commons/s3/crd.rs b/crates/stackable-operator/src/commons/s3/crd.rs index 5bd17fe2f..0233e617e 100644 --- a/crates/stackable-operator/src/commons/s3/crd.rs +++ b/crates/stackable-operator/src/commons/s3/crd.rs @@ -98,18 +98,31 @@ pub enum S3AccessStyle { #[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub struct Region { - #[serde(default = "default_region_name")] + #[serde(default = "Region::default_region_name")] pub name: String, } +/// Having it as const &str as well, so we don't always allocate a [`String`] just for comparisons +const DEFAULT_REGION_NAME: &str = "us-east-1"; +impl Region { + fn default_region_name() -> String { + DEFAULT_REGION_NAME.to_string() + } + + /// Returns if the region sticks to the Stackable defaults. + /// + /// Some products don't really support configuring the region. + /// This function can be used to determine if a warning or error should be raised to inform the + /// user of this situation. + pub fn is_default_config(&self) -> bool { + self.name == DEFAULT_REGION_NAME + } +} + impl Default for Region { fn default() -> Self { Self { - name: default_region_name(), + name: Self::default_region_name(), } } } - -fn default_region_name() -> String { - "us-east-1".into() -} From 9a78c2dadc15a380b4d42e0163748776075165cf Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Fri, 14 Mar 2025 10:14:27 +0100 Subject: [PATCH 2/5] changelog --- crates/stackable-operator/CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index c92bd660f..ab387c71f 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -6,7 +6,9 @@ All notable changes to this project will be documented in this file. ### Added -- Add a `Region::is_default_config` function to determine if a region sticks to the default config ([#XXX]). +- Add a `Region::is_default_config` function to determine if a region sticks to the default config ([#983]). + +[#983]: https://github.com/stackabletech/operator-rs/pull/983 ## [0.87.2] - 2025-03-10 From 7d07914ef0e24452c21658707c326e2dbdea9680 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Fri, 14 Mar 2025 10:16:02 +0100 Subject: [PATCH 3/5] update docs --- crates/stackable-operator/src/commons/s3/crd.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/stackable-operator/src/commons/s3/crd.rs b/crates/stackable-operator/src/commons/s3/crd.rs index 0233e617e..62c6e4f67 100644 --- a/crates/stackable-operator/src/commons/s3/crd.rs +++ b/crates/stackable-operator/src/commons/s3/crd.rs @@ -102,7 +102,7 @@ pub struct Region { pub name: String, } -/// Having it as const &str as well, so we don't always allocate a [`String`] just for comparisons +/// Having it as `const &str` as well, so we don't always allocate a [`String`] just for comparisons const DEFAULT_REGION_NAME: &str = "us-east-1"; impl Region { fn default_region_name() -> String { From 78065ae11a876f66b078a0300e29cc69d5bc564f Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Fri, 14 Mar 2025 10:42:31 +0100 Subject: [PATCH 4/5] Update crates/stackable-operator/src/commons/s3/crd.rs Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> --- crates/stackable-operator/src/commons/s3/crd.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/stackable-operator/src/commons/s3/crd.rs b/crates/stackable-operator/src/commons/s3/crd.rs index 62c6e4f67..1f78cfab6 100644 --- a/crates/stackable-operator/src/commons/s3/crd.rs +++ b/crates/stackable-operator/src/commons/s3/crd.rs @@ -102,9 +102,10 @@ pub struct Region { pub name: String, } -/// Having it as `const &str` as well, so we don't always allocate a [`String`] just for comparisons -const DEFAULT_REGION_NAME: &str = "us-east-1"; impl Region { + /// Having it as `const &str` as well, so we don't always allocate a [`String`] just for comparisons + pub const DEFAULT_REGION_NAME: &str = "us-east-1"; + fn default_region_name() -> String { DEFAULT_REGION_NAME.to_string() } From 6c97a680dcc62a78236259ca945b3c15dc34ef36 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Fri, 14 Mar 2025 10:43:07 +0100 Subject: [PATCH 5/5] Fix compilation --- crates/stackable-operator/src/commons/s3/crd.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/stackable-operator/src/commons/s3/crd.rs b/crates/stackable-operator/src/commons/s3/crd.rs index 1f78cfab6..00b796876 100644 --- a/crates/stackable-operator/src/commons/s3/crd.rs +++ b/crates/stackable-operator/src/commons/s3/crd.rs @@ -107,7 +107,7 @@ impl Region { pub const DEFAULT_REGION_NAME: &str = "us-east-1"; fn default_region_name() -> String { - DEFAULT_REGION_NAME.to_string() + Self::DEFAULT_REGION_NAME.to_string() } /// Returns if the region sticks to the Stackable defaults. @@ -116,7 +116,7 @@ impl Region { /// This function can be used to determine if a warning or error should be raised to inform the /// user of this situation. pub fn is_default_config(&self) -> bool { - self.name == DEFAULT_REGION_NAME + self.name == Self::DEFAULT_REGION_NAME } }