Repository: furiko-io/furiko
Pull request #78 (2022-05-06 16:14:34)

feat(api): Update maxAttempts to int64
Updates maxAttempts to be int64 instead, there is no need to use int32.


Patch:
diff --git a/apis/execution/v1alpha1/job_types.go b/apis/execution/v1alpha1/job_types.go
index f89ee09..ce716e6 100644
--- a/apis/execution/v1alpha1/job_types.go
+++ b/apis/execution/v1alpha1/job_types.go
@@ -151,7 +151,7 @@ type JobTemplateSpec struct {
 	// integer. Defaults to 1.
 	//
 	// +optional
-	MaxAttempts *int32 `json:"maxAttempts,omitempty"`
+	MaxAttempts *int64 `json:"maxAttempts,omitempty"`
 
 	// Optional duration in seconds to wait between retries. If left empty or zero,
 	// it means no delay (i.e. retry immediately). Value must be a non-negative
diff --git a/apis/execution/v1alpha1/zz_generated.deepcopy.go b/apis/execution/v1alpha1/zz_generated.deepcopy.go
index a21b030..3058225 100644
--- a/apis/execution/v1alpha1/zz_generated.deepcopy.go
+++ b/apis/execution/v1alpha1/zz_generated.deepcopy.go
@@ -484,7 +484,7 @@ func (in *JobTemplateSpec) DeepCopyInto(out *JobTemplateSpec) {
 	in.Task.DeepCopyInto(&out.Task)
 	if in.MaxAttempts != nil {
 		in, out := &in.MaxAttempts, &out.MaxAttempts
-		*out = new(int32)
+		*out = new(int64)
 		**out = **in
 	}
 	if in.RetryDelaySeconds != nil {
diff --git a/config/crd/bases/execution.furiko.io_jobconfigs.yaml b/config/crd/bases/execution.furiko.io_jobconfigs.yaml
index a934f48..29b9fd8 100644
--- a/config/crd/bases/execution.furiko.io_jobconfigs.yaml
+++ b/config/crd/bases/execution.furiko.io_jobconfigs.yaml
@@ -211,7 +211,7 @@ spec:
                       properties:
                         maxAttempts:
                           description: Specifies maximum number of attempts for the Job. Each attempt will create a single task at a time, and if the task fails, the controller will wait retryDelaySeconds before creating the next task attempt. Once maxAttempts is reached, the Job terminates in RetryLimitExceeded. Value must be a positive integer. Defaults to 1.
-                          format: int32
+                          format: int64
                           type: integer
                         retryDelaySeconds:
                           description: Optional duration in seconds to wait between retries. If left empty or zero, it means no delay (i.e. retry immediately). Value must be a non-negative integer.
diff --git a/config/crd/bases/execution.furiko.io_jobs.yaml b/config/crd/bases/execution.furiko.io_jobs.yaml
index cae1811..e0f3c98 100644
--- a/config/crd/bases/execution.furiko.io_jobs.yaml
+++ b/config/crd/bases/execution.furiko.io_jobs.yaml
@@ -83,7 +83,7 @@ spec:
                   properties:
                     maxAttempts:
                       description: Specifies maximum number of attempts for the Job. Each attempt will create a single task at a time, and if the task fails, the controller will wait retryDelaySeconds before creating the next task attempt. Once maxAttempts is reached, the Job terminates in RetryLimitExceeded. Value must be a positive integer. Defaults to 1.
-                      format: int32
+                      format: int64
                       type: integer
                     retryDelaySeconds:
                       description: Optional duration in seconds to wait between retries. If left empty or zero, it means no delay (i.e. retry immediately). Value must be a non-negative integer.
diff --git a/pkg/execution/mutation/mutation.go b/pkg/execution/mutation/mutation.go
index 343177f..04f84a2 100644
--- a/pkg/execution/mutation/mutation.go
+++ b/pkg/execution/mutation/mutation.go
@@ -297,7 +297,7 @@ func (m *Mutator) MutateJobTemplateSpec(spec *v1alpha1.JobTemplateSpec, fldPath
 
 	// Add MaxAttempts if not specified.
 	if spec.MaxAttempts == nil {
-		spec.MaxAttempts = pointer.Int32(1)
+		spec.MaxAttempts = pointer.Int64(1)
 	}
 
 	// Mutate task's PodTemplateSpec.
diff --git a/pkg/execution/util/job/task_utils.go b/pkg/execution/util/job/task_utils.go
index 2af2168..2700f67 100644
--- a/pkg/execution/util/job/task_utils.go
+++ b/pkg/execution/util/job/task_utils.go
@@ -52,7 +52,7 @@ func GetMaxAllowedTasks(rj *execution.Job) int64 {
 	var maxAttempts int64 = 1
 	if template := rj.Spec.Template; template != nil {
 		if rj.Spec.Template.MaxAttempts != nil {
-			maxAttempts = int64(*rj.Spec.Template.MaxAttempts)
+			maxAttempts = *rj.Spec.Template.MaxAttempts
 		}
 	}
 	return maxAttempts
diff --git a/pkg/execution/validation/validation.go b/pkg/execution/validation/validation.go
index a26c04a..4ede798 100644
--- a/pkg/execution/validation/validation.go
+++ b/pkg/execution/validation/validation.go
@@ -393,15 +393,15 @@ func (v *Validator) ValidateJobTemplateSpec(template *v1alpha1.JobTemplateSpec,
 	return allErrs
 }
 
-func (v *Validator) ValidateMaxRetryAttempts(attempts int32, fldPath *field.Path) field.ErrorList {
+func (v *Validator) ValidateMaxRetryAttempts(attempts int64, fldPath *field.Path) field.ErrorList {
 	allErrs := field.ErrorList{}
 
 	// Must be greater than 0.
-	allErrs = append(allErrs, validation.ValidateGT(int64(attempts), 0, fldPath)...)
+	allErrs = append(allErrs, validation.ValidateGT(attempts, 0, fldPath)...)
 
 	// Set an arbitrary limit of 50 attempts.
 	// TODO(irvinlim): Support configuring this value
-	allErrs = append(allErrs, validation.ValidateLTE(int64(attempts), 50, fldPath)...)
+	allErrs = append(allErrs, validation.ValidateLTE(attempts, 50, fldPath)...)
 
 	return allErrs
 }


Test patch:
diff --git a/pkg/execution/mutation/mutation_test.go b/pkg/execution/mutation/mutation_test.go
index d3d66ea..5021878 100644
--- a/pkg/execution/mutation/mutation_test.go
+++ b/pkg/execution/mutation/mutation_test.go
@@ -652,7 +652,7 @@ func TestMutator_MutateJob(t *testing.T) {
 								Pod: &podTemplateSpecBasic,
 							},
 						},
-						MaxAttempts: pointer.Int32(1),
+						MaxAttempts: pointer.Int64(1),
 					},
 					TTLSecondsAfterFinished: config.DefaultJobExecutionConfig.DefaultTTLSecondsAfterFinished,
 				},
@@ -670,7 +670,7 @@ func TestMutator_MutateJob(t *testing.T) {
 								Pod: &podTemplateSpecBasic,
 							},
 						},
-						MaxAttempts: pointer.Int32(1),
+						MaxAttempts: pointer.Int64(1),
 					},
 					TTLSecondsAfterFinished: config.DefaultJobExecutionConfig.DefaultTTLSecondsAfterFinished,
 				},
diff --git a/pkg/execution/mutation/patcher_jobs_test.go b/pkg/execution/mutation/patcher_jobs_test.go
index 6959443..a7e359c 100644
--- a/pkg/execution/mutation/patcher_jobs_test.go
+++ b/pkg/execution/mutation/patcher_jobs_test.go
@@ -70,7 +70,7 @@ func TestNewJobPatcher(t *testing.T) {
 								},
 							},
 						},
-						MaxAttempts: pointer.Int32(1),
+						MaxAttempts: pointer.Int64(1),
 					},
 					TTLSecondsAfterFinished: config.DefaultJobExecutionConfig.DefaultTTLSecondsAfterFinished,
 				},
@@ -91,7 +91,7 @@ func TestNewJobPatcher(t *testing.T) {
 					Type: v1alpha1.JobTypeAdhoc,
 					Template: &v1alpha1.JobTemplateSpec{
 						Task:        jobTemplateSpecBasic.Spec.Task,
-						MaxAttempts: pointer.Int32(1),
+						MaxAttempts: pointer.Int64(1),
 					},
 					StartPolicy:             &startPolicyBasic,
 					TTLSecondsAfterFinished: config.DefaultJobExecutionConfig.DefaultTTLSecondsAfterFinished,
diff --git a/pkg/execution/util/job/condition_test.go b/pkg/execution/util/job/condition_test.go
index 1a85a76..858c4e0 100644
--- a/pkg/execution/util/job/condition_test.go
+++ b/pkg/execution/util/job/condition_test.go
@@ -23,6 +23,7 @@ import (
 	"github.com/google/go-cmp/cmp"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/util/clock"
+	"k8s.io/utils/pointer"
 
 	execution "github.com/furiko-io/furiko/apis/execution/v1alpha1"
 	"github.com/furiko-io/furiko/pkg/execution/tasks"
@@ -309,7 +310,7 @@ func TestGetCondition(t *testing.T) {
 				rj: &execution.Job{
 					Spec: execution.JobSpec{
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: createTaskRefsStatus("task1"),
@@ -374,7 +375,7 @@ func TestGetCondition(t *testing.T) {
 				rj: &execution.Job{
 					Spec: execution.JobSpec{
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: createTaskRefsStatus("task1"),
@@ -442,7 +443,7 @@ func TestGetCondition(t *testing.T) {
 				rj: &execution.Job{
 					Spec: execution.JobSpec{
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: createTaskRefsStatus("task1", "task2"),
@@ -482,7 +483,7 @@ func TestGetCondition(t *testing.T) {
 				rj: &execution.Job{
 					Spec: execution.JobSpec{
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: createTaskRefsStatus("task1", "task2"),
@@ -541,7 +542,7 @@ func TestGetCondition(t *testing.T) {
 					Spec: execution.JobSpec{
 						KillTimestamp: &killTime,
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: execution.JobStatus{
@@ -585,7 +586,7 @@ func TestGetCondition(t *testing.T) {
 					Spec: execution.JobSpec{
 						KillTimestamp: &killTime,
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: execution.JobStatus{
@@ -662,7 +663,7 @@ func TestGetCondition(t *testing.T) {
 				rj: &execution.Job{
 					Spec: execution.JobSpec{
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: createTaskRefsStatus("task1"),
@@ -683,7 +684,7 @@ func TestGetCondition(t *testing.T) {
 				rj: &execution.Job{
 					Spec: execution.JobSpec{
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: execution.JobStatus{
@@ -720,7 +721,7 @@ func TestGetCondition(t *testing.T) {
 					Spec: execution.JobSpec{
 						KillTimestamp: &killTime,
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: createTaskRefsStatus("task1"),
diff --git a/pkg/execution/util/job/job_utils_test.go b/pkg/execution/util/job/job_utils_test.go
index 321015c..e66f08d 100644
--- a/pkg/execution/util/job/job_utils_test.go
+++ b/pkg/execution/util/job/job_utils_test.go
@@ -19,6 +19,8 @@ package job_test
 import (
 	"testing"
 
+	"k8s.io/utils/pointer"
+
 	execution "github.com/furiko-io/furiko/apis/execution/v1alpha1"
 	jobtasks "github.com/furiko-io/furiko/pkg/execution/tasks"
 	jobutil "github.com/furiko-io/furiko/pkg/execution/util/job"
@@ -48,7 +50,7 @@ func TestAllowedToCreateNewTask(t *testing.T) {
 				rj: &execution.Job{
 					Spec: execution.JobSpec{
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: createTaskRefsStatus("task1"),
@@ -70,7 +72,7 @@ func TestAllowedToCreateNewTask(t *testing.T) {
 				rj: &execution.Job{
 					Spec: execution.JobSpec{
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: createTaskRefsStatus("task1"),
@@ -96,7 +98,7 @@ func TestAllowedToCreateNewTask(t *testing.T) {
 				rj: &execution.Job{
 					Spec: execution.JobSpec{
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: createTaskRefsStatus("task1"),
@@ -124,7 +126,7 @@ func TestAllowedToCreateNewTask(t *testing.T) {
 				rj: &execution.Job{
 					Spec: execution.JobSpec{
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: createTaskRefsStatus("task1"),
@@ -176,7 +178,7 @@ func TestAllowedToCreateNewTask(t *testing.T) {
 					Spec: execution.JobSpec{
 						KillTimestamp: &killTime,
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &two,
+							MaxAttempts: pointer.Int64(2),
 						},
 					},
 					Status: createTaskRefsStatus("task1"),
@@ -204,7 +206,7 @@ func TestAllowedToCreateNewTask(t *testing.T) {
 				rj: &execution.Job{
 					Spec: execution.JobSpec{
 						Template: &execution.JobTemplateSpec{
-							MaxAttempts: &three,
+							MaxAttempts: pointer.Int64(3),
 						},
 					},
 					Status: createTaskRefsStatus("task1", "task2"),
diff --git a/pkg/execution/util/job/task_test.go b/pkg/execution/util/job/task_test.go
index 53929e2..0c13f65 100644
--- a/pkg/execution/util/job/task_test.go
+++ b/pkg/execution/util/job/task_test.go
@@ -43,8 +43,6 @@ var (
 	finishTime       = metav1.NewTime(stdFinishTime)
 	finishTime2      = metav1.NewTime(stdFinishTime.Add(time.Minute))
 	killTime         = metav1.NewTime(stdKillTime)
-	two              = int32(2)
-	three            = int32(3)
 )
 
 type stubTask struct {
diff --git a/pkg/execution/util/job/task_utils_test.go b/pkg/execution/util/job/task_utils_test.go
index 0177d32..1451a53 100644
--- a/pkg/execution/util/job/task_utils_test.go
+++ b/pkg/execution/util/job/task_utils_test.go
@@ -38,7 +38,7 @@ func TestGetNextAllowedRetry(t *testing.T) {
 			rj: &execution.Job{
 				Spec: execution.JobSpec{
 					Template: &execution.JobTemplateSpec{
-						MaxAttempts: &three,
+						MaxAttempts: pointer.Int64(3),
 					},
 				},
 			},
@@ -49,7 +49,7 @@ func TestGetNextAllowedRetry(t *testing.T) {
 			rj: &execution.Job{
 				Spec: execution.JobSpec{
 					Template: &execution.JobTemplateSpec{
-						MaxAttempts:       &three,
+						MaxAttempts:       pointer.Int64(3),
 						RetryDelaySeconds: pointer.Int64(30),
 					},
 				},
@@ -82,7 +82,7 @@ func TestGetNextAllowedRetry(t *testing.T) {
 			rj: &execution.Job{
 				Spec: execution.JobSpec{
 					Template: &execution.JobTemplateSpec{
-						MaxAttempts: &three,
+						MaxAttempts: pointer.Int64(3),
 					},
 				},
 				Status: execution.JobStatus{
@@ -107,7 +107,7 @@ func TestGetNextAllowedRetry(t *testing.T) {
 			rj: &execution.Job{
 				Spec: execution.JobSpec{
 					Template: &execution.JobTemplateSpec{
-						MaxAttempts:       &three,
+						MaxAttempts:       pointer.Int64(3),
 						RetryDelaySeconds: pointer.Int64(30),
 					},
 				},
@@ -133,7 +133,7 @@ func TestGetNextAllowedRetry(t *testing.T) {
 			rj: &execution.Job{
 				Spec: execution.JobSpec{
 					Template: &execution.JobTemplateSpec{
-						MaxAttempts:       &three,
+						MaxAttempts:       pointer.Int64(3),
 						RetryDelaySeconds: pointer.Int64(30),
 					},
 				},
@@ -158,7 +158,7 @@ func TestGetNextAllowedRetry(t *testing.T) {
 			rj: &execution.Job{
 				Spec: execution.JobSpec{
 					Template: &execution.JobTemplateSpec{
-						MaxAttempts:       &three,
+						MaxAttempts:       pointer.Int64(3),
 						RetryDelaySeconds: pointer.Int64(30),
 					},
 					KillTimestamp: &killTime,
@@ -185,7 +185,7 @@ func TestGetNextAllowedRetry(t *testing.T) {
 			rj: &execution.Job{
 				Spec: execution.JobSpec{
 					Template: &execution.JobTemplateSpec{
-						MaxAttempts:       &two,
+						MaxAttempts:       pointer.Int64(2),
 						RetryDelaySeconds: pointer.Int64(30),
 					},
 				},
@@ -220,7 +220,7 @@ func TestGetNextAllowedRetry(t *testing.T) {
 			rj: &execution.Job{
 				Spec: execution.JobSpec{
 					Template: &execution.JobTemplateSpec{
-						MaxAttempts:       &two,
+						MaxAttempts:       pointer.Int64(2),
 						RetryDelaySeconds: pointer.Int64(30),
 					},
 				},
diff --git a/pkg/execution/validation/validation_test.go b/pkg/execution/validation/validation_test.go
index 6b76018..7b1c5fa 100644
--- a/pkg/execution/validation/validation_test.go
+++ b/pkg/execution/validation/validation_test.go
@@ -97,7 +97,7 @@ var (
 				},
 				PendingTimeoutSeconds: pointer.Int64(1800),
 			},
-			MaxAttempts:       pointer.Int32(5),
+			MaxAttempts:       pointer.Int64(5),
 			RetryDelaySeconds: pointer.Int64(60),
 		},
 	}
@@ -120,7 +120,7 @@ var (
 		ObjectMeta: jobTemplateSpecBasic.ObjectMeta,
 		Spec: v1alpha1.JobTemplateSpec{
 			Task:              jobTemplateSpecBasic.Spec.Task,
-			MaxAttempts:       pointer.Int32(10),
+			MaxAttempts:       pointer.Int64(10),
 			RetryDelaySeconds: jobTemplateSpecBasic.Spec.RetryDelaySeconds,
 		},
 	}
@@ -129,7 +129,7 @@ var (
 		ObjectMeta: jobTemplateSpecBasic.ObjectMeta,
 		Spec: v1alpha1.JobTemplateSpec{
 			Task:              jobTemplateSpecBasic.Spec.Task,
-			MaxAttempts:       pointer.Int32(100),
+			MaxAttempts:       pointer.Int64(100),
 			RetryDelaySeconds: jobTemplateSpecBasic.Spec.RetryDelaySeconds,
 		},
 	}