From ce6075c8008599c2bfdea6d4d11affdcba236896 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Thu, 5 Nov 2020 10:13:50 +0100 Subject: [PATCH 1/2] Remove prom-active-alerts Prom-active-alerts command is not used, not tested, and currently broken. Let's remove it. --- .gitignore | 1 - cmd/prom-active-alerts/main.go | 23 ----------------------- 2 files changed, 24 deletions(-) delete mode 100644 cmd/prom-active-alerts/main.go diff --git a/.gitignore b/.gitignore index 400ca4d..7d22e2d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ cmd/kured/kured -cmd/prom-active-alerts/prom-active-alerts vendor build diff --git a/cmd/prom-active-alerts/main.go b/cmd/prom-active-alerts/main.go deleted file mode 100644 index a2dec5c..0000000 --- a/cmd/prom-active-alerts/main.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "fmt" - "log" - "os" - "regexp" - - "github.com/weaveworks/kured/pkg/alerts" -) - -func main() { - if len(os.Args) != 3 { - log.Fatalf("USAGE: %s ", os.Args[0]) - } - - count, err := alerts.PrometheusCountActive(os.Args[1], regexp.MustCompile(os.Args[2])) - if err != nil { - log.Fatal(err) - } - - fmt.Println(count) -} From 7091debe23653a72a18ee3410d284343bca5162a Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Thu, 5 Nov 2020 10:14:39 +0100 Subject: [PATCH 2/2] Make lint happier Without this, golint is complaining about a few cosmetic changes. This solves it, and is necessary if we want to add a lint test in CI. --- cmd/kured/main.go | 7 +++---- pkg/alerts/prometheus.go | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cmd/kured/main.go b/cmd/kured/main.go index 81ed076..ae94494 100644 --- a/cmd/kured/main.go +++ b/cmd/kured/main.go @@ -151,10 +151,9 @@ func rebootRequired() bool { if sentinelExists() { log.Infof("Reboot required") return true - } else { - log.Infof("Reboot not required") - return false } + log.Infof("Reboot not required") + return false } func rebootBlocked(client *kubernetes.Clientset, nodeID string) bool { @@ -334,7 +333,7 @@ func rebootAsRequired(nodeID string, window *timewindow.TimeWindow, TTL time.Dur source := rand.NewSource(time.Now().UnixNano()) tick := delaytick.New(source, period) - for _ = range tick { + for range tick { if window.Contains(time.Now()) && rebootRequired() && !rebootBlocked(client, nodeID) { node, err := client.CoreV1().Nodes().Get(context.TODO(), nodeID, metav1.GetOptions{}) if err != nil { diff --git a/pkg/alerts/prometheus.go b/pkg/alerts/prometheus.go index 3193294..625a4c0 100644 --- a/pkg/alerts/prometheus.go +++ b/pkg/alerts/prometheus.go @@ -12,7 +12,7 @@ import ( "github.com/prometheus/common/model" ) -// Returns a list of names of active (e.g. pending or firing) alerts, filtered +// PrometheusActiveAlerts returns a list of names of active (e.g. pending or firing) alerts, filtered // by the supplied regexp. func PrometheusActiveAlerts(prometheusURL string, filter *regexp.Regexp) ([]string, error) { client, err := api.NewClient(api.Config{Address: prometheusURL}) @@ -39,7 +39,7 @@ func PrometheusActiveAlerts(prometheusURL string, filter *regexp.Regexp) ([]stri } var activeAlerts []string - for activeAlert, _ := range activeAlertSet { + for activeAlert := range activeAlertSet { activeAlerts = append(activeAlerts, activeAlert) } sort.Sort(sort.StringSlice(activeAlerts))