@@ -31,18 +31,12 @@ func executeCommandTrivy(command string) ([]byte, error) {
31
31
func RunTrivyK8sClusterScan (js nats.JetStreamContext ) error {
32
32
var report report.ConsolidatedReport
33
33
cmdString := "trivy k8s --report summary cluster --exclude-nodes kubernetes.io/arch:amd64 --timeout 60m -f json --cache-dir /tmp/.cache --debug"
34
-
35
- // Log the command before execution
36
- log .Printf ("Executing command: %s\n " , cmdString )
37
-
38
- // Execute the command
34
+ clearCacheCmd := "trivy k8s --clear-cache"
39
35
out , err := executeCommandTrivy (cmdString )
40
-
41
- // Handle errors and process the command output as needed
42
36
if err != nil {
43
37
log .Printf ("Error executing command: %v\n " , err )
38
+ return err
44
39
}
45
- // Log the command output for debugging purposes
46
40
log .Printf ("Command output: %s\n " , out )
47
41
outStr := string (out )
48
42
parts := strings .SplitN (outStr , "{" , 2 )
@@ -59,11 +53,15 @@ func RunTrivyK8sClusterScan(js nats.JetStreamContext) error {
59
53
log .Printf ("Error occurred while Unmarshalling json for k8s cluster scan: %v" , err )
60
54
return err
61
55
}
56
+ _ , err = executeCommandTrivy (clearCacheCmd )
57
+ if err != nil {
58
+ log .Printf ("Error executing command: %v\n " , err )
59
+ return err
60
+ }
62
61
err = publishTrivyK8sReport (report , js )
63
62
if err != nil {
64
63
return err
65
64
}
66
- cleanupCache ("/tmp/.cache" )
67
65
return nil
68
66
}
69
67
0 commit comments