diff --git a/agent/kubviz/k8smetrics_agent.go b/agent/kubviz/k8smetrics_agent.go index d7804086..6528d075 100644 --- a/agent/kubviz/k8smetrics_agent.go +++ b/agent/kubviz/k8smetrics_agent.go @@ -20,6 +20,7 @@ import ( "github.com/intelops/kubviz/agent/config" "github.com/intelops/kubviz/agent/kubviz/plugins/events" + //"github.com/intelops/kubviz/agent/kubviz/plugins/ketall" //"github.com/intelops/kubviz/agent/kubviz/plugins/kubepreupgrade" @@ -146,8 +147,8 @@ func main() { events.LogErr(err) // err = trivy.RunTrivyImageScans(config, js) // events.LogErr(err) - // err = trivy.RunTrivyK8sClusterScan(js) - // events.LogErr(err) + err = trivy.RunTrivyK8sClusterScan(js) + events.LogErr(err) // err = kubescore.RunKubeScore(clientset, js) // events.LogErr(err) } diff --git a/agent/kubviz/plugins/trivy/trivy.go b/agent/kubviz/plugins/trivy/trivy.go index 625b405a..19475155 100644 --- a/agent/kubviz/plugins/trivy/trivy.go +++ b/agent/kubviz/plugins/trivy/trivy.go @@ -2,7 +2,7 @@ package trivy import ( "bytes" - "context" + // "context" "encoding/json" "fmt" "log" @@ -14,21 +14,22 @@ import ( "github.com/google/uuid" "github.com/intelops/kubviz/constants" "github.com/intelops/kubviz/model" - "github.com/intelops/kubviz/pkg/opentelemetry" + + // "github.com/intelops/kubviz/pkg/opentelemetry" "github.com/nats-io/nats.go" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" + // "go.opentelemetry.io/otel" + // "go.opentelemetry.io/otel/attribute" ) var ClusterName string = os.Getenv("CLUSTER_NAME") func executeCommandTrivy(command string) ([]byte, error) { - ctx := context.Background() - tracer := otel.Tracer("trivy-cluster") - _, span := tracer.Start(opentelemetry.BuildContext(ctx), "executeCommandTrivy") - span.SetAttributes(attribute.String("trivy-k8s-agent", "command-running")) - defer span.End() + // ctx := context.Background() + // tracer := otel.Tracer("trivy-cluster") + // _, span := tracer.Start(opentelemetry.BuildContext(ctx), "executeCommandTrivy") + // span.SetAttributes(attribute.String("trivy-k8s-agent", "command-running")) + // defer span.End() cmd := exec.Command("/bin/sh", "-c", command) var outc, errc bytes.Buffer @@ -53,13 +54,13 @@ func RunTrivyK8sClusterScan(js nats.JetStreamContext) error { } var report report.ConsolidatedReport - ctx := context.Background() - tracer := otel.Tracer("trivy-cluster") - _, span := tracer.Start(opentelemetry.BuildContext(ctx), "RunTrivyK8sClusterScan") - span.SetAttributes(attribute.String("cluster-name", report.ClusterName)) - defer span.End() + // ctx := context.Background() + // tracer := otel.Tracer("trivy-cluster") + // _, span := tracer.Start(opentelemetry.BuildContext(ctx), "RunTrivyK8sClusterScan") + // span.SetAttributes(attribute.String("cluster-name", report.ClusterName)) + // defer span.End() - cmdString := fmt.Sprintf("trivy k8s --report summary cluster --exclude-nodes kubernetes.io/arch:amd64 --timeout 60m -f json --cache-dir %s --debug", trivyCacheDir) + cmdString := fmt.Sprintf("trivy k8s --report=summary cluster --exclude-nodes kubernetes.io/arch:amd64 --timeout 60m -f json --cache-dir %s --debug", trivyCacheDir) // clearCacheCmd := "trivy k8s --clear-cache" out, err := executeCommandTrivy(cmdString) if err != nil { @@ -106,5 +107,6 @@ func PublishTrivyK8sReport(report report.ConsolidatedReport, js nats.JetStreamCo return err } log.Printf("Trivy k8s cluster report with ID:%s has been published\n", metrics.ID) + log.Printf("Trivy k8s cluster report with ID:%s has been published\n", metrics.Report) return nil }