Skip to content

Commit 6976581

Browse files
authored
Merge pull request #21 from bigkevmcd/replace-cronjobs
Apply image updates to CronJob objects
2 parents 51a31cf + aad1df6 commit 6976581

File tree

5 files changed

+81
-11
lines changed

5 files changed

+81
-11
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: batch/v1beta1
2+
kind: CronJob
3+
metadata:
4+
name: foo
5+
namespace: bar
6+
spec:
7+
schedule: "*/1 * * * *"
8+
jobTemplate:
9+
spec:
10+
template:
11+
spec:
12+
containers:
13+
- name: c
14+
image: helloworld:v1.0.0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: batch/v1beta1
2+
kind: CronJob
3+
metadata:
4+
name: foo
5+
namespace: bar
6+
spec:
7+
schedule: "*/1 * * * *"
8+
jobTemplate:
9+
spec:
10+
template:
11+
spec:
12+
containers:
13+
- name: c
14+
image: helloworld:v1.0.0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: batch/v1beta1
2+
kind: CronJob
3+
metadata:
4+
name: foo
5+
namespace: bar
6+
spec:
7+
schedule: "*/1 * * * *"
8+
jobTemplate:
9+
spec:
10+
template:
11+
spec:
12+
containers:
13+
- name: c
14+
image: used:v1.1.0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: batch/v1beta1
2+
kind: CronJob
3+
metadata:
4+
name: foo
5+
namespace: bar
6+
spec:
7+
schedule: "*/1 * * * *"
8+
jobTemplate:
9+
spec:
10+
template:
11+
spec:
12+
containers:
13+
- name: c
14+
image: used:v1.0.0

pkg/update/update.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,35 @@ func makeUpdateImagesFilter(originalRepo, replacement string) kio.Filter {
5656
})
5757

5858
return kio.FilterFunc(func(objs []*yaml.RNode) ([]*yaml.RNode, error) {
59+
tees := []yaml.Filter{
60+
yaml.Tee(
61+
yaml.Lookup("initContainers"),
62+
replaceImageInEachContainer,
63+
),
64+
yaml.Tee(
65+
yaml.Lookup("containers"),
66+
replaceImageInEachContainer,
67+
),
68+
}
69+
5970
for _, obj := range objs {
60-
if err := obj.PipeE(
61-
yaml.Lookup("spec", "template", "spec"),
62-
yaml.Tee(
63-
yaml.Lookup("initContainers"),
64-
replaceImageInEachContainer,
65-
),
66-
yaml.Tee(
67-
yaml.Lookup("containers"),
68-
replaceImageInEachContainer,
69-
),
70-
); err != nil {
71+
lookup := yaml.Lookup("spec", "template", "spec")
72+
switch kind(obj) {
73+
case "CronJob":
74+
lookup = yaml.Lookup("spec", "jobTemplate", "spec", "template", "spec")
75+
}
76+
if err := obj.PipeE(append([]yaml.Filter{lookup}, tees...)...); err != nil {
7177
return nil, err
7278
}
7379
}
7480
return objs, nil
7581
})
7682
}
83+
84+
func kind(a *yaml.RNode) string {
85+
f := a.Field(yaml.KindField)
86+
if f != nil {
87+
return yaml.GetValue(f.Value)
88+
}
89+
return ""
90+
}

0 commit comments

Comments
 (0)