Skip to content

Commit

Permalink
default values
Browse files Browse the repository at this point in the history
  • Loading branch information
Nithunikzz committed Sep 29, 2023
1 parent a5ab558 commit 91b3a6b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 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
53 changes: 26 additions & 27 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)
// if err != nil {
// return err
// }
// err = RunTrivySbomScan(config, js)
// if err != nil {
// return err
// }
err = RunTrivySbomScan(config, js)
if err != nil {
return err
}
err = RunTrivyK8sClusterScan(js)
if err != nil {
return err
}

return nil

}
Expand Down Expand Up @@ -118,25 +119,23 @@ func main() {
go publishMetrics(clientset, js, clusterMetricsChan)
go server.StartServer()
collectAndPublishMetrics := func() {
// err := outDatedImages(config, js)
// LogErr(err)
// err = KubePreUpgradeDetector(config, js)
// LogErr(err)
// err = GetAllResources(config, js)
// LogErr(err)
// err = RakeesOutput(config, js)
// LogErr(err)
err := outDatedImages(config, js)
LogErr(err)
err = KubePreUpgradeDetector(config, js)
LogErr(err)
err = GetAllResources(config, js)
LogErr(err)
err = RakeesOutput(config, js)
LogErr(err)
// getK8sEvents(clientset)
err := runTrivyScans(config, js)
err = runTrivyScans(config, js)
LogErr(err)
// err = RunKubeScore(clientset, js)
// LogErr(err)
}

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

0 comments on commit 91b3a6b

Please sign in to comment.