diff --git a/pkg/controllers/chart/chart.go b/pkg/controllers/chart/chart.go index d090b265..896c73f7 100644 --- a/pkg/controllers/chart/chart.go +++ b/pkg/controllers/chart/chart.go @@ -53,7 +53,7 @@ const ( var ( commaRE = regexp.MustCompile(`\\*,`) deletePolicy = metav1.DeletePropagationForeground - DefaultJobImage = "rancher/klipper-helm:v0.9.0-build20240730" + DefaultJobImage = "rancher/klipper-helm:v0.9.1-build20240731" DefaultFailurePolicy = FailurePolicyReinstall defaultBackOffLimit = pointer.Int32(1000) @@ -409,6 +409,18 @@ func job(chart *v1.HelmChart, apiServerPort string) (*batch.Job, *corev1.Secret, }, }, Spec: batch.JobSpec{ + PodFailurePolicy: &batch.PodFailurePolicy{ + Rules: []batch.PodFailurePolicyRule{ + { + Action: batch.PodFailurePolicyActionFailJob, + OnExitCodes: &batch.PodFailurePolicyOnExitCodesRequirement{ + ContainerName: pointer.String("helm"), + Operator: batch.PodFailurePolicyOnExitCodesOpIn, + Values: []int32{64}, + }, + }, + }, + }, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{}, @@ -417,7 +429,7 @@ func job(chart *v1.HelmChart, apiServerPort string) (*batch.Job, *corev1.Secret, }, }, Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyOnFailure, + RestartPolicy: corev1.RestartPolicyNever, Containers: []corev1.Container{ { Name: "helm", diff --git a/test/framework/framework.go b/test/framework/framework.go index b1756a3c..70db94f4 100644 --- a/test/framework/framework.go +++ b/test/framework/framework.go @@ -236,3 +236,13 @@ func (f *Framework) GetChartContent(url string) (string, error) { } return string(b.Bytes()), nil } + +// GetJobCondition returns true if there is a condition on the job matching the selected type and status +func (f *Framework) GetJobCondition(job *batchv1.Job, condition batchv1.JobConditionType, status corev1.ConditionStatus) bool { + for _, v := range job.Status.Conditions { + if v.Type == condition && v.Status == status { + return true + } + } + return false +} diff --git a/test/suite/helm_test.go b/test/suite/helm_test.go index 838f31f5..213c369d 100644 --- a/test/suite/helm_test.go +++ b/test/suite/helm_test.go @@ -2,6 +2,7 @@ package suite_test import ( "context" + "fmt" "time" . "github.com/onsi/ginkgo/v2" @@ -376,12 +377,21 @@ var _ = Describe("Helm Tests", Ordered, func() { chart, err = framework.CreateHelmChart(chart, framework.Namespace) Expect(err).ToNot(HaveOccurred()) }) - It("Should return error status", func() { - chart, err = framework.GetHelmChart(chart.Name, chart.Namespace) - Eventually(err, 120*time.Second).ShouldNot(HaveOccurred()) - job, err = framework.GetJob(chart) - Eventually(err, 120*time.Second).ShouldNot(HaveOccurred()) - Eventually(job.Status.Failed, 120*time.Second).Should(BeNumerically(">", 0)) + It("Job should have failed condition", func() { + Eventually(func() error { + chart, err = framework.GetHelmChart(chart.Name, chart.Namespace) + if err != nil { + return err + } + job, err = framework.GetJob(chart) + if err != nil { + return err + } + if !framework.GetJobCondition(job, batchv1.JobFailed, corev1.ConditionTrue) { + return fmt.Errorf("expected condition %v=%v not found", batchv1.JobFailed, corev1.ConditionTrue) + } + return nil + }, 120*time.Second).ShouldNot(HaveOccurred()) }) })