Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Simplify common S3 structs and add helper functions #679

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
tracing = "0.1.37"
tracing-opentelemetry = "0.21.0"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
url = "2.4.1"

[dev-dependencies]
rstest = "0.18.1"
Expand Down
3 changes: 2 additions & 1 deletion src/commons/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This module provides common datastructures or CRDs shared between all the operators
//! This module provides common data-structures or CRDs shared between all the operators

pub mod affinity;
pub mod authentication;
Expand All @@ -11,3 +11,4 @@ pub mod rbac;
pub mod resources;
pub mod s3;
pub mod secret_class;
pub mod tls;
256 changes: 0 additions & 256 deletions src/commons/s3.rs

This file was deleted.

81 changes: 81 additions & 0 deletions src/commons/s3/crd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use kube::CustomResource;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::commons::{secret_class::SecretClassVolume, tls::TlsClientDetails};

use super::S3ConnectionInlineOrReference;

/// Contains connection and access details to access an S3 object store.
#[derive(CustomResource, Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[kube(
group = "s3.stackable.tech",
version = "v1alpha1",
kind = "S3Connection",
plural = "s3connections",
crates(
kube_core = "kube::core",
k8s_openapi = "k8s_openapi",
schemars = "schemars"
),
namespaced
)]
#[serde(rename_all = "camelCase")]
pub struct S3ConnectionSpec {
/// Hostname of the S3 server without any protocol or port.
// TODO: Rename to `hostname` to be more consistent with other structs.
#[serde(rename = "host")]
pub hostname: String,

/// Port the S3 server listens on.
/// Port of the S3 server. If TLS is used defaults to 443 otherwise to 80.
pub(crate) port: Option<u16>,

/// Which access style to use.
/// Defaults to virtual hosted-style as most of the data products out there.
/// Have a look at the official documentation on <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html>
#[serde(default)]
pub access_style: S3AccessStyle,

/// If the S3 uses authentication you have to specify you S3 credentials.
/// In the most cases a SecretClass providing `accessKey` and `secretKey` is sufficient.
pub credentials: Option<SecretClassVolume>,

/// If you want to use TLS when talking to S3 you can enable TLS encrypted communication with this setting.
#[serde(flatten)]
pub tls: TlsClientDetails,
}

/// Contains the name of the bucket as well as the needed connection details.
#[derive(Clone, CustomResource, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[kube(
group = "s3.stackable.tech",
version = "v1alpha1",
kind = "S3Bucket",
plural = "s3buckets",
crates(
kube_core = "kube::core",
k8s_openapi = "k8s_openapi",
schemars = "schemars"
),
namespaced
)]
#[serde(rename_all = "camelCase")]
pub struct S3BucketSpec {
/// Name of the bucket
pub(crate) bucket_name: String,
/// Either a inlined s3 connection or a reference to a S3Connection object
pub(crate) connection: S3ConnectionInlineOrReference,
}

#[derive(
strum::Display, Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize,
)]
#[strum(serialize_all = "PascalCase")]
pub enum S3AccessStyle {
/// Use path-style access as described in <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#path-style-access>
Path,
/// Use as virtual hosted-style access as described in <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#virtual-hosted-style-access>
#[default]
VirtualHosted,
}
Loading