File tree Expand file tree Collapse file tree 2 files changed +28
-14
lines changed Expand file tree Collapse file tree 2 files changed +28
-14
lines changed Original file line number Diff line number Diff line change @@ -55,15 +55,25 @@ func (pt *imageTagTransformer) Transform(resources resmap.ResMap) error {
55
55
then loops though all images inside containers session, finds matched ones and update the tag name
56
56
*/
57
57
func (pt * imageTagTransformer ) findAndReplaceTag (obj map [string ]interface {}) error {
58
- _ , found := obj ["containers" ]
59
- if found {
60
- return pt .updateContainers (obj )
58
+ paths := []string {"containers" , "initContainers" }
59
+ found := false
60
+ for _ , path := range paths {
61
+ _ , found = obj [path ]
62
+ if found {
63
+ err := pt .updateContainers (obj , path )
64
+ if err != nil {
65
+ return err
66
+ }
67
+ }
68
+ }
69
+ if ! found {
70
+ return pt .findContainers (obj )
61
71
}
62
- return pt . findContainers ( obj )
72
+ return nil
63
73
}
64
74
65
- func (pt * imageTagTransformer ) updateContainers (obj map [string ]interface {}) error {
66
- containers := obj ["containers" ].([]interface {})
75
+ func (pt * imageTagTransformer ) updateContainers (obj map [string ]interface {}, path string ) error {
76
+ containers := obj [path ].([]interface {})
67
77
for i := range containers {
68
78
container := containers [i ].(map [string ]interface {})
69
79
image , found := container ["image" ]
Original file line number Diff line number Diff line change @@ -39,15 +39,17 @@ func TestImageTagTransformer(t *testing.T) {
39
39
"spec" : map [string ]interface {}{
40
40
"template" : map [string ]interface {}{
41
41
"spec" : map [string ]interface {}{
42
+ "initContainers" : []interface {}{
43
+ map [string ]interface {}{
44
+ "name" : "nginx2" ,
45
+ "image" : "my-nginx:1.8.0" ,
46
+ },
47
+ },
42
48
"containers" : []interface {}{
43
49
map [string ]interface {}{
44
50
"name" : "nginx" ,
45
51
"image" : "nginx:1.7.9" ,
46
52
},
47
- map [string ]interface {}{
48
- "name" : "nginx2" ,
49
- "image" : "my-nginx:1.8.0" ,
50
- },
51
53
},
52
54
},
53
55
},
@@ -101,15 +103,17 @@ func TestImageTagTransformer(t *testing.T) {
101
103
"spec" : map [string ]interface {}{
102
104
"template" : map [string ]interface {}{
103
105
"spec" : map [string ]interface {}{
106
+ "initContainers" : []interface {}{
107
+ map [string ]interface {}{
108
+ "name" : "nginx2" ,
109
+ "image" : "my-nginx:previous" ,
110
+ },
111
+ },
104
112
"containers" : []interface {}{
105
113
map [string ]interface {}{
106
114
"name" : "nginx" ,
107
115
"image" : "nginx:v2" ,
108
116
},
109
- map [string ]interface {}{
110
- "name" : "nginx2" ,
111
- "image" : "my-nginx:previous" ,
112
- },
113
117
},
114
118
},
115
119
},
You can’t perform that action at this time.
0 commit comments