From 1822b94d52f895d375655d6f154037c4dda5321d Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Fri, 11 Feb 2022 13:59:00 +0100 Subject: [PATCH] fix gosec/lint issues Signed-off-by: Markus Blaschke --- autopilot/main.go | 5 ++++- autopilot/task.repair.go | 13 ++++++++++--- autopilot/task.update.go | 4 +++- k8s/kubectl.go | 2 +- main.go | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/autopilot/main.go b/autopilot/main.go index 49841aa..a143759 100644 --- a/autopilot/main.go +++ b/autopilot/main.go @@ -425,7 +425,10 @@ func (r *AzureK8sAutopilot) syncNodeLockCache(contextLogger *log.Entry, nodeList // add to lock cache contextLogger.Debugf("found existing lock \"%s\" for node %s, duration: %s", annotationName, node.Name, lockDuration.String()) - cacheLock.Add(node.Name, true, *lockDuration) //nolint:golint,errcheck + // lock vm for next redeploy, can take up to 15 mins + if err := cacheLock.Add(node.Name, true, *lockDuration); err != nil { + contextLogger.Error(err) + } } else { cacheLock.Delete(node.Name) } diff --git a/autopilot/task.repair.go b/autopilot/task.repair.go index 263426d..44e63a1 100644 --- a/autopilot/task.repair.go +++ b/autopilot/task.repair.go @@ -65,7 +65,9 @@ func (r *AzureK8sAutopilot) repairRun(contextLogger *log.Entry) { if r.DryRun { nodeContextLogger.Infof("node %s repair skipped, dry run", node.Name) - r.repair.nodeLock.Add(node.Name, true, r.Config.Repair.LockDuration) //nolint:golint,errcheck + if err := r.repair.nodeLock.Add(node.Name, true, r.Config.Repair.LockDuration); err != nil { + nodeContextLogger.Error(err) + } continue } @@ -88,14 +90,19 @@ func (r *AzureK8sAutopilot) repairRun(contextLogger *log.Entry) { if err != nil { r.prometheus.general.errors.WithLabelValues("azure").Inc() nodeContextLogger.Errorf("node %s repair failed: %s", node.Name, err.Error()) - r.repair.nodeLock.Add(node.Name, true, r.Config.Repair.LockDurationError) //nolint:golint,errcheck + // lock vm for next redeploy, can take up to 15 mins + if err := r.repair.nodeLock.Add(node.Name, true, r.Config.Repair.LockDurationError); err != nil { + nodeContextLogger.Error(err) + } if k8sErr := node.AnnotationLockSet(r.Config.Repair.NodeLockAnnotation, r.Config.Repair.LockDurationError, r.Config.Autoscaler.ScaledownLockTime); k8sErr != nil { nodeContextLogger.Error(k8sErr) } continue } else { // lock vm for next redeploy, can take up to 15 mins - r.repair.nodeLock.Add(node.Name, true, r.Config.Repair.LockDuration) //nolint:golint,errcheck + if err := r.repair.nodeLock.Add(node.Name, true, r.Config.Repair.LockDuration); err != nil { + nodeContextLogger.Error(err) + } if k8sErr := node.AnnotationLockSet(r.Config.Repair.NodeLockAnnotation, r.Config.Repair.LockDuration, r.Config.Autoscaler.ScaledownLockTime); k8sErr != nil { nodeContextLogger.Error(k8sErr) } diff --git a/autopilot/task.update.go b/autopilot/task.update.go index 2a6af54..9973d60 100644 --- a/autopilot/task.update.go +++ b/autopilot/task.update.go @@ -146,7 +146,9 @@ func (r *AzureK8sAutopilot) updateNode(contextLogger *log.Entry, node *k8s.Node, } func (r *AzureK8sAutopilot) updateNodeLock(contextLogger *log.Entry, node *k8s.Node, dur time.Duration) { - r.update.nodeLock.Add(node.Name, true, dur) //nolint:golint,errcheck + if err := r.update.nodeLock.Add(node.Name, true, dur); err != nil { + contextLogger.Error(err) + } if k8sErr := node.AnnotationLockSet(r.Config.Update.NodeLockAnnotation, dur, r.Config.Autoscaler.ScaledownLockTime); k8sErr != nil { contextLogger.Error(k8sErr) } diff --git a/k8s/kubectl.go b/k8s/kubectl.go index dad3aff..215b253 100644 --- a/k8s/kubectl.go +++ b/k8s/kubectl.go @@ -62,7 +62,7 @@ func (k *Kubectl) exec(args ...string) error { args = append(args, "--dry-run") } - return k.runComand(exec.Command(k.Conf.KubectlPath, args...)) + return k.runComand(exec.Command(k.Conf.KubectlPath, args...)) //#nosec G204 } func (k *Kubectl) runComand(cmd *exec.Cmd) (err error) { diff --git a/main.go b/main.go index 25279ae..98aeb39 100644 --- a/main.go +++ b/main.go @@ -49,7 +49,7 @@ func main() { log.Infof("starting http server on %s", opts.ServerBind) startHttpServer() - termChan := make(chan os.Signal) + termChan := make(chan os.Signal, 1) signal.Notify(termChan, syscall.SIGINT, syscall.SIGTERM) //nolint:staticcheck <-termChan log.Info("shutdown signal received, trying to stop")