-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cronjob: add a check for having startingDeadlineSeconds set
- Loading branch information
Showing
5 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cronjob | ||
|
||
import ( | ||
"github.com/zegl/kube-score/scorecard" | ||
"k8s.io/api/batch/v1beta1" | ||
) | ||
|
||
func ScoreCronJobHasDeadline(job v1beta1.CronJob) (score scorecard.TestScore) { | ||
score.Name = "CronJob has deadline" | ||
score.ID = "cronjob-has-deadline" | ||
|
||
if job.Spec.StartingDeadlineSeconds == nil { | ||
score.Grade = scorecard.GradeCritical | ||
score.AddComment("", "The CronJob should have startingDeadlineSeconds configured", | ||
"This makes sure that jobs are automatically cancelled if they can not be scheduler") | ||
return | ||
} | ||
|
||
score.Grade = scorecard.GradeAllOK | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package score | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestCronJobHasDeadline(t *testing.T) { | ||
testExpectedScore(t, "cronjob-deadline-set.yaml", "CronJob has deadline", 10) | ||
} | ||
|
||
func TestCronJobNotHasDeadline(t *testing.T) { | ||
testExpectedScore(t, "cronjob-deadline-not-set.yaml", "CronJob has deadline", 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
apiVersion: batch/v1beta1 | ||
kind: CronJob | ||
metadata: | ||
name: hello | ||
spec: | ||
schedule: "*/1 * * * *" | ||
jobTemplate: | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: hello | ||
image: busybox | ||
args: | ||
- /bin/sh | ||
- -c | ||
- date; echo Hello from the Kubernetes cluster | ||
restartPolicy: OnFailure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: batch/v1beta1 | ||
kind: CronJob | ||
metadata: | ||
name: hello | ||
spec: | ||
schedule: "*/1 * * * *" | ||
startingDeadlineSeconds: 100 | ||
jobTemplate: | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: hello | ||
image: busybox | ||
args: | ||
- /bin/sh | ||
- -c | ||
- date; echo Hello from the Kubernetes cluster | ||
restartPolicy: OnFailure |