Skip to content

Commit b4ad00f

Browse files
authored
fix(cli): ensure correct command is picked by telemetry (#9260)
1 parent ed4640e commit b4ad00f

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

pkg/commands/artifact/run.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const (
4747
TargetRepository TargetKind = "repo"
4848
TargetSBOM TargetKind = "sbom"
4949
TargetVM TargetKind = "vm"
50+
TargetK8s TargetKind = "k8s"
5051
)
5152

5253
var (
@@ -113,7 +114,7 @@ func WithInitializeService(f InitializeScanService) RunnerOption {
113114

114115
// NewRunner initializes Runner that provides scanning functionalities.
115116
// It is possible to return SkipScan and it must be handled by caller.
116-
func NewRunner(ctx context.Context, cliOptions flag.Options, opts ...RunnerOption) (Runner, error) {
117+
func NewRunner(ctx context.Context, cliOptions flag.Options, targetKind TargetKind, opts ...RunnerOption) (Runner, error) {
117118
r := &runner{}
118119
for _, opt := range opts {
119120
opt(r)
@@ -125,9 +126,8 @@ func NewRunner(ctx context.Context, cliOptions flag.Options, opts ...RunnerOptio
125126
Timeout: cliOptions.Timeout,
126127
TraceHTTP: cliOptions.TraceHTTP,
127128
}))
128-
// get the sub command that is being used or fallback to "trivy"
129-
commandName := lo.NthOr(os.Args, 1, "trivy")
130-
r.versionChecker = notification.NewVersionChecker(commandName, &cliOptions)
129+
130+
r.versionChecker = notification.NewVersionChecker(string(targetKind), &cliOptions)
131131

132132
// Update the vulnerability database if needed.
133133
if err := r.initDB(ctx, cliOptions); err != nil {
@@ -421,7 +421,7 @@ func Run(ctx context.Context, opts flag.Options, targetKind TargetKind) (err err
421421
}
422422

423423
func run(ctx context.Context, opts flag.Options, targetKind TargetKind) (types.Report, error) {
424-
r, err := NewRunner(ctx, opts)
424+
r, err := NewRunner(ctx, opts, targetKind)
425425
if err != nil {
426426
if errors.Is(err, SkipScan) {
427427
return types.Report{}, nil

pkg/k8s/commands/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func newRunner(flagOpts flag.Options, cluster string) *runner {
6262
}
6363

6464
func (r *runner) run(ctx context.Context, artifacts []*k8sArtifacts.Artifact) error {
65-
runner, err := cmd.NewRunner(ctx, r.flagOpts)
65+
runner, err := cmd.NewRunner(ctx, r.flagOpts, cmd.TargetK8s)
6666
if err != nil {
6767
if errors.Is(err, cmd.SkipScan) {
6868
return nil

pkg/k8s/scanner/scanner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func TestScanner_Scan(t *testing.T) {
276276
ctx := t.Context()
277277
uuid.SetFakeUUID(t, "3ff14136-e09f-4df9-80ea-%012d")
278278

279-
runner, err := cmd.NewRunner(ctx, flagOpts)
279+
runner, err := cmd.NewRunner(ctx, flagOpts, cmd.TargetK8s)
280280
require.NoError(t, err)
281281

282282
scanner := NewScanner(tt.clusterName, runner, flagOpts)

0 commit comments

Comments
 (0)