@@ -31,7 +31,7 @@ pub struct S3BucketSpec {
31
31
#[ serde( default , skip_serializing_if = "Option::is_none" ) ]
32
32
pub bucket_name : Option < String > ,
33
33
#[ serde( default , skip_serializing_if = "Option::is_none" ) ]
34
- pub connection : Option < ConnectionDef > ,
34
+ pub connection : Option < S3ConnectionDef > ,
35
35
}
36
36
37
37
impl S3BucketSpec {
@@ -57,14 +57,10 @@ impl S3BucketSpec {
57
57
namespace : Option < & str > ,
58
58
) -> OperatorResult < InlinedS3BucketSpec > {
59
59
match self . connection . as_ref ( ) {
60
- Some ( ConnectionDef :: Reference ( res_name ) ) => Ok ( InlinedS3BucketSpec {
61
- connection : Some ( S3ConnectionSpec :: get ( res_name , client, namespace) . await ?) ,
60
+ Some ( connection_def ) => Ok ( InlinedS3BucketSpec {
61
+ connection : Some ( connection_def . resolve ( client, namespace) . await ?) ,
62
62
bucket_name : self . bucket_name . clone ( ) ,
63
63
} ) ,
64
- Some ( ConnectionDef :: Inline ( conn_spec) ) => Ok ( InlinedS3BucketSpec {
65
- bucket_name : self . bucket_name . clone ( ) ,
66
- connection : Some ( conn_spec. clone ( ) ) ,
67
- } ) ,
68
64
None => Ok ( InlinedS3BucketSpec {
69
65
bucket_name : self . bucket_name . clone ( ) ,
70
66
connection : None ,
@@ -135,8 +131,8 @@ impl S3BucketDef {
135
131
) -> OperatorResult < InlinedS3BucketSpec > {
136
132
match self {
137
133
S3BucketDef :: Inline ( s3_bucket) => s3_bucket. inlined ( client, namespace) . await ,
138
- S3BucketDef :: Reference ( _s3_bucket ) => {
139
- S3BucketSpec :: get ( _s3_bucket . as_str ( ) , client, namespace)
134
+ S3BucketDef :: Reference ( s3_bucket ) => {
135
+ S3BucketSpec :: get ( s3_bucket . as_str ( ) , client, namespace)
140
136
. await ?
141
137
. inlined ( client, namespace)
142
138
. await
@@ -145,14 +141,30 @@ impl S3BucketDef {
145
141
}
146
142
}
147
143
148
- /// S3 connection definition used by [S3BucketSpec]
144
+ /// Operators are expected to define fields for this type in order to work with S3 connections.
149
145
#[ derive( Clone , Debug , Deserialize , JsonSchema , PartialEq , Serialize ) ]
150
146
#[ serde( rename_all = "camelCase" ) ]
151
- pub enum ConnectionDef {
147
+ pub enum S3ConnectionDef {
152
148
Inline ( S3ConnectionSpec ) ,
153
149
Reference ( String ) ,
154
150
}
155
151
152
+ impl S3ConnectionDef {
153
+ /// Returns an [S3ConnectionSpec].
154
+ pub async fn resolve (
155
+ & self ,
156
+ client : & Client ,
157
+ namespace : Option < & str > ,
158
+ ) -> OperatorResult < S3ConnectionSpec > {
159
+ match self {
160
+ S3ConnectionDef :: Inline ( s3_connection_spec) => Ok ( s3_connection_spec. clone ( ) ) ,
161
+ S3ConnectionDef :: Reference ( s3_conn_reference) => {
162
+ S3ConnectionSpec :: get ( s3_conn_reference, client, namespace) . await
163
+ }
164
+ }
165
+ }
166
+ }
167
+
156
168
/// S3 connection definition as CRD.
157
169
#[ derive( CustomResource , Clone , Debug , Default , Deserialize , JsonSchema , PartialEq , Serialize ) ]
158
170
#[ kube(
@@ -197,14 +209,14 @@ impl S3ConnectionSpec {
197
209
198
210
#[ cfg( test) ]
199
211
mod test {
200
- use crate :: commons:: s3:: ConnectionDef ;
212
+ use crate :: commons:: s3:: S3ConnectionDef ;
201
213
use crate :: commons:: s3:: { S3BucketSpec , S3ConnectionSpec } ;
202
214
203
215
#[ test]
204
216
fn test_ser_inline ( ) {
205
217
let bucket = S3BucketSpec {
206
218
bucket_name : Some ( "test-bucket-name" . to_owned ( ) ) ,
207
- connection : Some ( ConnectionDef :: Inline ( S3ConnectionSpec {
219
+ connection : Some ( S3ConnectionDef :: Inline ( S3ConnectionSpec {
208
220
host : Some ( "host" . to_owned ( ) ) ,
209
221
port : Some ( 8080 ) ,
210
222
secret_class : None ,
0 commit comments