From 5d88e6c6db2aeba0d58a28cf50da10d95a499826 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Thu, 5 Nov 2020 10:56:16 +0100 Subject: [PATCH] Make lint happier in pkg folder Without this patch, lint will complain about a few cosmetic details. --- pkg/daemonsetlock/daemonsetlock.go | 6 ++++++ pkg/delaytick/delaytick.go | 2 +- pkg/notifications/slack/slack.go | 2 ++ pkg/timewindow/days.go | 8 ++++---- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pkg/daemonsetlock/daemonsetlock.go b/pkg/daemonsetlock/daemonsetlock.go index 20fe88d..4031065 100644 --- a/pkg/daemonsetlock/daemonsetlock.go +++ b/pkg/daemonsetlock/daemonsetlock.go @@ -11,6 +11,8 @@ import ( "k8s.io/client-go/kubernetes" ) +// DaemonSetLock holds all necessary information to do actions +// on the kured ds which holds lock info through annotations. type DaemonSetLock struct { client *kubernetes.Clientset nodeID string @@ -26,10 +28,12 @@ type lockAnnotationValue struct { TTL time.Duration `json:"TTL"` } +// New creates a daemonsetLock object containing the necessary data for follow up k8s requests func New(client *kubernetes.Clientset, nodeID, namespace, name, annotation string) *DaemonSetLock { return &DaemonSetLock{client, nodeID, namespace, name, annotation} } +// Acquire attempts to annotate the kured daemonset with lock info from instantiated DaemonSetLock using client-go func (dsl *DaemonSetLock) Acquire(metadata interface{}, TTL time.Duration) (acquired bool, owner string, err error) { for { ds, err := dsl.client.AppsV1().DaemonSets(dsl.namespace).Get(context.TODO(), dsl.name, metav1.GetOptions{}) @@ -75,6 +79,7 @@ func (dsl *DaemonSetLock) Acquire(metadata interface{}, TTL time.Duration) (acqu } } +// Test attempts to check the kured daemonset lock status (existence, expiry) from instantiated DaemonSetLock using client-go func (dsl *DaemonSetLock) Test(metadata interface{}) (holding bool, err error) { ds, err := dsl.client.AppsV1().DaemonSets(dsl.namespace).Get(context.TODO(), dsl.name, metav1.GetOptions{}) if err != nil { @@ -98,6 +103,7 @@ func (dsl *DaemonSetLock) Test(metadata interface{}) (holding bool, err error) { return false, nil } +// Release attempts to remove the lock data from the kured ds annotations using client-go func (dsl *DaemonSetLock) Release() error { for { ds, err := dsl.client.AppsV1().DaemonSets(dsl.namespace).Get(context.TODO(), dsl.name, metav1.GetOptions{}) diff --git a/pkg/delaytick/delaytick.go b/pkg/delaytick/delaytick.go index 4673bb9..880b64e 100644 --- a/pkg/delaytick/delaytick.go +++ b/pkg/delaytick/delaytick.go @@ -5,7 +5,7 @@ import ( "time" ) -// Tick regularly after an initial delay randomly distributed between d/2 and d + d/2 +// New ticks regularly after an initial delay randomly distributed between d/2 and d + d/2 func New(s rand.Source, d time.Duration) <-chan time.Time { c := make(chan time.Time) diff --git a/pkg/notifications/slack/slack.go b/pkg/notifications/slack/slack.go index 30ac4c5..3ebb7ec 100644 --- a/pkg/notifications/slack/slack.go +++ b/pkg/notifications/slack/slack.go @@ -43,10 +43,12 @@ func notify(hookURL, username, channel, message string) error { return nil } +// NotifyDrain is the exposed way to notify of a drain event onto a slack chan func NotifyDrain(hookURL, username, channel, nodeID string) error { return notify(hookURL, username, channel, fmt.Sprintf("Draining node %s", nodeID)) } +// NotifyReboot is the exposed way to notify of a reboot event onto a slack chan func NotifyReboot(hookURL, username, channel, nodeID string) error { return notify(hookURL, username, channel, fmt.Sprintf("Rebooting node %s", nodeID)) } diff --git a/pkg/timewindow/days.go b/pkg/timewindow/days.go index 2635c84..9d0e8b9 100644 --- a/pkg/timewindow/days.go +++ b/pkg/timewindow/days.go @@ -7,6 +7,8 @@ import ( "time" ) +// EveryDay contains all days of the week, and exports it +// for convenience use in the cmd line arguments. var EveryDay = []string{"su", "mo", "tu", "we", "th", "fr", "sa"} // dayStrings maps day strings to time.Weekdays @@ -78,14 +80,12 @@ func parseWeekday(day string) (time.Weekday, error) { if n, err := strconv.Atoi(day); err == nil { if n >= 0 && n < 7 { return time.Weekday(n), nil - } else { - return time.Sunday, fmt.Errorf("Invalid weekday, number out of range: %s", day) } + return time.Sunday, fmt.Errorf("Invalid weekday, number out of range: %s", day) } if weekday, ok := dayStrings[strings.ToLower(day)]; ok { return weekday, nil - } else { - return time.Sunday, fmt.Errorf("Invalid weekday: %s", day) } + return time.Sunday, fmt.Errorf("Invalid weekday: %s", day) }