Skip to content

Commit 06843c9

Browse files
committed
Fail the job instead of restarting if the exit code indicates unsupported chart version
Signed-off-by: Brad Davidson <[email protected]>
1 parent 9e978aa commit 06843c9

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

pkg/controllers/chart/chart.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const (
5353
var (
5454
commaRE = regexp.MustCompile(`\\*,`)
5555
deletePolicy = metav1.DeletePropagationForeground
56-
DefaultJobImage = "rancher/klipper-helm:v0.9.0-build20240730"
56+
DefaultJobImage = "rancher/klipper-helm:v0.9.1-build20240731"
5757
DefaultFailurePolicy = FailurePolicyReinstall
5858
defaultBackOffLimit = pointer.Int32(1000)
5959

@@ -409,6 +409,18 @@ func job(chart *v1.HelmChart, apiServerPort string) (*batch.Job, *corev1.Secret,
409409
},
410410
},
411411
Spec: batch.JobSpec{
412+
PodFailurePolicy: &batch.PodFailurePolicy{
413+
Rules: []batch.PodFailurePolicyRule{
414+
{
415+
Action: batch.PodFailurePolicyActionFailJob,
416+
OnExitCodes: &batch.PodFailurePolicyOnExitCodesRequirement{
417+
ContainerName: pointer.String("helm"),
418+
Operator: batch.PodFailurePolicyOnExitCodesOpIn,
419+
Values: []int32{64},
420+
},
421+
},
422+
},
423+
},
412424
Template: corev1.PodTemplateSpec{
413425
ObjectMeta: metav1.ObjectMeta{
414426
Annotations: map[string]string{},
@@ -417,7 +429,7 @@ func job(chart *v1.HelmChart, apiServerPort string) (*batch.Job, *corev1.Secret,
417429
},
418430
},
419431
Spec: corev1.PodSpec{
420-
RestartPolicy: corev1.RestartPolicyOnFailure,
432+
RestartPolicy: corev1.RestartPolicyNever,
421433
Containers: []corev1.Container{
422434
{
423435
Name: "helm",

test/framework/framework.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,13 @@ func (f *Framework) GetChartContent(url string) (string, error) {
236236
}
237237
return string(b.Bytes()), nil
238238
}
239+
240+
// GetJobCondition returns true if there is a condition on the job matching the selected type and status
241+
func (f *Framework) GetJobCondition(job *batchv1.Job, condition batchv1.JobConditionType, status corev1.ConditionStatus) bool {
242+
for _, v := range job.Status.Conditions {
243+
if v.Type == condition && v.Status == status {
244+
return true
245+
}
246+
}
247+
return false
248+
}

test/suite/helm_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package suite_test
22

33
import (
44
"context"
5+
"fmt"
56
"time"
67

78
. "github.com/onsi/ginkgo/v2"
@@ -376,12 +377,21 @@ var _ = Describe("Helm Tests", Ordered, func() {
376377
chart, err = framework.CreateHelmChart(chart, framework.Namespace)
377378
Expect(err).ToNot(HaveOccurred())
378379
})
379-
It("Should return error status", func() {
380-
chart, err = framework.GetHelmChart(chart.Name, chart.Namespace)
381-
Eventually(err, 120*time.Second).ShouldNot(HaveOccurred())
382-
job, err = framework.GetJob(chart)
383-
Eventually(err, 120*time.Second).ShouldNot(HaveOccurred())
384-
Eventually(job.Status.Failed, 120*time.Second).Should(BeNumerically(">", 0))
380+
It("Job should have failed condition", func() {
381+
Eventually(func() error {
382+
chart, err = framework.GetHelmChart(chart.Name, chart.Namespace)
383+
if err != nil {
384+
return err
385+
}
386+
job, err = framework.GetJob(chart)
387+
if err != nil {
388+
return err
389+
}
390+
if !framework.GetJobCondition(job, batchv1.JobFailed, corev1.ConditionTrue) {
391+
return fmt.Errorf("expected condition %v=%v not found", batchv1.JobFailed, corev1.ConditionTrue)
392+
}
393+
return nil
394+
}, 120*time.Second).ShouldNot(HaveOccurred())
385395
})
386396
})
387397

0 commit comments

Comments
 (0)