Skip to content

Commit c7bc930

Browse files
committed
Change credentials of S3ConnectionSpec to use the common SecretClassVolume struct
1 parent e14b29b commit c7bc930

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ All notable changes to this project will be documented in this file.
66

77
### Changed
88

9-
- `impl Into<Resourcerequirements> for Resources` set's fields to `None` instead of `Some(<empty map>)` when nothing is defined.([#398]).
9+
- `impl Into<Resourcerequirements> for Resources` set's fields to `None` instead of `Some(<empty map>)` when nothing is defined. ([#398]).
10+
- BREAKING: Change credentials of `S3ConnectionSpec` to use the common `SecretClassVolume` struct ([#405]).
1011

1112
[#398]: https://github.com/stackabletech/operator-rs/pull/398
13+
[#405]: https://github.com/stackabletech/operator-rs/pull/405
1214

1315
## [0.20.0] - 2022-05-13
1416

src/builder/pod/volume.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ impl VolumeBuilder {
149149
self
150150
}
151151

152+
pub fn ephemeral(&mut self, ephemeral: impl Into<EphemeralVolumeSource>) -> &mut Self {
153+
self.volume_source = VolumeSource::Ephemeral(Box::new(ephemeral.into()));
154+
self
155+
}
156+
152157
/// Consumes the Builder and returns a constructed Volume
153158
pub fn build(&self) -> Volume {
154159
let name = self.name.clone();

src/commons/s3.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! Operator CRDs are expected to use the [S3BucketDef] as an entry point to this module
55
//! and obtain an [InlinedS3BucketSpec] by calling [`S3BucketDef::resolve`].
66
//!
7-
use crate::commons::tls::Tls;
7+
use crate::commons::{secret_class::SecretClassVolume, tls::Tls};
88
use crate::error;
99
use crate::{client::Client, error::OperatorResult};
1010
use kube::CustomResource;
@@ -82,14 +82,6 @@ impl InlinedS3BucketSpec {
8282
.as_ref()
8383
.and_then(|connection| connection.endpoint())
8484
}
85-
86-
/// Shortcut to [S3ConnectionSpec::secret_class]
87-
pub fn secret_class(&self) -> Option<String> {
88-
match self.connection.as_ref() {
89-
Some(conn_spec) => conn_spec.secret_class.clone(),
90-
_ => None,
91-
}
92-
}
9385
}
9486

9587
/// Operators are expected to define fields for this type in order to work with S3 buckets.
@@ -159,14 +151,23 @@ impl S3ConnectionDef {
159151
)]
160152
#[serde(rename_all = "camelCase")]
161153
pub struct S3ConnectionSpec {
154+
/// Hostname of the S3 server without any protocol or port
162155
#[serde(default, skip_serializing_if = "Option::is_none")]
163156
pub host: Option<String>,
157+
/// Port the S3 server listens on.
158+
/// If not specified the products will determine the port to use.
164159
#[serde(default, skip_serializing_if = "Option::is_none")]
165160
pub port: Option<u16>,
161+
/// Which access style to use.
162+
/// Defaults to virtual hosted-style as most of the data products out there.
163+
/// Have a look at the official documentation on <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html>
166164
#[serde(default, skip_serializing_if = "Option::is_none")]
167165
pub access_style: Option<S3AccessStyle>,
166+
/// If the S3 uses authentication you have to specify you S3 credentials.
167+
/// In the most cases a SecretClass providing `accessKey` and `secretKey` is sufficient.
168168
#[serde(default, skip_serializing_if = "Option::is_none")]
169-
pub secret_class: Option<String>,
169+
pub credentials: Option<SecretClassVolume>,
170+
/// If you want to use TLS when talking to S3 you can enable TLS encrypted communication with this setting.
170171
#[serde(default, skip_serializing_if = "Option::is_none")]
171172
pub tls: Option<Tls>,
172173
}
@@ -203,7 +204,9 @@ impl S3ConnectionSpec {
203204
#[derive(strum::Display, Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
204205
#[strum(serialize_all = "PascalCase")]
205206
pub enum S3AccessStyle {
207+
/// Use path-style access as described in <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#path-style-access>
206208
Path,
209+
/// Use as virtual hosted-style access as described in <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#virtual-hosted-style-access>
207210
VirtualHosted,
208211
}
209212

@@ -225,7 +228,7 @@ mod test {
225228
connection: Some(S3ConnectionDef::Inline(S3ConnectionSpec {
226229
host: Some("host".to_owned()),
227230
port: Some(8080),
228-
secret_class: None,
231+
credentials: None,
229232
access_style: Some(S3AccessStyle::VirtualHosted),
230233
tls: None,
231234
})),

src/commons/secret_class.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::builder::SecretOperatorVolumeSourceBuilder;
2-
use k8s_openapi::api::core::v1::EphemeralVolumeSource;
1+
use crate::builder::{SecretOperatorVolumeSourceBuilder, VolumeBuilder};
2+
use k8s_openapi::api::core::v1::{EphemeralVolumeSource, Volume};
33
use schemars::JsonSchema;
44
use serde::{Deserialize, Serialize};
55

@@ -13,7 +13,7 @@ pub struct SecretClassVolume {
1313
}
1414

1515
impl SecretClassVolume {
16-
pub fn to_ephemeral_volume(&self) -> EphemeralVolumeSource {
16+
pub fn to_ephemeral_volume_source(&self) -> EphemeralVolumeSource {
1717
let mut secret_operator_volume_builder =
1818
SecretOperatorVolumeSourceBuilder::new(&self.secret_class);
1919

@@ -31,6 +31,12 @@ impl SecretClassVolume {
3131

3232
secret_operator_volume_builder.build()
3333
}
34+
35+
pub fn to_volume(&self, volume_name: &str) -> Volume {
36+
VolumeBuilder::new(volume_name)
37+
.ephemeral(self.to_ephemeral_volume_source())
38+
.build()
39+
}
3440
}
3541

3642
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
@@ -50,16 +56,16 @@ mod tests {
5056
use std::collections::BTreeMap;
5157

5258
#[test]
53-
fn test_secret_class_volume_to_csi_volume() {
54-
let secret_class_volume = SecretClassVolume {
59+
fn test_secret_class_volume_to_csi_volume_source() {
60+
let secret_class_volume_source = SecretClassVolume {
5561
secret_class: "myclass".to_string(), // pragma: allowlist secret
5662
scope: Some(SecretClassVolumeScope {
5763
pod: true,
5864
node: false,
5965
services: vec!["myservice".to_string()],
6066
}),
6167
}
62-
.to_ephemeral_volume();
68+
.to_ephemeral_volume_source();
6369

6470
let expected_volume_attributes = BTreeMap::from([
6571
(
@@ -74,7 +80,7 @@ mod tests {
7480

7581
assert_eq!(
7682
expected_volume_attributes,
77-
secret_class_volume
83+
secret_class_volume_source
7884
.volume_claim_template
7985
.unwrap()
8086
.metadata

0 commit comments

Comments
 (0)