Skip to content

Commit

Permalink
fix: cronjob schedule check
Browse files Browse the repository at this point in the history
  • Loading branch information
hayk99 committed Oct 18, 2024
1 parent 25ef785 commit bc16b95
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion charts/registry-scanner/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Sysdig Registry Scanner
type: application
home: https://www.sysdig.com/
icon: https://avatars.githubusercontent.com/u/5068817?s=200&v=4
version: 1.4.1
version: 1.4.2
appVersion: 0.5.0
maintainers:
- name: sysdiglabs
9 changes: 5 additions & 4 deletions charts/registry-scanner/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ Check cronjob value
{{- $month := index $parts 3 -}}
{{- $dayOfWeek := index $parts 4 -}}
{{- if and (eq $dayOfMonth "*" ) (eq $dayOfWeek "*") (eq $month "*") -}}}
{{- printf "WARNING: You have configured the registry scanner to run on a schedule of '%s'. Running the scanner more often than every 24 hours can increase the load on your registry. The recommended configuration is to perform a scan weekly." $schedule | fail}}
{{- if and (eq $dayOfMonth "*" ) (eq $dayOfWeek "*") (eq $month "*") -}}
{{- if or ($hour | contains "*") ($hour | contains ",") ($hour | contains "-") ($hour | contains "/") -}}
# {{- printf "WARNING: You have configured the registry scanner to run on a schedule of '%s'. Running the scanner more often than every 24 hours can increase the load on your registry. The recommended configuration is to perform a scan weekly." $schedule | fail}}
{{- fail (printf "WARNING: You have configured the registry scanner to run on a schedule of '%s'. Running the scanner more often than every 24 hours can increase the load on your registry. The recommended configuration is to perform a scan weekly." $schedule) }}
{{- end -}}
{{- end -}}
{{- else -}}
{{- print "Error: Wrong cronjob format." | quote }}
{{- end -}}
{{- end -}}
41 changes: 37 additions & 4 deletions charts/registry-scanner/tests/cronjob_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ tests:
set:
cronjob.schedule: "0 0 * * *"
asserts:
- failedTemplate:
errorMessage: "WARNING: You have configured the registry scanner to run on a schedule of '0 0 * * *'. \
Running the scanner more often than every 24 hours can increase the load on your registry. \
The recommended configuration is to perform a scan weekly."
- equal:
path: spec.schedule
value: "0 0 * * *"

- it: sets cronjob schedule less often than 24h
set:
Expand All @@ -138,3 +137,37 @@ tests:
- equal:
path: spec.schedule
value: "0 0 1 * *"

- it: sets cronjob schedule less often than 24h
set:
cronjob.schedule: "0 0 1 4 *"
asserts:
- equal:
path: spec.schedule
value: "0 0 1 4 *"
- it: sets cronjob schedule less often than 24h and slash
set:
cronjob.schedule: "0 1/2 * * *"
asserts:
- failedTemplate:
errorMessage: "WARNING: You have configured the registry scanner to run on a schedule of '0 1/2 * * *'. \
Running the scanner more often than every 24 hours can increase the load on your registry. \
The recommended configuration is to perform a scan weekly."

- it: sets cronjob schedule less often than 24h and comma
set:
cronjob.schedule: "0 1,2 * * *"
asserts:
- failedTemplate:
errorMessage: "WARNING: You have configured the registry scanner to run on a schedule of '0 1,2 * * *'. \
Running the scanner more often than every 24 hours can increase the load on your registry. \
The recommended configuration is to perform a scan weekly."

- it: sets cronjob schedule less often than 24h and dash
set:
cronjob.schedule: "0 1-2 * * *"
asserts:
- failedTemplate:
errorMessage: "WARNING: You have configured the registry scanner to run on a schedule of '0 1-2 * * *'. \
Running the scanner more often than every 24 hours can increase the load on your registry. \
The recommended configuration is to perform a scan weekly."

0 comments on commit bc16b95

Please sign in to comment.