Skip to content

Commit

Permalink
support custom backOffLimit in HelmConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Mehta <[email protected]>
  • Loading branch information
ibrokethecloud authored and brandond committed Jul 28, 2023
1 parent 7ca672b commit 345c53c
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 364 deletions.
1 change: 1 addition & 0 deletions pkg/apis/helm.cattle.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type HelmChartSpec struct {
Bootstrap bool `json:"bootstrap,omitempty"`
ChartContent string `json:"chartContent,omitempty"`
JobImage string `json:"jobImage,omitempty"`
BackOffLimit *int32 `json:"backOffLimit,omitempty"`
Timeout *metav1.Duration `json:"timeout,omitempty"`
FailurePolicy string `json:"failurePolicy,omitempty"`
AuthSecret *corev1.LocalObjectReference `json:"authSecret,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/helm.cattle.io/v1/zz_generated_deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion pkg/controllers/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
deletePolicy = metav1.DeletePropagationForeground
DefaultJobImage = "rancher/klipper-helm:v0.8.0-build20230510"
DefaultFailurePolicy = FailurePolicyReinstall
defaultBackOffLimit = pointer.Int32(1000)
)

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

// override default backOffLimit if specified
backOffLimit := defaultBackOffLimit
if chart.Spec.BackOffLimit != nil {
backOffLimit = chart.Spec.BackOffLimit
}

// get the default job and configmaps
job, valuesSecret, contentConfigMap := job(chart, c.apiServerPort)

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

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

job.Spec.Template.ObjectMeta.Annotations[Annotation] = fmt.Sprintf("SHA256=%X", hash.Sum(nil))
}

func setBackOffLimit(job *batch.Job, backOffLimit *int32) {
job.Spec.BackoffLimit = backOffLimit
}
242 changes: 62 additions & 180 deletions pkg/generated/controllers/helm.cattle.io/v1/helmchart.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 345c53c

Please sign in to comment.