@@ -2,6 +2,7 @@ use kube::CustomResource;
22use schemars:: JsonSchema ;
33use serde:: { Deserialize , Serialize } ;
44use snafu:: { ResultExt as _, Snafu } ;
5+ use stackable_versioned:: versioned;
56use url:: Url ;
67
78use crate :: {
@@ -48,78 +49,88 @@ pub enum ConnectionError {
4849 } ,
4950}
5051
51- /// S3 connection definition as a resource.
52- /// Learn more on the [S3 concept documentation](DOCS_BASE_URL_PLACEHOLDER/concepts/s3).
53- #[ derive( CustomResource , Clone , Debug , Deserialize , Eq , JsonSchema , PartialEq , Serialize ) ]
54- #[ kube(
55- group = "s3.stackable.tech" ,
56- version = "v1alpha1" ,
57- kind = "S3Connection" ,
58- plural = "s3connections" ,
59- crates(
60- kube_core = "kube::core" ,
61- k8s_openapi = "k8s_openapi" ,
62- schemars = "schemars"
63- ) ,
64- namespaced
65- ) ]
66- #[ serde( rename_all = "camelCase" ) ]
67- pub struct ConnectionSpec {
68- /// Host of the S3 server without any protocol or port. For example: `west1.my-cloud.com`.
69- pub host : HostName ,
70-
71- /// Port the S3 server listens on.
72- /// If not specified the product will determine the port to use.
73- #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
74- pub port : Option < u16 > ,
75-
76- /// Bucket region used for signing headers (sigv4).
77- ///
78- /// This defaults to `us-east-1` which is compatible with other implementations such as Minio.
79- ///
80- /// WARNING: Some products use the Hadoop S3 implementation which falls back to us-east-2.
81- #[ serde( default ) ]
82- pub region : Region ,
83-
84- /// Which access style to use.
85- /// Defaults to virtual hosted-style as most of the data products out there.
86- /// Have a look at the [AWS documentation](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html).
87- #[ serde( default ) ]
88- pub access_style : S3AccessStyle ,
89-
90- /// If the S3 uses authentication you have to specify you S3 credentials.
91- /// In the most cases a [SecretClass](DOCS_BASE_URL_PLACEHOLDER/secret-operator/secretclass)
92- /// providing `accessKey` and `secretKey` is sufficient.
93- #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
94- pub credentials : Option < SecretClassVolume > ,
95-
96- /// Use a TLS connection. If not specified no TLS will be used.
97- #[ serde( flatten) ]
98- pub tls : TlsClientDetails ,
99- }
52+ #[ versioned( version( name = "v1alpha1" ) ) ]
53+ pub mod versioned {
54+ /// S3 connection definition as a resource.
55+ /// Learn more on the [S3 concept documentation](DOCS_BASE_URL_PLACEHOLDER/concepts/s3).
56+ #[ versioned( k8s(
57+ group = "s3.stackable.tech" ,
58+ kind = "S3Connection" ,
59+ plural = "s3connections" ,
60+ crates(
61+ kube_core = "kube::core" ,
62+ k8s_openapi = "k8s_openapi" ,
63+ schemars = "schemars"
64+ ) ,
65+ namespaced
66+ ) ) ]
67+ #[ derive( CustomResource , Clone , Debug , Deserialize , Eq , JsonSchema , PartialEq , Serialize ) ]
68+ #[ serde( rename_all = "camelCase" ) ]
69+ pub struct ConnectionSpec {
70+ /// Host of the S3 server without any protocol or port. For example: `west1.my-cloud.com`.
71+ pub host : HostName ,
72+
73+ /// Port the S3 server listens on.
74+ /// If not specified the product will determine the port to use.
75+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
76+ pub port : Option < u16 > ,
77+
78+ /// Bucket region used for signing headers (sigv4).
79+ ///
80+ /// This defaults to `us-east-1` which is compatible with other implementations such as Minio.
81+ ///
82+ /// WARNING: Some products use the Hadoop S3 implementation which falls back to us-east-2.
83+ #[ serde( default ) ]
84+ pub region : Region ,
85+
86+ /// Which access style to use.
87+ /// Defaults to virtual hosted-style as most of the data products out there.
88+ /// Have a look at the [AWS documentation](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html).
89+ #[ serde( default ) ]
90+ pub access_style : S3AccessStyle ,
91+
92+ /// If the S3 uses authentication you have to specify you S3 credentials.
93+ /// In the most cases a [SecretClass](DOCS_BASE_URL_PLACEHOLDER/secret-operator/secretclass)
94+ /// providing `accessKey` and `secretKey` is sufficient.
95+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
96+ pub credentials : Option < SecretClassVolume > ,
97+
98+ /// Use a TLS connection. If not specified no TLS will be used.
99+ #[ serde( flatten) ]
100+ pub tls : TlsClientDetails ,
101+ }
100102
101- #[ derive(
102- strum:: Display , Clone , Debug , Default , Deserialize , Eq , JsonSchema , PartialEq , Serialize ,
103- ) ]
104- #[ strum( serialize_all = "PascalCase" ) ]
105- pub enum S3AccessStyle {
106- /// Use path-style access as described in <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#path-style-access>
107- Path ,
108-
109- /// Use as virtual hosted-style access as described in <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#virtual-hosted-style-access>
110- #[ default]
111- VirtualHosted ,
112- }
103+ #[ derive(
104+ strum:: Display , Clone , Debug , Default , Deserialize , Eq , JsonSchema , PartialEq , Serialize ,
105+ ) ]
106+ #[ strum( serialize_all = "PascalCase" ) ]
107+ pub enum S3AccessStyle {
108+ /// Use path-style access as described in <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#path-style-access>
109+ Path ,
110+
111+ /// Use as virtual hosted-style access as described in <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#virtual-hosted-style-access>
112+ #[ default]
113+ VirtualHosted ,
114+ }
113115
114- /// Set a named S3 Bucket region.
115- #[ derive( Clone , Debug , Deserialize , Eq , JsonSchema , PartialEq , Serialize ) ]
116- #[ serde( rename_all = "camelCase" ) ]
117- pub struct Region {
118- #[ serde( default = "Region::default_region_name" ) ]
119- pub name : String ,
116+ /// Set a named S3 Bucket region.
117+ #[ derive( Clone , Debug , Deserialize , Eq , JsonSchema , PartialEq , Serialize ) ]
118+ #[ serde( rename_all = "camelCase" ) ]
119+ pub struct Region {
120+ #[ serde( default = "v1alpha1::Region::default_region_name" ) ]
121+ pub name : String ,
122+ }
123+
124+ #[ derive( Clone , Debug , Deserialize , Eq , JsonSchema , PartialEq , Serialize ) ]
125+ #[ serde( rename_all = "camelCase" ) ]
126+ // TODO: This probably should be serde(untagged), but this would be a breaking change
127+ pub enum InlineConnectionOrReference {
128+ Inline ( ConnectionSpec ) ,
129+ Reference ( String ) ,
130+ }
120131}
121132
122- impl Region {
133+ impl v1alpha1 :: Region {
123134 /// Having it as `const &str` as well, so we don't always allocate a [`String`] just for comparisons
124135 pub const DEFAULT_REGION_NAME : & str = "us-east-1" ;
125136
@@ -137,26 +148,18 @@ impl Region {
137148 }
138149}
139150
140- impl Default for Region {
151+ impl Default for v1alpha1 :: Region {
141152 fn default ( ) -> Self {
142153 Self {
143154 name : Self :: default_region_name ( ) ,
144155 }
145156 }
146157}
147158
148- #[ derive( Clone , Debug , Deserialize , Eq , JsonSchema , PartialEq , Serialize ) ]
149- #[ serde( rename_all = "camelCase" ) ]
150- // TODO: This probably should be serde(untagged), but this would be a breaking change
151- pub enum ConnectionInlineOrReference {
152- Inline ( ConnectionSpec ) ,
153- Reference ( String ) ,
154- }
155-
156159/// Use this type in you operator!
157- pub type ResolvedConnection = ConnectionSpec ;
160+ pub type ResolvedConnection = v1alpha1 :: ConnectionSpec ;
158161
159- impl ConnectionInlineOrReference {
162+ impl v1alpha1 :: InlineConnectionOrReference {
160163 pub async fn resolve (
161164 self ,
162165 client : & Client ,
@@ -166,7 +169,7 @@ impl ConnectionInlineOrReference {
166169 Self :: Inline ( inline) => Ok ( inline) ,
167170 Self :: Reference ( reference) => {
168171 let connection_spec = client
169- . get :: < S3Connection > ( & reference, namespace)
172+ . get :: < v1alpha1 :: S3Connection > ( & reference, namespace)
170173 . await
171174 . context ( RetrieveS3ConnectionSnafu {
172175 s3_connection : reference,
0 commit comments