@@ -7,9 +7,9 @@ use crate::error::{Error, OperatorResult};
7
7
8
8
use k8s_openapi:: {
9
9
api:: core:: v1:: {
10
- Affinity , Container , NodeAffinity , NodeSelector , NodeSelectorRequirement , NodeSelectorTerm ,
11
- Pod , PodAffinity , PodCondition , PodSecurityContext , PodSpec , PodStatus , PodTemplateSpec ,
12
- Toleration , Volume ,
10
+ Affinity , Container , LocalObjectReference , NodeAffinity , NodeSelector ,
11
+ NodeSelectorRequirement , NodeSelectorTerm , Pod , PodAffinity , PodCondition ,
12
+ PodSecurityContext , PodSpec , PodStatus , PodTemplateSpec , Toleration , Volume ,
13
13
} ,
14
14
apimachinery:: pkg:: apis:: meta:: v1:: { LabelSelector , LabelSelectorRequirement , ObjectMeta } ,
15
15
} ;
@@ -31,6 +31,7 @@ pub struct PodBuilder {
31
31
tolerations : Option < Vec < Toleration > > ,
32
32
volumes : Option < Vec < Volume > > ,
33
33
service_account_name : Option < String > ,
34
+ image_pull_secrets : Option < Vec < LocalObjectReference > > ,
34
35
}
35
36
36
37
impl PodBuilder {
@@ -145,6 +146,16 @@ impl PodBuilder {
145
146
self
146
147
}
147
148
149
+ pub fn image_pull_secrets (
150
+ & mut self ,
151
+ secrets : impl IntoIterator < Item = String > + Iterator < Item = String > ,
152
+ ) -> & mut Self {
153
+ self . image_pull_secrets
154
+ . get_or_insert_with ( Vec :: new)
155
+ . extend ( secrets. map ( |s| LocalObjectReference { name : Some ( s) } ) ) ;
156
+ self
157
+ }
158
+
148
159
/// Hack because [`Pod`] predates [`LabelSelector`], and so its functionality is split between [`PodSpec::node_selector`] and [`Affinity::node_affinity`]
149
160
fn node_selector_for_label_selector (
150
161
label_selector : Option < LabelSelector > ,
@@ -215,6 +226,7 @@ impl PodBuilder {
215
226
// such as https://github.com/stackabletech/spark-operator/pull/256.
216
227
enable_service_links : Some ( false ) ,
217
228
service_account_name : self . service_account_name . clone ( ) ,
229
+ image_pull_secrets : self . image_pull_secrets . clone ( ) ,
218
230
..PodSpec :: default ( )
219
231
}
220
232
}
@@ -246,15 +258,14 @@ impl PodBuilder {
246
258
247
259
#[ cfg( test) ]
248
260
mod tests {
249
- use k8s_openapi:: {
250
- api:: core:: v1:: { PodAffinity , PodAffinityTerm } ,
251
- apimachinery:: pkg:: apis:: meta:: v1:: { LabelSelector , LabelSelectorRequirement } ,
252
- } ;
253
-
254
261
use crate :: builder:: {
255
262
meta:: ObjectMetaBuilder ,
256
263
pod:: { container:: ContainerBuilder , volume:: VolumeBuilder , PodBuilder } ,
257
264
} ;
265
+ use k8s_openapi:: {
266
+ api:: core:: v1:: { LocalObjectReference , PodAffinity , PodAffinityTerm } ,
267
+ apimachinery:: pkg:: apis:: meta:: v1:: { LabelSelector , LabelSelectorRequirement } ,
268
+ } ;
258
269
259
270
#[ test]
260
271
fn test_pod_builder ( ) {
@@ -333,4 +344,25 @@ mod tests {
333
344
334
345
assert_eq ! ( pod. metadata. name. unwrap( ) , "foo" ) ;
335
346
}
347
+
348
+ #[ test]
349
+ fn test_pod_builder_image_pull_secrets ( ) {
350
+ let container = ContainerBuilder :: new ( "container" )
351
+ . image ( "private-comapany/product:2.4.14" )
352
+ . build ( ) ;
353
+
354
+ let pod = PodBuilder :: new ( )
355
+ . metadata ( ObjectMetaBuilder :: new ( ) . name ( "testpod" ) . build ( ) )
356
+ . add_container ( container)
357
+ . image_pull_secrets ( vec ! [ "company-registry-secret" . to_string( ) ] . into_iter ( ) )
358
+ . build ( )
359
+ . unwrap ( ) ;
360
+
361
+ assert_eq ! (
362
+ pod. spec. unwrap( ) . image_pull_secrets. unwrap( ) ,
363
+ vec![ LocalObjectReference {
364
+ name: Some ( "company-registry-secret" . to_string( ) )
365
+ } ]
366
+ ) ;
367
+ }
336
368
}
0 commit comments