|
| 1 | +use kube::CustomResource; |
| 2 | +use schemars::JsonSchema; |
| 3 | +use serde::{Deserialize, Serialize}; |
| 4 | + |
| 5 | +use crate::commons::{ |
| 6 | + networking::Host, secret_class::SecretClassVolume, tls_verification::TlsClientDetails, |
| 7 | +}; |
| 8 | + |
| 9 | +use super::S3ConnectionInlineOrReference; |
| 10 | + |
| 11 | +/// S3 bucket specification containing the bucket name and an inlined or referenced connection specification. |
| 12 | +/// Learn more on the [S3 concept documentation](DOCS_BASE_URL_PLACEHOLDER/concepts/s3). |
| 13 | +#[derive(Clone, CustomResource, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)] |
| 14 | +#[kube( |
| 15 | + group = "s3.stackable.tech", |
| 16 | + version = "v1alpha1", |
| 17 | + kind = "S3Bucket", |
| 18 | + plural = "s3buckets", |
| 19 | + crates( |
| 20 | + kube_core = "kube::core", |
| 21 | + k8s_openapi = "k8s_openapi", |
| 22 | + schemars = "schemars" |
| 23 | + ), |
| 24 | + namespaced |
| 25 | +)] |
| 26 | +#[serde(rename_all = "camelCase")] |
| 27 | +pub struct S3BucketSpec { |
| 28 | + /// The name of the S3 bucket. |
| 29 | + pub bucket_name: String, |
| 30 | + |
| 31 | + /// The definition of an S3 connection, either inline or as a reference. |
| 32 | + pub connection: S3ConnectionInlineOrReference, |
| 33 | +} |
| 34 | + |
| 35 | +/// S3 connection definition as a resource. |
| 36 | +/// Learn more on the [S3 concept documentation](DOCS_BASE_URL_PLACEHOLDER/concepts/s3). |
| 37 | +#[derive(CustomResource, Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)] |
| 38 | +#[kube( |
| 39 | + group = "s3.stackable.tech", |
| 40 | + version = "v1alpha1", |
| 41 | + kind = "S3Connection", |
| 42 | + plural = "s3connections", |
| 43 | + crates( |
| 44 | + kube_core = "kube::core", |
| 45 | + k8s_openapi = "k8s_openapi", |
| 46 | + schemars = "schemars" |
| 47 | + ), |
| 48 | + namespaced |
| 49 | +)] |
| 50 | +#[serde(rename_all = "camelCase")] |
| 51 | +pub struct S3ConnectionSpec { |
| 52 | + /// Host of the S3 server without any protocol or port. For example: `west1.my-cloud.com`. |
| 53 | + pub host: Host, |
| 54 | + |
| 55 | + /// Port the S3 server listens on. |
| 56 | + /// If not specified the product will determine the port to use. |
| 57 | + #[serde(default, skip_serializing_if = "Option::is_none")] |
| 58 | + pub port: Option<u16>, |
| 59 | + |
| 60 | + /// Which access style to use. |
| 61 | + /// Defaults to virtual hosted-style as most of the data products out there. |
| 62 | + /// Have a look at the [AWS documentation](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html). |
| 63 | + #[serde(default)] |
| 64 | + pub access_style: S3AccessStyle, |
| 65 | + |
| 66 | + /// If the S3 uses authentication you have to specify you S3 credentials. |
| 67 | + /// In the most cases a [SecretClass](DOCS_BASE_URL_PLACEHOLDER/secret-operator/secretclass) |
| 68 | + /// providing `accessKey` and `secretKey` is sufficient. |
| 69 | + #[serde(default, skip_serializing_if = "Option::is_none")] |
| 70 | + pub credentials: Option<SecretClassVolume>, |
| 71 | + |
| 72 | + /// Use a TLS connection. If not specified no TLS will be used. |
| 73 | + #[serde(flatten)] |
| 74 | + pub tls: TlsClientDetails, |
| 75 | +} |
| 76 | + |
| 77 | +#[derive( |
| 78 | + strum::Display, Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize, |
| 79 | +)] |
| 80 | +#[strum(serialize_all = "PascalCase")] |
| 81 | +pub enum S3AccessStyle { |
| 82 | + /// Use path-style access as described in <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#path-style-access> |
| 83 | + Path, |
| 84 | + |
| 85 | + /// Use as virtual hosted-style access as described in <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#virtual-hosted-style-access> |
| 86 | + #[default] |
| 87 | + VirtualHosted, |
| 88 | +} |
0 commit comments