diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index 2e69864c6..ab387c71f 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -4,6 +4,12 @@ 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 ([#983]). + +[#983]: https://github.com/stackabletech/operator-rs/pull/983 + ## [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..00b796876 100644 --- a/crates/stackable-operator/src/commons/s3/crd.rs +++ b/crates/stackable-operator/src/commons/s3/crd.rs @@ -98,18 +98,32 @@ 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, } +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 { + Self::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 == Self::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() -}