Skip to content

Commit 5851f96

Browse files
committed
Add initContainers in imageTagTransformer
1 parent 5906aab commit 5851f96

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

pkg/transformers/imagetag.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,25 @@ func (pt *imageTagTransformer) Transform(resources resmap.ResMap) error {
5555
then loops though all images inside containers session, finds matched ones and update the tag name
5656
*/
5757
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)
6171
}
62-
return pt.findContainers(obj)
72+
return nil
6373
}
6474

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{})
6777
for i := range containers {
6878
container := containers[i].(map[string]interface{})
6979
image, found := container["image"]

pkg/transformers/imagetag_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ func TestImageTagTransformer(t *testing.T) {
3939
"spec": map[string]interface{}{
4040
"template": map[string]interface{}{
4141
"spec": map[string]interface{}{
42+
"initContainers": []interface{}{
43+
map[string]interface{}{
44+
"name": "nginx2",
45+
"image": "my-nginx:1.8.0",
46+
},
47+
},
4248
"containers": []interface{}{
4349
map[string]interface{}{
4450
"name": "nginx",
4551
"image": "nginx:1.7.9",
4652
},
47-
map[string]interface{}{
48-
"name": "nginx2",
49-
"image": "my-nginx:1.8.0",
50-
},
5153
},
5254
},
5355
},
@@ -101,15 +103,17 @@ func TestImageTagTransformer(t *testing.T) {
101103
"spec": map[string]interface{}{
102104
"template": map[string]interface{}{
103105
"spec": map[string]interface{}{
106+
"initContainers": []interface{}{
107+
map[string]interface{}{
108+
"name": "nginx2",
109+
"image": "my-nginx:previous",
110+
},
111+
},
104112
"containers": []interface{}{
105113
map[string]interface{}{
106114
"name": "nginx",
107115
"image": "nginx:v2",
108116
},
109-
map[string]interface{}{
110-
"name": "nginx2",
111-
"image": "my-nginx:previous",
112-
},
113117
},
114118
},
115119
},

0 commit comments

Comments
 (0)