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

[SHIPA-2627] omit default backoffLimit value #242

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion ci/limits.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"github.com/theketchio/ketch/cmd/ketch": 61.4,
"github.com/theketchio/ketch/cmd/ketch": 61.3,
"github.com/theketchio/ketch/cmd/ketch/configuration": 0,
"github.com/theketchio/ketch/cmd/ketch/output": 68.3,
"github.com/theketchio/ketch/cmd/manager": 0,
Expand Down
5 changes: 0 additions & 5 deletions cmd/ketch/job_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ Deploy a job.
const (
defaultJobVersion = "v1"
defaultJobParallelism = 1
defaultJobCompletions = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this supposed to be deleted?

defaultJobBackoffLimit = 6
defaultJobRestartPolicy = "Never"
)

Expand Down Expand Up @@ -87,9 +85,6 @@ func setJobSpecDefaults(jobSpec *ketchv1.JobSpec) {
if jobSpec.Completions == 0 {
jobSpec.Completions = jobSpec.Parallelism
}
if jobSpec.BackoffLimit == 0 {
jobSpec.BackoffLimit = defaultJobBackoffLimit
}
if jobSpec.Policy.RestartPolicy == "" {
jobSpec.Policy.RestartPolicy = defaultJobRestartPolicy
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/ketch/job_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

ketchv1 "github.com/theketchio/ketch/internal/api/v1beta1"
"github.com/theketchio/ketch/internal/mocks"
"github.com/theketchio/ketch/internal/utils/conversions"
)

func TestJobDeploy(t *testing.T) {
Expand Down Expand Up @@ -59,7 +60,7 @@ policy:
Parallelism: 1,
Completions: 1,
Suspend: false,
BackoffLimit: 6,
BackoffLimit: conversions.IntPtr(6),
Containers: []ketchv1.Container{
{
Name: "lister",
Expand Down
3 changes: 2 additions & 1 deletion cmd/ketch/job_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

ketchv1 "github.com/theketchio/ketch/internal/api/v1beta1"
"github.com/theketchio/ketch/internal/mocks"
"github.com/theketchio/ketch/internal/utils/conversions"
)

func TestJobExport(t *testing.T) {
Expand All @@ -24,7 +25,7 @@ func TestJobExport(t *testing.T) {
Parallelism: 1,
Completions: 1,
Suspend: false,
BackoffLimit: 6,
BackoffLimit: conversions.IntPtr(6),
Containers: []ketchv1.Container{
{
Name: "lister",
Expand Down
23 changes: 21 additions & 2 deletions cmd/ketch/job_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

ketchv1 "github.com/theketchio/ketch/internal/api/v1beta1"
"github.com/theketchio/ketch/internal/mocks"
"github.com/theketchio/ketch/internal/utils/conversions"
)

func TestJobList(t *testing.T) {
Expand All @@ -24,7 +25,7 @@ func TestJobList(t *testing.T) {
Parallelism: 1,
Completions: 1,
Suspend: false,
BackoffLimit: 6,
BackoffLimit: conversions.IntPtr(6),
Containers: []ketchv1.Container{
{
Name: "lister",
Expand Down Expand Up @@ -80,7 +81,7 @@ func TestJobListNames(t *testing.T) {
Parallelism: 1,
Completions: 1,
Suspend: false,
BackoffLimit: 6,
BackoffLimit: conversions.IntPtr(6),
Containers: []ketchv1.Container{
{
Name: "lister",
Expand Down Expand Up @@ -109,6 +110,24 @@ func TestJobListNames(t *testing.T) {
},
wantOut: []string{"hello"},
},
{
name: "filter",
Copy link
Contributor

Choose a reason for hiding this comment

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

This test and the one below it share the same name, so it might be better to change the names to something like filter - no match and filter-success.

cfg: &mocks.Configuration{
CtrlClientObjects: []runtime.Object{mockJob},
DynamicClientObjects: []runtime.Object{},
},
filter: "goodbye",
wantOut: []string{},
},
{
name: "filter",
cfg: &mocks.Configuration{
CtrlClientObjects: []runtime.Object{mockJob},
DynamicClientObjects: []runtime.Object{},
},
filter: "hello",
wantOut: []string{"hello"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/ketch/job_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

ketchv1 "github.com/theketchio/ketch/internal/api/v1beta1"
"github.com/theketchio/ketch/internal/mocks"
"github.com/theketchio/ketch/internal/utils/conversions"
)

func TestJobRemove(t *testing.T) {
Expand All @@ -24,7 +25,7 @@ func TestJobRemove(t *testing.T) {
Parallelism: 1,
Completions: 1,
Suspend: false,
BackoffLimit: 6,
BackoffLimit: conversions.IntPtr(6),
Containers: []ketchv1.Container{
{
Name: "lister",
Expand Down
1 change: 1 addition & 0 deletions config/crd/bases/theketch.io_jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ spec:
description: JobSpec defines the desired state of Job
properties:
backoffLimit:
minimum: 0
type: integer
completions:
type: integer
Expand Down
19 changes: 10 additions & 9 deletions internal/api/v1beta1/job_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ import (

// JobSpec defines the desired state of Job
type JobSpec struct {
Version string `json:"version,omitempty"`
Type string `json:"type"`
Name string `json:"name"`
Framework string `json:"framework"`
Description string `json:"description,omitempty"`
Parallelism int `json:"parallelism,omitempty"`
Completions int `json:"completions,omitempty"`
Suspend bool `json:"suspend,omitempty"`
BackoffLimit int `json:"backoffLimit,omitempty"`
Version string `json:"version,omitempty"`
Type string `json:"type"`
Name string `json:"name"`
Framework string `json:"framework"`
Description string `json:"description,omitempty"`
Parallelism int `json:"parallelism,omitempty"`
Completions int `json:"completions,omitempty"`
Suspend bool `json:"suspend,omitempty"`
//+kubebuilder:validation:Minimum=0
BackoffLimit *int `json:"backoffLimit,omitempty"`
Containers []Container `json:"containers,omitempty"`
Policy Policy `json:"policy,omitempty"`
}
Expand Down
72 changes: 72 additions & 0 deletions internal/api/v1beta1/job_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package v1beta1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added these tests just to keep coverage up. Coverage dipped in a couple packages.


import (
"testing"

"github.com/stretchr/testify/require"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestCondition(t *testing.T) {
tests := []struct {
description string
jobStatus *JobStatus
conditionType ConditionType
expected *Condition
}{
{
description: "found",
jobStatus: &JobStatus{Conditions: []Condition{{Type: "type1", Status: "active"}, {Type: "type2", Status: "failed"}}},
conditionType: ConditionType("type1"),
expected: &Condition{Type: "type1", Status: "active"},
},
{
description: "not found",
jobStatus: &JobStatus{Conditions: []Condition{{Type: "type1", Status: "active"}, {Type: "type2", Status: "failed"}}},
conditionType: ConditionType("complete"),
expected: nil,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
res := tt.jobStatus.Condition(tt.conditionType)
require.Equal(t, tt.expected, res)
})
}
}

func TestSetCondition(t *testing.T) {
now := metav1.Time{}
j := &Job{
Status: JobStatus{
Conditions: []Condition{
{
Type: ConditionType("type1"),
Status: "active",
Message: "message-1",
},
},
},
}
expected := &Job{
Status: JobStatus{
Conditions: []Condition{
{
Type: ConditionType("type1"),
Status: "active",
Message: "message-1",
},
{
Type: ConditionType("type2"),
Status: "failed",
Message: "message-2",
LastTransitionTime: &now,
},
},
},
}

j.SetCondition("type2", v1.ConditionStatus("failed"), "message-2", now)
require.Equal(t, expected, j)
}
4 changes: 2 additions & 2 deletions internal/chart/chartutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestBufferedFiles(t *testing.T) {
Parallelism: 2,
Completions: 2,
Suspend: false,
BackoffLimit: 4,
BackoffLimit: conversions.IntPtr(4),
Containers: []ketchv1.Container{
{
Name: "test",
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestGetValuesMap(t *testing.T) {
Parallelism: 2,
Completions: 2,
Suspend: false,
BackoffLimit: 4,
BackoffLimit: conversions.IntPtr(4),
Containers: []ketchv1.Container{
{
Name: "test",
Expand Down
3 changes: 2 additions & 1 deletion internal/chart/job_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

ketchv1 "github.com/theketchio/ketch/internal/api/v1beta1"
"github.com/theketchio/ketch/internal/templates"
"github.com/theketchio/ketch/internal/utils/conversions"
)

var (
Expand All @@ -25,7 +26,7 @@ var (
Parallelism: 2,
Completions: 2,
Suspend: false,
BackoffLimit: 4,
BackoffLimit: conversions.IntPtr(4),
Containers: []ketchv1.Container{
{
Name: "test",
Expand Down
2 changes: 1 addition & 1 deletion internal/templates/job/yamls/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
{{- if $.Values.job.completions }}
completions: {{ $.Values.job.completions }}
{{- end }}
{{- if $.Values.job.backoffLimit }}
{{- if not (kindIs "invalid" $.Values.job.backoffLimit) }}
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

backoffLimit: {{ $.Values.job.backoffLimit }}
{{- end }}
{{- if $.Values.job.suspend }}
Expand Down