Skip to content

Commit bb53edc

Browse files
committed
Make resourceMode optional
Default doesn't work work required field in kubernetes@1.24 Signed-off-by: Jannik Hollenbach <jannik@hollenbach.de>
1 parent ccbe6cf commit bb53edc

12 files changed

Lines changed: 17 additions & 21 deletions

operator/apis/execution/v1/scan_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ type ScanSpec struct {
115115
ScanType string `json:"scanType,omitempty"`
116116

117117
// The Resource Mode of the scan: Should it use namespace-local or cluster-wide resources (ScanType vs. ClusterScanType)
118+
// +kubebuilder:validation:Optional
118119
// +kubebuilder:default:=namespaceLocal
119120
// +kubebuilder:validation:Enum="namespaceLocal";"clusterWide"
120-
ResourceMode ResourceMode `json:"resourceMode"`
121+
ResourceMode *ResourceMode `json:"resourceMode"`
121122

122123
// All CLI parameters to configure the scan container.
123124
// +kubebuilder:validation:Required

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

Lines changed: 5 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/cascading.securecodebox.io_cascadingrules.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4257,8 +4257,6 @@ spec:
42574257
- name
42584258
type: object
42594259
type: array
4260-
required:
4261-
- resourceMode
42624260
type: object
42634261
required:
42644262
- matches

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,8 +4082,6 @@ spec:
40824082
- name
40834083
type: object
40844084
type: array
4085-
required:
4086-
- resourceMode
40874085
type: object
40884086
status:
40894087
description: ScanStatus defines the observed state of Scan

operator/config/crd/bases/execution.securecodebox.io_scheduledscans.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4239,8 +4239,6 @@ spec:
42394239
- name
42404240
type: object
42414241
type: array
4242-
required:
4243-
- resourceMode
42444242
type: object
42454243
successfulJobsHistoryLimit:
42464244
description: SuccessfulJobsHistoryLimit determines how many past Scans

operator/controllers/execution/scans/hook_reconciler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (r *ScanReconciler) setHookStatus(scan *executionv1.Scan) error {
3333

3434
var hookStatuses []*executionv1.HookStatus
3535

36-
if scan.Spec.ResourceMode == executionv1.NamespaceLocal {
36+
if scan.Spec.ResourceMode == nil || *scan.Spec.ResourceMode == executionv1.NamespaceLocal {
3737
var scanCompletionHooks executionv1.ScanCompletionHookList
3838
if err := r.List(ctx, &scanCompletionHooks,
3939
client.InNamespace(scan.Namespace),
@@ -192,7 +192,7 @@ func (r *ScanReconciler) processPendingHook(scan *executionv1.Scan, status *exec
192192
var hookName string
193193
var hookSpec executionv1.ScanCompletionHookSpec
194194

195-
if scan.Spec.ResourceMode == executionv1.NamespaceLocal {
195+
if scan.Spec.ResourceMode == nil || *scan.Spec.ResourceMode == executionv1.NamespaceLocal {
196196
var hook executionv1.ScanCompletionHook
197197
err = r.Get(ctx, types.NamespacedName{Name: status.HookName, Namespace: scan.Namespace}, &hook)
198198
if err != nil {
@@ -201,7 +201,7 @@ func (r *ScanReconciler) processPendingHook(scan *executionv1.Scan, status *exec
201201
}
202202
hookName = hook.Name
203203
hookSpec = hook.Spec
204-
} else if scan.Spec.ResourceMode == executionv1.ClusterWide {
204+
} else if *scan.Spec.ResourceMode == executionv1.ClusterWide {
205205
var clusterHook executionv1.ClusterScanCompletionHook
206206
err = r.Get(ctx, types.NamespacedName{Name: status.HookName}, &clusterHook)
207207
if err != nil {

operator/controllers/execution/scans/parse_reconciler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (r *ScanReconciler) startParser(scan *executionv1.Scan) error {
3939

4040
// get the parse definition matching the parseType of the scan result
4141
var parseDefinitionSpec executionv1.ParseDefinitionSpec
42-
if scan.Spec.ResourceMode == executionv1.NamespaceLocal {
42+
if scan.Spec.ResourceMode == nil || *scan.Spec.ResourceMode == executionv1.NamespaceLocal {
4343
var parseDefinition executionv1.ParseDefinition
4444
if err := r.Get(ctx, types.NamespacedName{Name: parseType, Namespace: scan.Namespace}, &parseDefinition); err != nil {
4545
log.V(7).Info("Unable to fetch ParseDefinition")
@@ -55,7 +55,7 @@ func (r *ScanReconciler) startParser(scan *executionv1.Scan) error {
5555
}
5656
log.Info("Matching ParseDefinition Found", "ParseDefinition", parseType)
5757
parseDefinitionSpec = parseDefinition.Spec
58-
} else if scan.Spec.ResourceMode == executionv1.ClusterWide {
58+
} else if *scan.Spec.ResourceMode == executionv1.ClusterWide {
5959
var clusterParseDefinition executionv1.ClusterParseDefinition
6060
if err := r.Get(ctx, types.NamespacedName{Name: parseType}, &clusterParseDefinition); err != nil {
6161
log.V(7).Info("Unable to fetch ClusterParseDefinition")

operator/controllers/execution/scans/scan_reconciler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (r *ScanReconciler) startScan(scan *executionv1.Scan) error {
5050

5151
// get the ScanType for the scan
5252
var scanTypeSpec executionv1.ScanTypeSpec
53-
if scan.Spec.ResourceMode == executionv1.NamespaceLocal {
53+
if scan.Spec.ResourceMode == nil || *scan.Spec.ResourceMode == executionv1.NamespaceLocal {
5454
var scanType executionv1.ScanType
5555
if err := r.Get(ctx, types.NamespacedName{Name: scan.Spec.ScanType, Namespace: scan.Namespace}, &scanType); err != nil {
5656

@@ -67,7 +67,7 @@ func (r *ScanReconciler) startScan(scan *executionv1.Scan) error {
6767
}
6868
log.Info("Matching ScanType Found", "ScanType", scanType.Name)
6969
scanTypeSpec = scanType.Spec
70-
} else if scan.Spec.ResourceMode == executionv1.ClusterWide {
70+
} else if *scan.Spec.ResourceMode == executionv1.ClusterWide {
7171
var clusterScanType executionv1.ClusterScanType
7272

7373
if err := r.Get(ctx, types.NamespacedName{Name: scan.Spec.ScanType}, &clusterScanType); err != nil {

operator/controllers/execution/test_utils_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ func createScanType(ctx context.Context, namespace string) {
6464
}
6565

6666
func createScheduledScan(ctx context.Context, namespace string, retriggerOnScanTypeChange bool) executionv1.ScheduledScan {
67+
namespaceLocalResourceMode := executionv1.NamespaceLocal
68+
6769
scheduledScan := executionv1.ScheduledScan{
6870
ObjectMeta: metav1.ObjectMeta{
6971
Name: "test-scan",
@@ -74,7 +76,7 @@ func createScheduledScan(ctx context.Context, namespace string, retriggerOnScanT
7476
RetriggerOnScanTypeChange: retriggerOnScanTypeChange,
7577
ScanSpec: &executionv1.ScanSpec{
7678
ScanType: "nmap",
77-
ResourceMode: executionv1.NamespaceLocal,
79+
ResourceMode: &namespaceLocalResourceMode,
7880
Parameters: []string{"scanme.nmap.org"},
7981
},
8082
},

operator/crds/cascading.securecodebox.io_cascadingrules.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4832,8 +4832,6 @@ spec:
48324832
- name
48334833
type: object
48344834
type: array
4835-
required:
4836-
- resourceMode
48374835
type: object
48384836
required:
48394837
- matches

0 commit comments

Comments
 (0)