@@ -143,26 +143,29 @@ spec:
143143apiVersion: apps/v1
144144kind: Deployment
145145metadata:
146- name: nginx-deployment
147- labels:
148- app: nginx
146+ name: nginx-deployment
147+ labels:
148+ app: nginx
149149spec:
150- replicas: 3
151- selector:
152- matchLabels:
153- app: nginx
154- template:
155- metadata:
156- labels:
157- app: nginx
158- spec:
159- imagePullSecrets:
160- - name: myregistrykey
161- containers:
162- - name: nginx
163- image: nginx:1.14.2
164- ports:
165- - containerPort: 80
150+ replicas: 3
151+ selector:
152+ matchLabels:
153+ app: nginx
154+ template:
155+ metadata:
156+ labels:
157+ app: nginx
158+ spec:
159+ containers:
160+ - name: nginx
161+ image: nginx:1.14.2
162+ args:
163+ - --test
164+ - --arg
165+ ports:
166+ - containerPort: 80
167+ imagePullSecrets:
168+ - name: myregistrykey
166169`
167170)
168171
@@ -380,6 +383,22 @@ func Test_pod_Process(t *testing.T) {
380383 assert .False (t , ok )
381384 })
382385
386+ t .Run ("deployment with imagePullSecrets enabled but not provided in source" , func (t * testing.T ) {
387+ var deploy appsv1.Deployment
388+ obj := internal .GenerateObj (strDeployment )
389+ err := runtime .DefaultUnstructuredConverter .FromUnstructured (obj .Object , & deploy )
390+ assert .NoError (t , err )
391+ // enable ImagePullSecrets in config via metadata.New but source doesn't include imagePullSecrets
392+ svc := metadata .New (config.Config {ImagePullSecrets : true })
393+ specMap , tmpl , err := ProcessSpec ("nginx" , svc , deploy .Spec .Template .Spec )
394+ assert .NoError (t , err )
395+
396+ // spec should contain templated imagePullSecrets
397+ assert .Equal (t , "{{ .Values.imagePullSecrets | default list | toJson }}" , specMap ["imagePullSecrets" ])
398+
399+ assert .Equal (t , []interface {}{}, tmpl ["imagePullSecrets" ])
400+ })
401+
383402 t .Run ("deployment with imagePullSecrets" , func (t * testing.T ) {
384403
385404 var deploy appsv1.Deployment
@@ -395,11 +414,9 @@ func Test_pod_Process(t *testing.T) {
395414 assert .Equal (t , "{{ .Values.imagePullSecrets | default list | toJson }}" , specMap ["imagePullSecrets" ])
396415
397416 // values should contain the original imagePullSecrets slice
398- assert .Equal (t , helmify.Values {
399- "imagePullSecrets" : []interface {}{
400- map [string ]interface {}{"name" : "myregistrykey" },
401- },
402- }, tmpl )
417+ assert .Equal (t , []interface {}{
418+ map [string ]interface {}{"name" : "myregistrykey" },
419+ }, tmpl ["imagePullSecrets" ])
403420 })
404421
405422}
0 commit comments