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

Commit 186744d

Browse files
committed
Implement ParseCompleted Step
1 parent fb8a9f1 commit 186744d

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

operator/apis/execution/v1/scan_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const (
6464
type HookStatus struct {
6565
HookName string `json:"hookName"`
6666
State HookState `json:"state"`
67-
JobName string `json:"jobName"`
67+
JobName string `json:"jobName,omitempty"`
6868
}
6969

7070
// FindingStats contains the general stats about the results of the scan

operator/apis/execution/v1/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operator/config/crd/bases/execution.experimental.securecodebox.io_scans.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ spec:
121121
jobName:
122122
type: string
123123
state:
124+
description: HookState Describes the State of a Hook on a Scan
124125
type: string
125126
required:
126127
- hookName
127-
- jobName
128128
- state
129129
type: object
130130
type: array
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: execution.experimental.securecodebox.io/v1
2+
kind: ScanCompletionHook
3+
metadata:
4+
name: "sleep-rw"
5+
spec:
6+
image: "sleep"
7+
type: "ReadAndWrite"
8+
env: []

operator/controllers/execution/scan_controller.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,42 @@ func (r *ScanReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
114114
err = r.checkIfParsingIsCompleted(&scan)
115115
case "ParseCompleted":
116116
// Hook status erstellen
117-
// List all ReadAndWrite Hook -> Hook Status an Scan hängen
118-
// Scan State auf ReadAndWriteHookProcessing setzen
117+
118+
var scanCompletionHooks executionv1.ScanCompletionHookList
119+
120+
if err := r.List(ctx, &scanCompletionHooks, client.InNamespace(scan.Namespace)); err != nil {
121+
r.Log.V(7).Info("Unable to fetch ScanCompletionHooks")
122+
return ctrl.Result{}, err
123+
}
124+
125+
r.Log.Info("Found ScanCompletionHooks", "ScanCompletionHooks", len(scanCompletionHooks.Items))
126+
127+
readAndWriteHooks := []executionv1.ScanCompletionHook{}
128+
// filter all ReadAndWriteHooks in the scamCompletionHooks list
129+
for _, hook := range scanCompletionHooks.Items {
130+
if hook.Spec.Type == executionv1.ReadAndWrite {
131+
readAndWriteHooks = append(readAndWriteHooks, hook)
132+
}
133+
}
134+
135+
r.Log.Info("Found ReadAndWriteHooks", "ReadAndWriteHooks", len(readAndWriteHooks))
136+
137+
hookStatus := []executionv1.HookStatus{}
138+
139+
for _, hook := range readAndWriteHooks {
140+
hookStatus = append(hookStatus, executionv1.HookStatus{
141+
HookName: hook.Name,
142+
State: executionv1.Pending,
143+
})
144+
}
145+
146+
scan.Status.State = "ReadAndWriteHookProcessing"
147+
scan.Status.ReadAndWriteHookStatus = hookStatus
148+
149+
if err := r.Status().Update(ctx, &scan); err != nil {
150+
r.Log.Error(err, "unable to update Scan status")
151+
return ctrl.Result{}, err
152+
}
119153
case "ReadAndWriteHookProcessing":
120154
// Hook Status Array durchgegen
121155

0 commit comments

Comments
 (0)