Skip to content

Commit 0ae4bba

Browse files
committed
added pvc to trivy
1 parent b2eb54a commit 0ae4bba

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

agent/kubviz/trivy.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package main
33
import (
44
"bytes"
55
"encoding/json"
6+
"fmt"
67
"log"
8+
"os"
79
exec "os/exec"
810
"strings"
911

@@ -29,8 +31,15 @@ func executeCommandTrivy(command string) ([]byte, error) {
2931
return outc.Bytes(), err
3032
}
3133
func RunTrivyK8sClusterScan(js nats.JetStreamContext) error {
34+
pvcMountPath := "/mnt/agent/kbz"
35+
trivyCacheDir := fmt.Sprintf("%s/trivy-cache", pvcMountPath)
36+
err := os.MkdirAll(trivyCacheDir, 0755)
37+
if err != nil {
38+
log.Printf("Error creating Trivy cache directory: %v\n", err)
39+
return err
40+
}
3241
var report report.ConsolidatedReport
33-
cmdString := "trivy k8s --report summary cluster --exclude-nodes kubernetes.io/arch:amd64 --timeout 60m -f json --cache-dir /tmp/.cache --debug"
42+
cmdString := fmt.Sprintf("trivy k8s --report summary cluster --exclude-nodes kubernetes.io/arch:amd64 --timeout 60m -f json --cache-dir %s --debug", trivyCacheDir)
3443
clearCacheCmd := "trivy k8s --clear-cache"
3544
out, err := executeCommandTrivy(cmdString)
3645
if err != nil {

0 commit comments

Comments
 (0)