Skip to content

Commit 1b7e474

Browse files
authored
fix: add context to target finding on k8s table view (aquasecurity#6099)
Signed-off-by: chenk <[email protected]>
1 parent 876ab84 commit 1b7e474

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pkg/k8s/report/table.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package report
22

33
import (
44
"context"
5+
"fmt"
56
"io"
7+
"strings"
68

79
"golang.org/x/xerrors"
810

@@ -50,8 +52,9 @@ func (tw TableWriter) Write(ctx context.Context, report Report) error {
5052
Output: tw.Output,
5153
Severities: tw.Severities,
5254
}
53-
for _, r := range report.Resources {
55+
for i, r := range report.Resources {
5456
if r.Report.Results.Failed() {
57+
updateTargetContext(&report.Resources[i])
5558
err := t.Write(ctx, r.Report)
5659
if err != nil {
5760
return err
@@ -67,3 +70,14 @@ func (tw TableWriter) Write(ctx context.Context, report Report) error {
6770

6871
return nil
6972
}
73+
74+
// updateTargetContext add context namespace, kind and name to the target
75+
func updateTargetContext(r *Resource) {
76+
targetName := fmt.Sprintf("namespace: %s, %s: %s", r.Namespace, strings.ToLower(r.Kind), r.Name)
77+
if r.Kind == "NodeComponents" || r.Kind == "NodeInfo" {
78+
targetName = fmt.Sprintf("node: %s", r.Name)
79+
}
80+
for i := range r.Report.Results {
81+
r.Report.Results[i].Target = targetName
82+
}
83+
}

0 commit comments

Comments
 (0)