Skip to content

Commit

Permalink
trivy changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nithunikzz committed Feb 28, 2024
1 parent d46ae02 commit 60e559e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 71 deletions.
133 changes: 67 additions & 66 deletions agent/kubviz/k8smetrics_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,42 @@ import (
"log"
"os"

//"os/signal"
//"syscall"
"os/signal"
"syscall"
"time"

//"github.com/go-co-op/gocron"
"github.com/go-co-op/gocron"
"github.com/nats-io/nats.go"

"context"

"github.com/intelops/kubviz/pkg/mtlsnats"
"github.com/intelops/kubviz/pkg/opentelemetry"

//"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

//"github.com/intelops/kubviz/agent/config"
"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"
"github.com/intelops/kubviz/agent/kubviz/plugins/ketall"
"github.com/intelops/kubviz/agent/kubviz/plugins/kubepreupgrade"

//"github.com/intelops/kubviz/agent/kubviz/plugins/kuberhealthy"
//"github.com/intelops/kubviz/agent/kubviz/plugins/kubescore"
//"github.com/intelops/kubviz/agent/kubviz/plugins/outdated"
//"github.com/intelops/kubviz/agent/kubviz/plugins/rakkess"
"github.com/intelops/kubviz/agent/kubviz/plugins/kuberhealthy"
"github.com/intelops/kubviz/agent/kubviz/plugins/kubescore"
"github.com/intelops/kubviz/agent/kubviz/plugins/outdated"
"github.com/intelops/kubviz/agent/kubviz/plugins/rakkess"

"github.com/intelops/kubviz/agent/kubviz/plugins/trivy"
//"github.com/intelops/kubviz/agent/kubviz/scheduler"
"github.com/intelops/kubviz/agent/kubviz/scheduler"

_ "k8s.io/client-go/plugin/pkg/client/auth/azure"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"

// _ "k8s.io/client-go/plugin/pkg/client/auth/openstack"
//"github.com/intelops/kubviz/agent/server"
"github.com/intelops/kubviz/agent/server"
//_ "k8s.io/client-go/plugin/pkg/client/auth/openstack"
"k8s.io/client-go/tools/clientcmd"
)

Expand Down Expand Up @@ -66,14 +67,14 @@ var (
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
env := Production
// clusterMetricsChan := make(chan error, 1)
// cfg, err := config.GetAgentConfigurations()
// if err != nil {
// log.Fatal("Failed to retrieve agent configurations", err)
// }
clusterMetricsChan := make(chan error, 1)
cfg, err := config.GetAgentConfigurations()
if err != nil {
log.Fatal("Failed to retrieve agent configurations", err)
}
var (
config *rest.Config
//clientset *kubernetes.Clientset
config *rest.Config
clientset *kubernetes.Clientset
)

var mtlsConfig mtlsnats.MtlsConfig
Expand All @@ -100,7 +101,7 @@ func main() {

if nc == nil {
nc, _ = nats.Connect(natsurl, nats.Name("K8s Metrics"), nats.Token(token))
//events.CheckErr(err)
events.CheckErr(err)
}
js, err := nc.JetStream()
events.CheckErr(err)
Expand All @@ -111,13 +112,13 @@ func main() {
if err != nil {
log.Fatal(err)
}
//clientset = events.GetK8sClient(config)
clientset = events.GetK8sClient(config)
} else {
config, err = rest.InClusterConfig()
if err != nil {
log.Fatal(err)
}
//clientset = events.GetK8sClient(config)
clientset = events.GetK8sClient(config)
}

tp, err := opentelemetry.InitTracer()
Expand All @@ -130,54 +131,54 @@ func main() {
}
}()

// go events.PublishMetrics(clientset, js, clusterMetricsChan)
// if cfg.KuberHealthyEnable {
// go kuberhealthy.StartKuberHealthy(js)
// }
// go server.StartServer()
go events.PublishMetrics(clientset, js, clusterMetricsChan)
if cfg.KuberHealthyEnable {
go kuberhealthy.StartKuberHealthy(js)
}
go server.StartServer()
collectAndPublishMetrics := func() {
// err := outdated.OutDatedImages(config, js)
// events.LogErr(err)
// err = kubepreupgrade.KubePreUpgradeDetector(config, js)
// events.LogErr(err)
// err = ketall.GetAllResources(config, js)
// events.LogErr(err)
// err = rakkess.RakeesOutput(config, js)
// events.LogErr(err)
// err = trivy.RunTrivySbomScan(config, js)
// events.LogErr(err)
err := outdated.OutDatedImages(config, js)
events.LogErr(err)
err = kubepreupgrade.KubePreUpgradeDetector(config, js)
events.LogErr(err)
err = ketall.GetAllResources(config, js)
events.LogErr(err)
err = rakkess.RakeesOutput(config, js)
events.LogErr(err)
err = trivy.RunTrivySbomScan(config, js)
events.LogErr(err)
err = trivy.RunTrivyImageScans(config, js)
events.LogErr(err)
// err = trivy.RunTrivyK8sClusterScan(js)
// events.LogErr(err)
// err = kubescore.RunKubeScore(clientset, js)
// events.LogErr(err)
err = trivy.RunTrivyK8sClusterScan(js)
events.LogErr(err)
err = kubescore.RunKubeScore(clientset, js)
events.LogErr(err)
}

collectAndPublishMetrics()

// if cfg.SchedulerEnable { // Assuming "cfg.Schedule" is a boolean indicating whether to schedule or not.
// scheduler := scheduler.InitScheduler(config, js, *cfg, clientset)

// // Start the scheduler
// scheduler.Start()
// signals := make(chan os.Signal, 1)
// signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
// <-signals

// scheduler.Stop()
// } else {
// if schedulingIntervalStr == "" {
// schedulingIntervalStr = "20m"
// }
// schedulingInterval, err := time.ParseDuration(schedulingIntervalStr)
// if err != nil {
// log.Fatalf("Failed to parse SCHEDULING_INTERVAL: %v", err)
// }
// s := gocron.NewScheduler(time.UTC)
// s.Every(schedulingInterval).Do(func() {
// collectAndPublishMetrics()
// })
// s.StartBlocking()
// }
if cfg.SchedulerEnable { // Assuming "cfg.Schedule" is a boolean indicating whether to schedule or not.
scheduler := scheduler.InitScheduler(config, js, *cfg, clientset)

// Start the scheduler
scheduler.Start()
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
<-signals

scheduler.Stop()
} else {
if schedulingIntervalStr == "" {
schedulingIntervalStr = "20m"
}
schedulingInterval, err := time.ParseDuration(schedulingIntervalStr)
if err != nil {
log.Fatalf("Failed to parse SCHEDULING_INTERVAL: %v", err)
}
s := gocron.NewScheduler(time.UTC)
s.Every(schedulingInterval).Do(func() {
collectAndPublishMetrics()
})
s.StartBlocking()
}
}
2 changes: 1 addition & 1 deletion agent/kubviz/plugins/events/event_metrics_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func publishK8sMetrics(id string, mtype string, mdata *v1.Event, js nats.JetStre
if err != nil {
return true, err
}
//log.Printf("Metrics with ID:%s has been published\n", id)
log.Printf("Metrics with ID:%s has been published\n", id)
return false, nil
}

Expand Down
2 changes: 1 addition & 1 deletion agent/kubviz/plugins/kubepreupgrade/kubePreUpgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func publishK8sDepricated_Deleted_Api(result *model.Result, js nats.JetStreamCon
}
}

//log.Printf("Metrics with Deletedapi and depricated api has been published")
log.Printf("Metrics with Deletedapi and depricated api has been published")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion agent/kubviz/plugins/kubescore/kube_score.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func publishKubescoreMetrics(report []json_v2.ScoredObject, js nats.JetStreamCon
return err
}
//log.Printf("Recommendations with ID:%s has been published\n", id)
//log.Printf("Recommendations :%#v", report)
log.Printf("Recommendations :%#v", report)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion agent/kubviz/plugins/outdated/outdated.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func PublishOutdatedImages(out model.CheckResultfinal, js nats.JetStreamContext)
if err != nil {
return err
}
//log.Printf("Metrics with outdated images has been published")
log.Printf("Metrics with outdated images has been published")
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion agent/kubviz/plugins/rakkess/rakees_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"os/signal"
"syscall"
Expand Down Expand Up @@ -99,7 +100,7 @@ func RakeesOutput(config *rest.Config, js nats.JetStreamContext) error {
if err != nil {
return err
}
//log.Printf("Metrics with resource %s has been published", resourceType)
log.Printf("Metrics with resource %s has been published", resourceType)
}
return nil

Expand Down

0 comments on commit 60e559e

Please sign in to comment.