Skip to content

Commit 345c53c

Browse files
ibrokethecloudbrandond
authored andcommitted
support custom backOffLimit in HelmConfig
Signed-off-by: Gaurav Mehta <gaurav@rancher.com>
1 parent 7ca672b commit 345c53c

File tree

8 files changed

+261
-364
lines changed

8 files changed

+261
-364
lines changed

pkg/apis/helm.cattle.io/v1/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type HelmChartSpec struct {
3232
Bootstrap bool `json:"bootstrap,omitempty"`
3333
ChartContent string `json:"chartContent,omitempty"`
3434
JobImage string `json:"jobImage,omitempty"`
35+
BackOffLimit *int32 `json:"backOffLimit,omitempty"`
3536
Timeout *metav1.Duration `json:"timeout,omitempty"`
3637
FailurePolicy string `json:"failurePolicy,omitempty"`
3738
AuthSecret *corev1.LocalObjectReference `json:"authSecret,omitempty"`

pkg/apis/helm.cattle.io/v1/zz_generated_deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controllers/chart/chart.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var (
5555
deletePolicy = metav1.DeletePropagationForeground
5656
DefaultJobImage = "rancher/klipper-helm:v0.8.0-build20230510"
5757
DefaultFailurePolicy = FailurePolicyReinstall
58+
defaultBackOffLimit = pointer.Int32(1000)
5859
)
5960

6061
type Controller struct {
@@ -310,6 +311,12 @@ func (c *Controller) getJobAndRelatedResources(chart *v1.HelmChart) (*batch.Job,
310311
failurePolicy = chart.Spec.FailurePolicy
311312
}
312313

314+
// override default backOffLimit if specified
315+
backOffLimit := defaultBackOffLimit
316+
if chart.Spec.BackOffLimit != nil {
317+
backOffLimit = chart.Spec.BackOffLimit
318+
}
319+
313320
// get the default job and configmaps
314321
job, valuesSecret, contentConfigMap := job(chart, c.apiServerPort)
315322

@@ -332,6 +339,7 @@ func (c *Controller) getJobAndRelatedResources(chart *v1.HelmChart) (*batch.Job,
332339
// note: the purpose of the additional annotation is to cause the job to be destroyed
333340
// and recreated if the hash of the HelmChartConfig changes while it is being processed
334341
setFailurePolicy(job, failurePolicy)
342+
setBackOffLimit(job, backOffLimit)
335343
hashObjects(job, contentConfigMap, valuesSecret)
336344

337345
return job, []runtime.Object{
@@ -376,7 +384,6 @@ func job(chart *v1.HelmChart, apiServerPort string) (*batch.Job, *corev1.Secret,
376384
},
377385
},
378386
Spec: batch.JobSpec{
379-
BackoffLimit: pointer.Int32Ptr(1000),
380387
Template: corev1.PodTemplateSpec{
381388
ObjectMeta: metav1.ObjectMeta{
382389
Annotations: map[string]string{},
@@ -814,3 +821,7 @@ func hashObjects(job *batch.Job, objs ...metav1.Object) {
814821

815822
job.Spec.Template.ObjectMeta.Annotations[Annotation] = fmt.Sprintf("SHA256=%X", hash.Sum(nil))
816823
}
824+
825+
func setBackOffLimit(job *batch.Job, backOffLimit *int32) {
826+
job.Spec.BackoffLimit = backOffLimit
827+
}

pkg/generated/controllers/helm.cattle.io/v1/helmchart.go

Lines changed: 62 additions & 180 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)