Skip to content

Commit

Permalink
fix: add context to target finding on k8s table view (#6099)
Browse files Browse the repository at this point in the history
Signed-off-by: chenk <hen.keinan@gmail.com>
  • Loading branch information
chen-keinan authored Feb 26, 2024
1 parent 876ab84 commit 1b7e474
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/k8s/report/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package report

import (
"context"
"fmt"
"io"
"strings"

"golang.org/x/xerrors"

Expand Down Expand Up @@ -50,8 +52,9 @@ func (tw TableWriter) Write(ctx context.Context, report Report) error {
Output: tw.Output,
Severities: tw.Severities,
}
for _, r := range report.Resources {
for i, r := range report.Resources {
if r.Report.Results.Failed() {
updateTargetContext(&report.Resources[i])
err := t.Write(ctx, r.Report)
if err != nil {
return err
Expand All @@ -67,3 +70,14 @@ func (tw TableWriter) Write(ctx context.Context, report Report) error {

return nil
}

// updateTargetContext add context namespace, kind and name to the target
func updateTargetContext(r *Resource) {
targetName := fmt.Sprintf("namespace: %s, %s: %s", r.Namespace, strings.ToLower(r.Kind), r.Name)
if r.Kind == "NodeComponents" || r.Kind == "NodeInfo" {
targetName = fmt.Sprintf("node: %s", r.Name)
}
for i := range r.Report.Results {
r.Report.Results[i].Target = targetName
}
}

0 comments on commit 1b7e474

Please sign in to comment.