Skip to content

Commit

Permalink
fix: cronjob schedule check (#1987)
Browse files Browse the repository at this point in the history
  • Loading branch information
hayk99 authored Oct 18, 2024
1 parent 25ef785 commit 80d9f7e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 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
2 changes: 1 addition & 1 deletion charts/registry-scanner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Use the following command to deploy:
helm upgrade --install registry-scanner \
--namespace sysdig-agent \
--create-namespace \
--version=1.4.1 \
--version=1.4.2 \
--set config.secureBaseURL=<SYSDIG_SECURE_URL> \
--set config.secureAPIToken=<SYSDIG_SECURE_API_TOKEN> \
--set config.secureSkipTLS=true \
Expand Down
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 80d9f7e

Please sign in to comment.