Skip to content

Commit 4ff46e3

Browse files
committed
Transfer the template value into the created Job.
1 parent a669058 commit 4ff46e3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

controllers/bootstrap.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ func jobFromTemplate(cl *gitopsv1alpha1.GitopsCluster, jt capiv1alpha1.JobTempla
4141
Template: corev1.PodTemplateSpec{
4242
Spec: jt.Spec,
4343
},
44-
BackoffLimit: jt.BackoffLimit,
44+
BackoffLimit: jt.BackoffLimit,
45+
TTLSecondsAfterFinished: jt.TTLSecondsAfterFinished,
4546
},
4647
}
4748
}

controllers/bootstrap_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,27 @@ func makeTestPodSpecWithVolumes(volumes ...corev1.Volume) corev1.PodSpec {
120120
}
121121
}
122122

123+
func Test_bootstrapClusterWithConfig_sets_job_ttl(t *testing.T) {
124+
bc := makeTestClusterBootstrapConfig(func(cfg *capiv1alpha1.ClusterBootstrapConfig) {
125+
cfg.Spec.Template.TTLSecondsAfterFinished = ptrutils.Int32Ptr(66)
126+
})
127+
cl := makeTestCluster()
128+
tc := makeTestClient(t)
129+
130+
if err := bootstrapClusterWithConfig(context.TODO(), logr.Discard(), tc, cl, bc); err != nil {
131+
t.Fatal(err)
132+
}
133+
134+
var jobList batchv1.JobList
135+
if err := tc.List(context.TODO(), &jobList, client.InNamespace(testNamespace)); err != nil {
136+
t.Fatal(err)
137+
}
138+
139+
if ttl := *jobList.Items[0].Spec.TTLSecondsAfterFinished; ttl != 66 {
140+
t.Fatalf("got TTLSecondsAfterFinished %v, want %v", ttl, 66)
141+
}
142+
}
143+
123144
func makeTestCluster(opts ...func(*gitopsv1alpha1.GitopsCluster)) *gitopsv1alpha1.GitopsCluster {
124145
c := &gitopsv1alpha1.GitopsCluster{
125146
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)