Skip to content

Commit a8f87a8

Browse files
committed
refactor(stackable-operator/s3connection: Make the region field more complex to cater to the various use-cases:
1. Using S3 buckets from within AWS (users can choose to auto-discover via IMDS) 2. Using S3 buckets from outside AWS (users can choose the default, or set an optimal region based on the clients location). 3. Not using AWS S3 buckets, eg: MinIO or IONOS (users can ignore setting the field and the default region will be set to keep the AWS SDK happy, even though the region is not used for bucket operations).
1 parent 16437c8 commit a8f87a8

File tree

1 file changed

+55
-5
lines changed
  • crates/stackable-operator/src/commons/s3

1 file changed

+55
-5
lines changed

crates/stackable-operator/src/commons/s3/crd.rs

+55-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,26 @@ pub struct S3ConnectionSpec {
5656
#[serde(default, skip_serializing_if = "Option::is_none")]
5757
pub port: Option<u16>,
5858

59-
/// Region to connect to when using AWS S3.
59+
/// AWS service API region used by the AWS SDK when using AWS S3 buckets.
60+
///
61+
/// This defaults to `us-east-1`.
62+
///
63+
/// NOTE: This is not the bucket region, and is used by the AWS SDK to make
64+
/// endpoints for various AWS service APIs. It is only useful when using AWS
65+
/// S3 buckets.
66+
///
67+
/// NOTE: This setting is only useful if using AWS S3 buckets. Other S3
68+
/// implementations _should not_ require this to be set.
69+
///
70+
/// When using AWS S3 buckets, you can configure optimal AWS service API
71+
/// connections in the following ways:
72+
/// - From **inside** AWS: Use an auto-discovery source (eg: AWS IMDS).
73+
/// - From **outside** AWS, or when IMDS is disabled, explicity set the
74+
/// region name nearest to where the client application is running from.
6075
///
6176
/// This defaults to us-east-1, and can be ignored if not using AWS S3.
62-
#[serde(default = "s3_region_default")]
63-
pub region: String,
77+
#[serde(flatten)]
78+
pub region: AwsRegion,
6479

6580
/// Which access style to use.
6681
/// Defaults to virtual hosted-style as most of the data products out there.
@@ -92,6 +107,41 @@ pub enum S3AccessStyle {
92107
VirtualHosted,
93108
}
94109

95-
fn s3_region_default() -> String {
96-
"us-east-1".to_owned()
110+
#[derive(strum::Display, Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
111+
#[strum(serialize_all = "snake_case")]
112+
pub enum AwsRegion {
113+
/// Defer region detection to an auto-discovery mechanism.
114+
Source(AwsRegionAutoDiscovery),
115+
116+
/// An explicit region, eg: eu-central-1
117+
Name(String),
118+
}
119+
120+
impl AwsRegion {
121+
/// Get the region.
122+
///
123+
/// Returns None if an auto-discovery source has been selected.
124+
/// Otherwise, returns the configured region name.
125+
pub fn region(self) -> Option<String> {
126+
match self {
127+
AwsRegion::Name(name) => Some(name),
128+
AwsRegion::Source(_) => None,
129+
}
130+
}
131+
}
132+
133+
impl Default for AwsRegion {
134+
fn default() -> Self {
135+
Self::Name("us-east-1".to_owned())
136+
}
137+
}
138+
139+
#[derive(strum::Display, Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
140+
#[strum(serialize_all = "kebab-case")]
141+
pub enum AwsRegionAutoDiscovery {
142+
/// AWS Instance Meta Data Service.
143+
///
144+
/// This variant should result in no region being given to the AWS SDK,
145+
/// which should, in turn, query the AWS IMDS.
146+
AwsImds,
97147
}

0 commit comments

Comments
 (0)