Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit 3461636

Browse files
committed
#29 Check if read only hook were already created before starting the job
1 parent 116510a commit 3461636

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

operator/controllers/execution/scan_controller.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
761790
func (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

Comments
 (0)