Skip to content
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
1 change: 1 addition & 0 deletions operator/controllers/execution/scans/parse_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func (r *ScanReconciler) startParser(scan *executionv1.Scan) error {
},
},
}
job.Spec.Template.Labels = util.MergeStringMaps(job.Spec.Template.Labels, scan.ObjectMeta.DeepCopy().Labels)

// Merge Env from ParserTemplate
job.Spec.Template.Spec.Containers[0].Env = append(
Expand Down
2 changes: 2 additions & 0 deletions operator/controllers/execution/scans/scan_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ func (r *ScanReconciler) constructJobForScan(scan *executionv1.Scan, scanTypeSpe
Spec: *scanTypeSpec.JobTemplate.Spec.DeepCopy(),
}

job.Spec.Template.Labels = util.MergeStringMaps(job.Spec.Template.Labels, scan.ObjectMeta.DeepCopy().Labels)

//add recommend kubernetes "managed by" label, to tell the SCB container autodiscovery to ignore the scan pod
podLabels := job.Spec.Template.Labels
if podLabels == nil {
Expand Down
15 changes: 15 additions & 0 deletions operator/utils/string_maps_merge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: the secureCodeBox authors
//
// SPDX-License-Identifier: Apache-2.0

package utils

func MergeStringMaps(maps ...map[string]string) map[string]string {
result := map[string]string{}
for _, m := range maps {
for key, value := range m {
result[key] = value
}
}
return result
}
34 changes: 34 additions & 0 deletions operator/utils/string_maps_merge_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: the secureCodeBox authors
//
// SPDX-License-Identifier: Apache-2.0

package utils

import (
"fmt"
"reflect"
"testing"
)

type testDataMaps struct {
inOne map[string]string
inTwo map[string]string
out map[string]string
}

func TestStringMapsMerge(t *testing.T) {
var tests = []testDataMaps{
{
inOne: map[string]string{"foo": "1", "bar": "2"},
inTwo: map[string]string{"x": "3", "y": "4"},
out: map[string]string{"foo": "1", "bar": "2", "x": "3", "y": "4"},
},
}

for _, test := range tests {
actual := MergeStringMaps(test.inOne, test.inTwo)
if !reflect.DeepEqual(actual, test.out) {
t.Error(fmt.Errorf("mergeStringMaps(\"%s\", \"%s\") returned \"%s\", expected \"%s\"", test.inOne, test.inTwo, actual, test.out))
}
}
}