Skip to content

Commit

Permalink
Merge pull request #247 from intelops/trivytime
Browse files Browse the repository at this point in the history
added time
  • Loading branch information
vijeyash1 authored Oct 6, 2023
2 parents 4c6be72 + e784414 commit 83ad922
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
type AgentConfigurations struct {
SANamespace string `envconfig:"SA_NAMESPACE" default:"default"`
SAName string `envconfig:"SA_NAME" default:"default"`
OutdatedInterval string `envconfig:"OUTDATED_INTERVAL" default:"@every 20m"`
OutdatedInterval string `envconfig:"OUTDATED_INTERVAL" default:"0"`
GetAllInterval string `envconfig:"GETALL_INTERVAL" default:"*/30 * * * *"`
KubeScoreInterval string `envconfig:"KUBESCORE_INTERVAL" default:"*/40 * * * *"`
RakkessInterval string `envconfig:"RAKKESS_INTERVAL" default:"*/50 * * * *"`
KubePreUpgradeInterval string `envconfig:"KUBEPREUPGRADE_INTERVAL" default:"*/60 * * * *"`
TrivyInterval string `envconfig:"TRIVY_INTERVAL" default:"*/10 * * * *"`
SchedulerEnable bool `envconfig:"SCHEDULER_ENABLE" default:"false"`
SchedulerEnable bool `envconfig:"SCHEDULER_ENABLE" default:"true"`
}

func GetAgentConfigurations() (serviceConf *AgentConfigurations, err error) {
Expand Down
23 changes: 11 additions & 12 deletions agent/kubviz/k8smetrics_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,19 @@ var (
)

func runTrivyScans(config *rest.Config, js nats.JetStreamContext) error {
err := RunTrivyK8sClusterScan(js)
err := RunTrivyImageScans(config, js)
if err != nil {
return err
}
err = RunTrivyImageScans(config, js)
err = RunTrivySbomScan(config, js)
if err != nil {
return err
}
err = RunTrivySbomScan(config, js)
err = RunTrivyK8sClusterScan(js)
if err != nil {
return err
}

return nil

}
Expand Down Expand Up @@ -134,9 +135,7 @@ func main() {
}

collectAndPublishMetrics()
if schedulingIntervalStr == "" {
schedulingIntervalStr = "20m"
}

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

Expand Down Expand Up @@ -301,7 +300,7 @@ func watchK8sEvents(clientset *kubernetes.Clientset, js nats.JetStreamContext) {
func initScheduler(config *rest.Config, js nats.JetStreamContext, cfg config.AgentConfigurations, clientset *kubernetes.Clientset) (s *Scheduler) {
log := logging.NewLogger()
s = NewScheduler(log)
if cfg.OutdatedInterval != "" {
if cfg.OutdatedInterval != "" && cfg.OutdatedInterval != "0" {
sj, err := NewOutDatedImagesJob(config, js, cfg.OutdatedInterval)
if err != nil {
log.Fatal("no time interval", err)
Expand All @@ -311,7 +310,7 @@ func initScheduler(config *rest.Config, js nats.JetStreamContext, cfg config.Age
log.Fatal("failed to do job", err)
}
}
if cfg.GetAllInterval != "" {
if cfg.GetAllInterval != "" && cfg.GetAllInterval != "0" {
sj, err := NewKetallJob(config, js, cfg.GetAllInterval)
if err != nil {
log.Fatal("no time interval", err)
Expand All @@ -321,7 +320,7 @@ func initScheduler(config *rest.Config, js nats.JetStreamContext, cfg config.Age
log.Fatal("failed to do job", err)
}
}
if cfg.KubeScoreInterval != "" {
if cfg.KubeScoreInterval != "" && cfg.KubeScoreInterval != "0" {
sj, err := NewKubescoreJob(clientset, js, cfg.KubeScoreInterval)
if err != nil {
log.Fatal("no time interval", err)
Expand All @@ -331,7 +330,7 @@ func initScheduler(config *rest.Config, js nats.JetStreamContext, cfg config.Age
log.Fatal("failed to do job", err)
}
}
if cfg.RakkessInterval != "" {
if cfg.RakkessInterval != "" && cfg.RakkessInterval != "0" {
sj, err := NewRakkessJob(config, js, cfg.RakkessInterval)
if err != nil {
log.Fatal("no time interval", err)
Expand All @@ -341,7 +340,7 @@ func initScheduler(config *rest.Config, js nats.JetStreamContext, cfg config.Age
log.Fatal("failed to do job", err)
}
}
if cfg.KubePreUpgradeInterval != "" {
if cfg.KubePreUpgradeInterval != "" && cfg.KubePreUpgradeInterval != "0" {
sj, err := NewKubePreUpgradeJob(config, js, cfg.KubePreUpgradeInterval)
if err != nil {
log.Fatal("no time interval", err)
Expand All @@ -351,7 +350,7 @@ func initScheduler(config *rest.Config, js nats.JetStreamContext, cfg config.Age
log.Fatal("failed to do job", err)
}
}
if cfg.TrivyInterval != "" {
if cfg.TrivyInterval != "" && cfg.TrivyInterval != "0" {
sj, err := NewTrivyJob(config, js, cfg.TrivyInterval)
if err != nil {
log.Fatal("no time interval", err)
Expand Down
2 changes: 1 addition & 1 deletion agent/kubviz/scheduler_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (v *KubePreUpgradeJob) CronSpec() string {

func (j *KubePreUpgradeJob) Run() {
// Call the Kubepreupgrade function with the provided config and js
err := GetAllResources(j.config, j.js)
err := KubePreUpgradeDetector(j.config, j.js)
LogErr(err)
}

Expand Down
2 changes: 1 addition & 1 deletion agent/kubviz/trivy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func executeCommandTrivy(command string) ([]byte, error) {
}
func RunTrivyK8sClusterScan(js nats.JetStreamContext) error {
var report report.ConsolidatedReport
cmdString := "trivy k8s --report summary cluster --exclude-nodes kubernetes.io/arch:amd64 --timeout 20m -f json --cache-dir /tmp/.cache --debug"
cmdString := "trivy k8s --report summary cluster --exclude-nodes kubernetes.io/arch:amd64 --timeout 60m -f json --cache-dir /tmp/.cache --debug"

// Log the command before execution
log.Printf("Executing command: %s\n", cmdString)
Expand Down

0 comments on commit 83ad922

Please sign in to comment.