Skip to content

Commit

Permalink
fix gosec/lint issues
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
  • Loading branch information
mblaschke committed Feb 11, 2022
1 parent 96c5805 commit 1822b94
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
5 changes: 4 additions & 1 deletion autopilot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 10 additions & 3 deletions autopilot/task.repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion autopilot/task.update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion k8s/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1822b94

Please sign in to comment.