From 4a0845a890e3915ed5a995df96935c4f0fa578e0 Mon Sep 17 00:00:00 2001 From: theloneexplorerquest Date: Sat, 10 Feb 2024 20:58:55 +1100 Subject: [PATCH 01/11] update job spec --- kubernetes/schema_job_spec.go | 16 ++++++++++++++++ kubernetes/structure_job.go | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/kubernetes/schema_job_spec.go b/kubernetes/schema_job_spec.go index 4fcb6b9745..03036c5741 100644 --- a/kubernetes/schema_job_spec.go +++ b/kubernetes/schema_job_spec.go @@ -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": { + 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, @@ -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, diff --git a/kubernetes/structure_job.go b/kubernetes/structure_job.go index 029456f251..0c3475c9bb 100644 --- a/kubernetes/structure_job.go +++ b/kubernetes/structure_job.go @@ -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)) } @@ -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)) } From d28da8ef90f1d8ab9a3bf643a760de1c070aca5e Mon Sep 17 00:00:00 2001 From: BBBmau Date: Fri, 20 Sep 2024 16:24:13 -0700 Subject: [PATCH 02/11] fix tests by adding in extra checks and DiffSuppressFuncs for both new attributes --- kubernetes/schema_job_spec.go | 18 +++++++++++++++++- kubernetes/structure_job.go | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/kubernetes/schema_job_spec.go b/kubernetes/schema_job_spec.go index 03036c5741..2bcd44799e 100644 --- a/kubernetes/schema_job_spec.go +++ b/kubernetes/schema_job_spec.go @@ -60,10 +60,18 @@ func jobSpecFields(specUpdatable bool) map[string]*schema.Schema { "backoff_limit_per_index": { Type: schema.TypeInt, Optional: true, - Default: 6, ForceNew: false, + Default: 6, 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.", + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + + if v, ok := d.GetOk("completion_mode"); ok { + return v.(string) != "Indexed" + } + + return true + }, }, // This field is immutable in Jobs. "completions": { @@ -98,6 +106,14 @@ func jobSpecFields(specUpdatable bool) map[string]*schema.Schema { 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", + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + + if v, ok := d.GetOk("completion_mode"); ok { + return v.(string) != "Indexed" + } + + return true + }, }, "parallelism": { Type: schema.TypeInt, diff --git a/kubernetes/structure_job.go b/kubernetes/structure_job.go index 0c3475c9bb..5f4ef036af 100644 --- a/kubernetes/structure_job.go +++ b/kubernetes/structure_job.go @@ -79,7 +79,7 @@ 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 { + if v, ok := in["backoff_limit_per_index"].(int); in["completion_mode"].(string) == "Indexed" && ok && v >= 0 { obj.BackoffLimitPerIndex = ptr.To(int32(v)) } @@ -96,7 +96,7 @@ func expandJobV1Spec(j []interface{}) (batchv1.JobSpec, error) { obj.ManualSelector = ptr.To(v.(bool)) } - if v, ok := in["max_failed_indexes"].(int); ok && v >= 0 { + if v, ok := in["max_failed_indexes"].(int); in["completion_mode"].(string) == "Indexed" && ok && v >= 0 { obj.MaxFailedIndexes = ptr.To(int32(v)) } From 261e9c742de7710633d7e1131b6d5976331117b1 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Fri, 20 Sep 2024 16:29:08 -0700 Subject: [PATCH 03/11] add changelog --- .changelog/2421.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2421.txt diff --git a/.changelog/2421.txt b/.changelog/2421.txt new file mode 100644 index 0000000000..9c569b3c03 --- /dev/null +++ b/.changelog/2421.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +Add `backoff_per_limit_index` and `max_failed_indexes` fields in `structure_job.go` +``` \ No newline at end of file From 589cff4d79b9acc0ae59545d98112009dd13e167 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Fri, 20 Sep 2024 16:39:40 -0700 Subject: [PATCH 04/11] add docs --- docs/resources/cron_job.md | 2 ++ docs/resources/cron_job_v1.md | 2 ++ docs/resources/job_v1.md | 2 ++ kubernetes/schema_job_spec.go | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/resources/cron_job.md b/docs/resources/cron_job.md index 16679f7dd6..e132a0d5e8 100644 --- a/docs/resources/cron_job.md +++ b/docs/resources/cron_job.md @@ -102,6 +102,8 @@ Optional: - `active_deadline_seconds` (Number) Optional duration in seconds the pod may be active on the node relative to StartTime before the system will actively try to mark it failed and kill associated containers. Value must be a positive integer. - `backoff_limit` (Number) Specifies the number of retries before marking this job failed. Defaults to 6 +- `backoff_limit_per_index` - (Number) 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. +- `max_failed_indexes` - (Number) 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 - `completion_mode` (String) Specifies how Pod completions are tracked. It can be `NonIndexed` (default) or `Indexed`. More info: https://kubernetes.io/docs/concepts/workloads/controllers/job/#completion-mode - `completions` (Number) Specifies the desired number of successfully finished pods the job should be run with. Setting to nil means that the success of any pod signals the success of all pods, and allows parallelism to have any positive value. Setting to 1 means that parallelism is limited to 1 and the success of that pod signals the success of the job. More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/ - `manual_selector` (Boolean) 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 diff --git a/docs/resources/cron_job_v1.md b/docs/resources/cron_job_v1.md index 0f6f6662e6..f31d0fc102 100644 --- a/docs/resources/cron_job_v1.md +++ b/docs/resources/cron_job_v1.md @@ -97,6 +97,8 @@ Optional: - `active_deadline_seconds` (Number) Optional duration in seconds the pod may be active on the node relative to StartTime before the system will actively try to mark it failed and kill associated containers. Value must be a positive integer. - `backoff_limit` (Number) Specifies the number of retries before marking this job failed. Defaults to 6 +- `backoff_limit_per_index` - (Number) 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. +- `max_failed_indexes` - (Number) 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 - `completion_mode` (String) Specifies how Pod completions are tracked. It can be `NonIndexed` (default) or `Indexed`. More info: https://kubernetes.io/docs/concepts/workloads/controllers/job/#completion-mode - `completions` (Number) Specifies the desired number of successfully finished pods the job should be run with. Setting to nil means that the success of any pod signals the success of all pods, and allows parallelism to have any positive value. Setting to 1 means that parallelism is limited to 1 and the success of that pod signals the success of the job. More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/ - `manual_selector` (Boolean) 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 diff --git a/docs/resources/job_v1.md b/docs/resources/job_v1.md index 70f52d1336..72249f1e47 100644 --- a/docs/resources/job_v1.md +++ b/docs/resources/job_v1.md @@ -55,6 +55,8 @@ Optional: - `active_deadline_seconds` (Number) Optional duration in seconds the pod may be active on the node relative to StartTime before the system will actively try to mark it failed and kill associated containers. Value must be a positive integer. - `backoff_limit` (Number) Specifies the number of retries before marking this job failed. Defaults to 6 +- `backoff_limit_per_index` - (Number) 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. +- `max_failed_indexes` - (Number) 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 - `completion_mode` (String) Specifies how Pod completions are tracked. It can be `NonIndexed` (default) or `Indexed`. More info: https://kubernetes.io/docs/concepts/workloads/controllers/job/#completion-mode - `completions` (Number) Specifies the desired number of successfully finished pods the job should be run with. Setting to nil means that the success of any pod signals the success of all pods, and allows parallelism to have any positive value. Setting to 1 means that parallelism is limited to 1 and the success of that pod signals the success of the job. More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/ - `manual_selector` (Boolean) 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 diff --git a/kubernetes/schema_job_spec.go b/kubernetes/schema_job_spec.go index 2bcd44799e..16565d9b4b 100644 --- a/kubernetes/schema_job_spec.go +++ b/kubernetes/schema_job_spec.go @@ -60,7 +60,7 @@ func jobSpecFields(specUpdatable bool) map[string]*schema.Schema { "backoff_limit_per_index": { Type: schema.TypeInt, Optional: true, - ForceNew: false, + ForceNew: true, Default: 6, 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.", From abdea7fffd7f21c52799719e3eeb6b766c18b3eb Mon Sep 17 00:00:00 2001 From: BBBmau Date: Fri, 20 Sep 2024 16:48:20 -0700 Subject: [PATCH 05/11] add new fields into TestAccKubernetesCronJobV1_minimalWithPodFailurePolicy test --- kubernetes/resource_kubernetes_cron_job_v1_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kubernetes/resource_kubernetes_cron_job_v1_test.go b/kubernetes/resource_kubernetes_cron_job_v1_test.go index be766bcb47..cef3eef1fc 100644 --- a/kubernetes/resource_kubernetes_cron_job_v1_test.go +++ b/kubernetes/resource_kubernetes_cron_job_v1_test.go @@ -443,6 +443,8 @@ func testAccKubernetesCronJobV1ConfigMinimal(name, imageName string) string { job_template { metadata {} spec { + backoff_limit_per_index = 3 + max_failed_indexes = 4 template { metadata {} spec { @@ -471,6 +473,8 @@ func testAccKubernetesCronJobV1ConfigMinimalWithPodFailurePolicy(name, imageName job_template { metadata {} spec { + backoff_limit_per_index = 3 + max_failed_indexes = 4 pod_failure_policy { rule { action = "FailJob" From db40ca4f548c408788a68fc08a1af46e78df43f6 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Fri, 20 Sep 2024 16:51:13 -0700 Subject: [PATCH 06/11] insert field checks for new fields --- kubernetes/resource_kubernetes_cron_job_v1_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kubernetes/resource_kubernetes_cron_job_v1_test.go b/kubernetes/resource_kubernetes_cron_job_v1_test.go index cef3eef1fc..4c072218a2 100644 --- a/kubernetes/resource_kubernetes_cron_job_v1_test.go +++ b/kubernetes/resource_kubernetes_cron_job_v1_test.go @@ -205,6 +205,8 @@ func TestAccKubernetesCronJobV1_minimalWithPodFailurePolicy(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "metadata.0.resource_version"), resource.TestCheckResourceAttrSet(resourceName, "metadata.0.uid"), resource.TestCheckResourceAttrSet(resourceName, "metadata.0.namespace"), + resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.backoff_limit_per_index", "3"), + resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.max_failed_indexes", "4"), resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.#", "2"), resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.action", "FailJob"), resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.on_exit_codes.0.container_name", "test"), From 8e13f8207e563c17bed46a9c3ee4c36aeee28c64 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Fri, 20 Sep 2024 16:55:38 -0700 Subject: [PATCH 07/11] make tests --- kubernetes/resource_kubernetes_cron_job_v1_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kubernetes/resource_kubernetes_cron_job_v1_test.go b/kubernetes/resource_kubernetes_cron_job_v1_test.go index 4c072218a2..723d47df93 100644 --- a/kubernetes/resource_kubernetes_cron_job_v1_test.go +++ b/kubernetes/resource_kubernetes_cron_job_v1_test.go @@ -446,7 +446,7 @@ func testAccKubernetesCronJobV1ConfigMinimal(name, imageName string) string { metadata {} spec { backoff_limit_per_index = 3 - max_failed_indexes = 4 + max_failed_indexes = 4 template { metadata {} spec { @@ -475,8 +475,8 @@ func testAccKubernetesCronJobV1ConfigMinimalWithPodFailurePolicy(name, imageName job_template { metadata {} spec { - backoff_limit_per_index = 3 - max_failed_indexes = 4 + backoff_limit_per_index = 3 + max_failed_indexes = 4 pod_failure_policy { rule { action = "FailJob" From 264ad2765374446e2856a60a807787e45cb9fe2e Mon Sep 17 00:00:00 2001 From: BBBmau Date: Fri, 20 Sep 2024 17:20:44 -0700 Subject: [PATCH 08/11] add flatteners --- .../resource_kubernetes_cron_job_v1_test.go | 4 ++-- kubernetes/schema_job_spec.go | 18 ------------------ kubernetes/structure_job.go | 12 ++++++++++-- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/kubernetes/resource_kubernetes_cron_job_v1_test.go b/kubernetes/resource_kubernetes_cron_job_v1_test.go index 723d47df93..135fce1b95 100644 --- a/kubernetes/resource_kubernetes_cron_job_v1_test.go +++ b/kubernetes/resource_kubernetes_cron_job_v1_test.go @@ -445,8 +445,6 @@ func testAccKubernetesCronJobV1ConfigMinimal(name, imageName string) string { job_template { metadata {} spec { - backoff_limit_per_index = 3 - max_failed_indexes = 4 template { metadata {} spec { @@ -477,6 +475,8 @@ func testAccKubernetesCronJobV1ConfigMinimalWithPodFailurePolicy(name, imageName spec { backoff_limit_per_index = 3 max_failed_indexes = 4 + completions = 4 + completion_mode = "Indexed" pod_failure_policy { rule { action = "FailJob" diff --git a/kubernetes/schema_job_spec.go b/kubernetes/schema_job_spec.go index 16565d9b4b..1e7157bab3 100644 --- a/kubernetes/schema_job_spec.go +++ b/kubernetes/schema_job_spec.go @@ -61,17 +61,8 @@ func jobSpecFields(specUpdatable bool) map[string]*schema.Schema { Type: schema.TypeInt, Optional: true, ForceNew: true, - Default: 6, 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.", - DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { - - if v, ok := d.GetOk("completion_mode"); ok { - return v.(string) != "Indexed" - } - - return true - }, }, // This field is immutable in Jobs. "completions": { @@ -103,17 +94,8 @@ func jobSpecFields(specUpdatable bool) map[string]*schema.Schema { 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", - DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { - - if v, ok := d.GetOk("completion_mode"); ok { - return v.(string) != "Indexed" - } - - return true - }, }, "parallelism": { Type: schema.TypeInt, diff --git a/kubernetes/structure_job.go b/kubernetes/structure_job.go index 5f4ef036af..5cdd657241 100644 --- a/kubernetes/structure_job.go +++ b/kubernetes/structure_job.go @@ -23,6 +23,14 @@ func flattenJobV1Spec(in batchv1.JobSpec, d *schema.ResourceData, meta interface att["backoff_limit"] = *in.BackoffLimit } + if in.BackoffLimitPerIndex != nil { + att["backoff_limit_per_index"] = *in.BackoffLimitPerIndex + } + + if in.MaxFailedIndexes != nil { + att["max_failed_indexes"] = *in.MaxFailedIndexes + } + if in.Completions != nil { att["completions"] = *in.Completions } @@ -79,7 +87,7 @@ func expandJobV1Spec(j []interface{}) (batchv1.JobSpec, error) { obj.BackoffLimit = ptr.To(int32(v)) } - if v, ok := in["backoff_limit_per_index"].(int); in["completion_mode"].(string) == "Indexed" && ok && v >= 0 { + if v, ok := in["backoff_limit_per_index"].(int); in["completion_mode"] == "Indexed" && ok && v >= 0 { obj.BackoffLimitPerIndex = ptr.To(int32(v)) } @@ -96,7 +104,7 @@ func expandJobV1Spec(j []interface{}) (batchv1.JobSpec, error) { obj.ManualSelector = ptr.To(v.(bool)) } - if v, ok := in["max_failed_indexes"].(int); in["completion_mode"].(string) == "Indexed" && ok && v >= 0 { + if v, ok := in["max_failed_indexes"].(int); in["completion_mode"] == "Indexed" && ok && v >= 0 { obj.MaxFailedIndexes = ptr.To(int32(v)) } From 248c69dcb0fe25386974d9333ae2bb56f8addf56 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Fri, 20 Sep 2024 17:26:57 -0700 Subject: [PATCH 09/11] lint fix --- kubernetes/resource_kubernetes_cron_job_v1_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kubernetes/resource_kubernetes_cron_job_v1_test.go b/kubernetes/resource_kubernetes_cron_job_v1_test.go index 135fce1b95..5c6eb5206b 100644 --- a/kubernetes/resource_kubernetes_cron_job_v1_test.go +++ b/kubernetes/resource_kubernetes_cron_job_v1_test.go @@ -475,8 +475,8 @@ func testAccKubernetesCronJobV1ConfigMinimalWithPodFailurePolicy(name, imageName spec { backoff_limit_per_index = 3 max_failed_indexes = 4 - completions = 4 - completion_mode = "Indexed" + completions = 4 + completion_mode = "Indexed" pod_failure_policy { rule { action = "FailJob" From 80a683ec99efe7f733b510ba2b11281d6fac4e91 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Fri, 20 Sep 2024 17:50:38 -0700 Subject: [PATCH 10/11] add new test - TestAccKubernetesCronJobV1_minimalWithBackoffLimitPerIndex --- .../resource_kubernetes_cron_job_v1_test.go | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/kubernetes/resource_kubernetes_cron_job_v1_test.go b/kubernetes/resource_kubernetes_cron_job_v1_test.go index 5c6eb5206b..6b563e00ea 100644 --- a/kubernetes/resource_kubernetes_cron_job_v1_test.go +++ b/kubernetes/resource_kubernetes_cron_job_v1_test.go @@ -199,6 +199,59 @@ func TestAccKubernetesCronJobV1_minimalWithPodFailurePolicy(t *testing.T) { }, { Config: testAccKubernetesCronJobV1ConfigMinimalWithPodFailurePolicy(name, imageName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesCronJobV1Exists(resourceName, &conf2), + resource.TestCheckResourceAttrSet(resourceName, "metadata.0.generation"), + resource.TestCheckResourceAttrSet(resourceName, "metadata.0.resource_version"), + resource.TestCheckResourceAttrSet(resourceName, "metadata.0.uid"), + resource.TestCheckResourceAttrSet(resourceName, "metadata.0.namespace"), + resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.#", "2"), + resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.action", "FailJob"), + resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.on_exit_codes.0.container_name", "test"), + resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.on_exit_codes.0.values.#", "3"), + resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.on_exit_codes.0.values.0", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.on_exit_codes.0.values.1", "2"), + resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.0.on_exit_codes.0.values.2", "42"), + resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.1.action", "Ignore"), + resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.1.on_pod_condition.0.type", "DisruptionTarget"), + resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.pod_failure_policy.0.rule.1.on_pod_condition.0.status", "False"), + testAccCheckKubernetesCronJobV1ForceNew(&conf1, &conf2, true), + ), + }, + }, + }) +} + +func TestAccKubernetesCronJobV1_minimalWithBackoffLimitPerIndex(t *testing.T) { + var conf1, conf2 batchv1.CronJob + + name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) + resourceName := "kubernetes_cron_job_v1.test" + imageName := busyboxImage + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + skipIfClusterVersionLessThan(t, "1.29.0") + }, + IDRefreshName: resourceName, + IDRefreshIgnore: []string{"metadata.0.resource_version"}, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testAccCheckKubernetesCronJobV1Destroy, + Steps: []resource.TestStep{ + { + Config: testAccKubernetesCronJobV1ConfigMinimal(name, imageName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesCronJobV1Exists(resourceName, &conf1), + resource.TestCheckResourceAttrSet(resourceName, "metadata.0.generation"), + resource.TestCheckResourceAttrSet(resourceName, "metadata.0.resource_version"), + resource.TestCheckResourceAttrSet(resourceName, "metadata.0.uid"), + resource.TestCheckResourceAttrSet(resourceName, "metadata.0.namespace"), + resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.metadata.0.namespace", ""), + ), + }, + { + Config: testAccKubernetesCronJobV1ConfigMinimalWithBackoffLimitPerIndex(name, imageName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckKubernetesCronJobV1Exists(resourceName, &conf2), resource.TestCheckResourceAttrSet(resourceName, "metadata.0.generation"), @@ -463,6 +516,56 @@ func testAccKubernetesCronJobV1ConfigMinimal(name, imageName string) string { `, name, imageName) } +func testAccKubernetesCronJobV1ConfigMinimalWithBackoffLimitPerIndex(name, imageName string) string { + return fmt.Sprintf(`resource "kubernetes_cron_job_v1" "test" { + metadata { + name = "%s" + } + spec { + schedule = "*/1 * * * *" + job_template { + metadata {} + spec { + backoff_limit_per_index = 3 + max_failed_indexes = 4 + completions = 4 + completion_mode = "Indexed" + pod_failure_policy { + rule { + action = "FailJob" + on_exit_codes { + container_name = "test" + operator = "In" + values = [1, 2, 42] + } + } + rule { + action = "Ignore" + on_pod_condition { + status = "False" + type = "DisruptionTarget" + } + } + } + template { + metadata {} + spec { + + container { + name = "test" + image = "%s" + command = ["sleep", "5"] + } + termination_grace_period_seconds = 1 + } + } + } + } + } +} +`, name, imageName) +} + func testAccKubernetesCronJobV1ConfigMinimalWithPodFailurePolicy(name, imageName string) string { return fmt.Sprintf(`resource "kubernetes_cron_job_v1" "test" { metadata { From 859b68be8d6702f37de52d80a00f2f24c8697bfa Mon Sep 17 00:00:00 2001 From: BBBmau Date: Fri, 20 Sep 2024 18:05:57 -0700 Subject: [PATCH 11/11] remove fields from other test --- kubernetes/resource_kubernetes_cron_job_v1_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/kubernetes/resource_kubernetes_cron_job_v1_test.go b/kubernetes/resource_kubernetes_cron_job_v1_test.go index 6b563e00ea..4dbf939e88 100644 --- a/kubernetes/resource_kubernetes_cron_job_v1_test.go +++ b/kubernetes/resource_kubernetes_cron_job_v1_test.go @@ -576,10 +576,6 @@ func testAccKubernetesCronJobV1ConfigMinimalWithPodFailurePolicy(name, imageName job_template { metadata {} spec { - backoff_limit_per_index = 3 - max_failed_indexes = 4 - completions = 4 - completion_mode = "Indexed" pod_failure_policy { rule { action = "FailJob"