@@ -33,7 +33,7 @@ var _ = Describe("ScanType controller", func() {
3333
3434 createNamespace (ctx , namespace )
3535 createScanType (ctx , namespace )
36- scheduledScan := createScheduledScan (ctx , namespace )
36+ scheduledScan := createScheduledScan (ctx , namespace , true )
3737
3838 // ensure that the ScheduledScan has been triggered
3939 waitForScheduledScanToBeTriggered (ctx , namespace )
@@ -74,7 +74,7 @@ var _ = Describe("ScanType controller", func() {
7474
7575 createNamespace (ctx , namespace )
7676 createScanType (ctx , namespace )
77- scheduledScan := createScheduledScan (ctx , namespace )
77+ scheduledScan := createScheduledScan (ctx , namespace , true )
7878
7979 // ensure that the ScheduledScan has been triggered
8080 waitForScheduledScanToBeTriggered (ctx , namespace )
@@ -96,6 +96,47 @@ var _ = Describe("ScanType controller", func() {
9696 }, timeout , interval ).Should (BeTrue (), "Scan was restarted without need" )
9797 })
9898 })
99+
100+ Context ("Should not trigger rescan when RetriggerOnScanTypeChange is set to False" , func () {
101+ It ("Should restart a scheduledScan when RetriggerOnScanTypeChange is set to True" , func () {
102+ ctx := context .Background ()
103+ namespace := "scantype-retrigger-on-scantype-false-test"
104+
105+ createNamespace (ctx , namespace )
106+ createScanType (ctx , namespace )
107+ scheduledScan := createScheduledScan (ctx , namespace , false )
108+
109+ // ensure that the ScheduledScan has been triggered
110+ waitForScheduledScanToBeTriggered (ctx , namespace )
111+ k8sClient .Get (ctx , types.NamespacedName {Name : "test-scan" , Namespace : namespace }, & scheduledScan )
112+ initialExecutionTime := * scheduledScan .Status .LastScheduleTime
113+
114+ // wait at least one second to ensure that the unix timestamps are at least one second apart.
115+ time .Sleep (1 * time .Second )
116+
117+ By ("Update ScanType to trigger rescan" )
118+ var scanType executionv1.ScanType
119+ k8sClient .Get (ctx , types.NamespacedName {Name : "nmap" , Namespace : namespace }, & scanType )
120+ if scanType .ObjectMeta .Annotations == nil {
121+ scanType .ObjectMeta .Annotations = map [string ]string {}
122+ }
123+ scanType .ObjectMeta .Annotations ["foobar.securecodebox.io/example" ] = "barfoo"
124+ err := k8sClient .Update (ctx , & scanType )
125+ if err != nil {
126+ panic (err )
127+ }
128+
129+ By ("Controller should set the lastScheduled Timestamp to the past to force a re-scan" )
130+ Eventually (func () bool {
131+ err := k8sClient .Get (ctx , types.NamespacedName {Name : "test-scan" , Namespace : namespace }, & scheduledScan )
132+ if errors .IsNotFound (err ) {
133+ panic ("ScheduledScan should be present for this check!" )
134+ }
135+
136+ return scheduledScan .Status .LastScheduleTime .Unix () == initialExecutionTime .Unix ()
137+ }, timeout , interval ).Should (BeTrue ())
138+ })
139+ })
99140})
100141
101142func waitForScheduledScanToBeTriggered (ctx context.Context , namespace string ) {
0 commit comments