Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JobBackoffLimitPerIndex feature gate fields #2421

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions kubernetes/schema_job_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ func jobSpecFields(specUpdatable bool) map[string]*schema.Schema {
ValidateFunc: validateNonNegativeInteger,
Description: "Specifies the number of retries before marking this job failed. Defaults to 6",
},
"backoff_limit_per_index": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's errors with the PR specifically due to the default value being used. Could you address these failures as well as include a test case for these new fields?

This is now supported with the feature gate being set to true by default. Let me know if there's anything unclear from adding tests.

 === NAME  TestAccKubernetesCronJobV1_minimalWithPodFailurePolicy
    resource_kubernetes_cron_job_v1_test.go:179: Step 1/2 error: Error running apply: exit status 1
        
        Error: CronJob.batch "tf-acc-test-jk4onc8cdw" is invalid: [spec.jobTemplate.spec.backoffLimitPerIndex: Invalid value: 6: requires indexed completion mode, spec.jobTemplate.spec.maxFailedIndexes: Invalid value: 6: requires indexed completion mode]
        
          with kubernetes_cron_job_v1.test,
          on terraform_plugin_test.tf line 1, in resource "kubernetes_cron_job_v1" "test":
           1: resource "kubernetes_cron_job_v1" "test" {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any help needed on this @theloneexplorerquest ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a heads-up I'll be wrapping this up to get it merged as this is part of our v2.33.0 milestone @theloneexplorerquest

Type: schema.TypeInt,
Optional: true,
Default: 6,
ForceNew: false,
ValidateFunc: validateNonNegativeInteger,
Description: "Specifies the limit for the number of retries within an index before marking this index as failed. When enabled the number of failures per index is kept in the pod's batch.kubernetes.io/job-index-failure-count annotation. It can only be set when Job's completionMode=Indexed, and the Pod's restart policy is Never. The field is immutable.",
},
// This field is immutable in Jobs.
"completions": {
Type: schema.TypeInt,
Expand All @@ -83,6 +91,14 @@ func jobSpecFields(specUpdatable bool) map[string]*schema.Schema {
ForceNew: false,
Description: "Controls generation of pod labels and pod selectors. Leave unset unless you are certain what you are doing. When false or unset, the system pick labels unique to this job and appends those labels to the pod template. When true, the user is responsible for picking unique labels and specifying the selector. Failure to pick a unique label may cause this and other jobs to not function correctly. More info: https://git.k8s.io/community/contributors/design-proposals/selector-generation.md",
},
"max_failed_indexes": {
Type: schema.TypeInt,
Optional: true,
ForceNew: false,
Default: 6,
ValidateFunc: validateNonNegativeInteger,
Description: "Controls generation of pod labels and pod selectors. Leave unset unless you are certain what you are doing. When false or unset, the system pick labels unique to this job and appends those labels to the pod template. When true, the user is responsible for picking unique labels and specifying the selector. Failure to pick a unique label may cause this and other jobs to not function correctly. More info: https://git.k8s.io/community/contributors/design-proposals/selector-generation.md",
},
"parallelism": {
Type: schema.TypeInt,
Optional: true,
Expand Down
8 changes: 8 additions & 0 deletions kubernetes/structure_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func expandJobV1Spec(j []interface{}) (batchv1.JobSpec, error) {
obj.BackoffLimit = ptr.To(int32(v))
}

if v, ok := in["backoff_limit_per_index"].(int); ok && v >= 0 {
obj.BackoffLimitPerIndex = ptr.To(int32(v))
}

if v, ok := in["completions"].(int); ok && v > 0 {
obj.Completions = ptr.To(int32(v))
}
Expand All @@ -92,6 +96,10 @@ func expandJobV1Spec(j []interface{}) (batchv1.JobSpec, error) {
obj.ManualSelector = ptr.To(v.(bool))
}

if v, ok := in["max_failed_indexes"].(int); ok && v >= 0 {
obj.MaxFailedIndexes = ptr.To(int32(v))
}

if v, ok := in["parallelism"].(int); ok && v >= 0 {
obj.Parallelism = ptr.To(int32(v))
}
Expand Down
Loading