@@ -726,7 +726,22 @@ func (r *ScanReconciler) startReadOnlyHooks(scan *executionv1.Scan) error {
726726 rules ,
727727 )
728728
729+ // Get all read-only-hooks for scan to later check that they weren't already created
730+ jobs , err := r .getJobsForScan (scan , client.MatchingLabels {
731+ "experimental.securecodebox.io/job-type" : "read-only-hook" ,
732+ })
733+ if err != nil {
734+ return err
735+ }
736+
729737 for _ , hook := range readOnlyHooks {
738+ // Check if hook was already executed
739+ if containsJobForHook (jobs , hook ) == true {
740+ r .Log .V (4 ).Info ("Skipping creation of job for hook '%s' as it already exists" , hook .Name )
741+ // Job was already created
742+ continue
743+ }
744+
730745 rawFileURL , err := r .PresignedGetURL (scan .UID , scan .Status .RawResultFile )
731746 if err != nil {
732747 return err
@@ -758,6 +773,20 @@ func (r *ScanReconciler) startReadOnlyHooks(scan *executionv1.Scan) error {
758773 return nil
759774}
760775
776+ func containsJobForHook (jobs * batch.JobList , hook executionv1.ScanCompletionHook ) bool {
777+ if len (jobs .Items ) == 0 {
778+ return false
779+ }
780+
781+ for _ , job := range jobs .Items {
782+ if job .ObjectMeta .Labels ["experimental.securecodebox.io/hook-name" ] == hook .Name {
783+ return true
784+ }
785+ }
786+
787+ return false
788+ }
789+
761790func (r * ScanReconciler ) checkIfReadOnlyHookIsCompleted (scan * executionv1.Scan ) error {
762791 ctx := context .Background ()
763792 readOnlyHookCompletion , err := r .checkIfJobIsCompleted (scan , client.MatchingLabels {"experimental.securecodebox.io/job-type" : "read-only-hook" })
0 commit comments