Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions operator/apis/execution/v1/parsedefinition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ type ParseDefinitionSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of ParseDefinition. Edit ParseDefinition_types.go to remove/update
HandlesResultsType string `json:"handlesResultsType,omitempty"`
Image string `json:"image,omitempty"`
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
// Image is the reference to the parser container image which ca transform the raw scan report into findings
Image string `json:"image,omitempty"`
// ImagePullSecrets used to access private parser images
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
}

// ParseDefinitionStatus defines the observed state of ParseDefinition
Expand All @@ -42,7 +42,6 @@ type ParseDefinitionStatus struct {
}

// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="Handles Type",type=string,JSONPath=`.spec.handlesResultsType`,description="Which result file type the parser is able to handle"
// +kubebuilder:printcolumn:name="Image",type=string,JSONPath=`.spec.image`,description="Scanner Container Image"

// ParseDefinition is the Schema for the parsedefinitions API
Expand Down
11 changes: 7 additions & 4 deletions operator/apis/execution/v1/scheduledscan_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ type ScheduledScanSpec struct {
// Important: Run "make" to regenerate code after modifying this file

// Interval describes how often the scan should be repeated
// Examples: '12h', '7d', '30m' (only days, hours and minutes supported, specified as integers)
// Examples: '12h', '30m'
Interval metav1.Duration `json:"interval"`

// HistoryLimit determines how many past Scans will be kept until the oldest one will be delted, defaults to 3. When set to 0 Scans will be deleted directly after completion
HistoryLimit int64 `json:"historyLimit,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0

// Foo is an example field of ScheduledScan. Edit ScheduledScan_types.go to remove/update
// SuccessfulJobsHistoryLimit determines how many past Scans will be kept until the oldest one will be deleted, defaults to 3. When set to 0, Scans will be deleted directly after completion
SuccessfulJobsHistoryLimit *int32 `json:"successfulJobsHistoryLimit,omitempty"`

// ScanSpec describes the scan which should be started regularly
ScanSpec *ScanSpec `json:"scanSpec"`
}

Expand Down
5 changes: 5 additions & 0 deletions operator/apis/execution/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ metadata:
name: parsedefinitions.execution.securecodebox.io
spec:
additionalPrinterColumns:
- JSONPath: .spec.handlesResultsType
description: Which result file type the parser is able to handle
name: Handles Type
type: string
- JSONPath: .spec.image
description: Scanner Container Image
name: Image
Expand Down Expand Up @@ -44,13 +40,12 @@ spec:
spec:
description: ParseDefinitionSpec defines the desired state of ParseDefinition
properties:
handlesResultsType:
description: Foo is an example field of ParseDefinition. Edit ParseDefinition_types.go
to remove/update
type: string
image:
description: Image is the reference to the parser container image which
ca transform the raw scan report into findings
type: string
imagePullSecrets:
description: ImagePullSecrets used to access private parser images
items:
description: LocalObjectReference contains enough information to let
you locate the referenced object inside the same namespace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,12 @@ spec:
spec:
description: ScheduledScanSpec defines the desired state of ScheduledScan
properties:
historyLimit:
description: HistoryLimit determines how many past Scans will be kept
until the oldest one will be delted, defaults to 3. When set to 0
Scans will be deleted directly after completion
format: int64
type: integer
interval:
description: 'Interval describes how often the scan should be repeated
Examples: ''12h'', ''7d'', ''30m'' (only days, hours and minutes supported,
specified as integers)'
Examples: ''12h'', ''30m'''
type: string
scanSpec:
description: Foo is an example field of ScheduledScan. Edit ScheduledScan_types.go
to remove/update
description: ScanSpec describes the scan which should be started regularly
properties:
cascades:
description: A label selector is a label query over a set of resources.
Expand Down Expand Up @@ -232,6 +224,13 @@ spec:
scanType:
type: string
type: object
successfulJobsHistoryLimit:
description: SuccessfulJobsHistoryLimit determines how many past Scans
will be kept until the oldest one will be deleted, defaults to 3.
When set to 0, Scans will be deleted directly after completion
format: int32
minimum: 0
type: integer
required:
- interval
- scanSpec
Expand Down
1 change: 0 additions & 1 deletion operator/config/samples/execution_v1_parsedefinition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ kind: ParseDefinition
metadata:
name: "nmap-xml"
spec:
handlesResultsType: nmap-xml
image: securecodebox/nmap-parser
2 changes: 1 addition & 1 deletion operator/config/samples/execution_v1_scheduledscan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: scheduled-nmap-localhost
spec:
interval: 1m
historyLimit: 2
successfulJobsHistoryLimit: 2
scanSpec:
scanType: "nmap"
parameters:
Expand Down
7 changes: 6 additions & 1 deletion operator/controllers/execution/scheduledscan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ func (r *ScheduledScanReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
}

// Delete Old Scans when exceeding the history limit
var historyLimit int32 = 3
if scheduledScan.Spec.SuccessfulJobsHistoryLimit != nil {
historyLimit = *scheduledScan.Spec.SuccessfulJobsHistoryLimit
}

for i, scan := range completedScans {
if int64(i) >= int64(len(completedScans))-scheduledScan.Spec.HistoryLimit {
if int32(i) >= int32(len(completedScans))-historyLimit {
break
}
if err := r.Delete(ctx, &scan, client.PropagationPolicy(metav1.DeletePropagationBackground)); (err) != nil {
Expand Down
11 changes: 3 additions & 8 deletions operator/crds/execution.securecodebox.io_parsedefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ metadata:
name: parsedefinitions.execution.securecodebox.io
spec:
additionalPrinterColumns:
- JSONPath: .spec.handlesResultsType
description: Which result file type the parser is able to handle
name: Handles Type
type: string
- JSONPath: .spec.image
description: Scanner Container Image
name: Image
Expand Down Expand Up @@ -44,13 +40,12 @@ spec:
spec:
description: ParseDefinitionSpec defines the desired state of ParseDefinition
properties:
handlesResultsType:
description: Foo is an example field of ParseDefinition. Edit ParseDefinition_types.go
to remove/update
type: string
image:
description: Image is the reference to the parser container image which
ca transform the raw scan report into findings
type: string
imagePullSecrets:
description: ImagePullSecrets used to access private parser images
items:
description: LocalObjectReference contains enough information to let
you locate the referenced object inside the same namespace.
Expand Down
19 changes: 9 additions & 10 deletions operator/crds/execution.securecodebox.io_scheduledscans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,12 @@ spec:
spec:
description: ScheduledScanSpec defines the desired state of ScheduledScan
properties:
historyLimit:
description: HistoryLimit determines how many past Scans will be kept
until the oldest one will be delted, defaults to 3. When set to 0
Scans will be deleted directly after completion
format: int64
type: integer
interval:
description: 'Interval describes how often the scan should be repeated
Examples: ''12h'', ''7d'', ''30m'' (only days, hours and minutes supported,
specified as integers)'
Examples: ''12h'', ''30m'''
type: string
scanSpec:
description: Foo is an example field of ScheduledScan. Edit ScheduledScan_types.go
to remove/update
description: ScanSpec describes the scan which should be started regularly
properties:
cascades:
description: A label selector is a label query over a set of resources.
Expand Down Expand Up @@ -232,6 +224,13 @@ spec:
scanType:
type: string
type: object
successfulJobsHistoryLimit:
description: SuccessfulJobsHistoryLimit determines how many past Scans
will be kept until the oldest one will be deleted, defaults to 3.
When set to 0, Scans will be deleted directly after completion
format: int32
minimum: 0
type: integer
required:
- interval
- scanSpec
Expand Down