Skip to content

Commit

Permalink
lint: fix lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim An <maksiman@microsoft.com>
  • Loading branch information
anmaxvl committed Feb 13, 2025
1 parent 3113a68 commit 2a6673b
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 32 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ jobs:
--timeout=10m
--config=${{ github.workspace }}/.golangci.yml
working-directory: ${{ github.workspace }}/${{ matrix.root }}
only-new-issues: true
env:
GOOS: ${{ matrix.goos }}

Expand Down
7 changes: 3 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ run:
- admin
- functional
- integration
skip-dirs:
# paths are relative to module root
- cri-containerd/test-images

linters:
enable:
Expand All @@ -34,13 +31,15 @@ linters-settings:
# struct order is often for Win32 compat
# also, ignore pointer bytes/GC issues for now until performance becomes an issue
- fieldalignment
check-shadowing: true

stylecheck:
# https://staticcheck.io/docs/checks
checks: ["all"]

issues:
exclude-dirs:
# paths are relative to module root
- cri-containerd/test-images
exclude-rules:
# err is very often shadowed in nested scopes
- linters:
Expand Down
2 changes: 1 addition & 1 deletion hcn/hcnerrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func checkForErrors(methodName string, hr error, resultBuffer *uint16) error {

if errorFound {
returnError := new(hr, methodName, result)
logrus.Debugf(returnError.Error()) // HCN errors logged for debugging.
logrus.Debug(returnError.Error()) // HCN errors logged for debugging.
return returnError
}

Expand Down
2 changes: 1 addition & 1 deletion internal/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (e *Exec) Start() error {
pSec := &windows.SecurityAttributes{Length: uint32(unsafe.Sizeof(zeroSec)), InheritHandle: 1}
tSec := &windows.SecurityAttributes{Length: uint32(unsafe.Sizeof(zeroSec)), InheritHandle: 1}

siEx.ProcThreadAttributeList = attrList.List() //nolint:govet // unusedwrite: ProcThreadAttributeList will be read in syscall
siEx.ProcThreadAttributeList = attrList.List()
siEx.Cb = uint32(unsafe.Sizeof(*siEx))
if e.execConfig.token != 0 {
err = windows.CreateProcessAsUser(
Expand Down
10 changes: 5 additions & 5 deletions internal/guest/gcserr/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ func BaseStackTrace(e error) errors.StackTrace {
cause := e
var tracer StackTracer
for cause != nil {
serr, ok := cause.(StackTracer) //nolint:errorlint
serr, ok := cause.(StackTracer)
if ok {
tracer = serr
}
cerr, ok := cause.(causer) //nolint:errorlint
cerr, ok := cause.(causer)
if !ok {
break
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func (e *wrappingHresultError) StackTrace() errors.StackTrace {
type stackTracer interface {
StackTrace() errors.StackTrace
}
serr, ok := e.Cause().(stackTracer) //nolint:errorlint
serr, ok := e.Cause().(stackTracer)
if !ok {
return nil
}
Expand Down Expand Up @@ -167,11 +167,11 @@ func GetHresult(e error) (Hresult, error) {
}
cause := e
for cause != nil {
herr, ok := cause.(hresulter) //nolint:errorlint
herr, ok := cause.(hresulter)
if ok {
return herr.Hresult(), nil
}
cerr, ok := cause.(causer) //nolint:errorlint
cerr, ok := cause.(causer)
if !ok {
break
}
Expand Down
3 changes: 2 additions & 1 deletion internal/guest/network/netns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package network
import (
"bytes"
"context"
"errors"
"fmt"
"net"
"strings"
Expand Down Expand Up @@ -72,7 +73,7 @@ func unreachableNetlinkRouteAdd(count *int, link netlink.Link, expected []*testR
if err := f(route); err != nil {
return err
}
return fmt.Errorf(unreachableErrStr)
return errors.New(unreachableErrStr)
}
}

Expand Down
9 changes: 4 additions & 5 deletions internal/hcs/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func (process *Process) SystemID() string {
}

func (process *Process) processSignalResult(ctx context.Context, err error) (bool, error) {
switch err { //nolint:errorlint
case nil:
if err == nil {
return true, nil
case ErrVmcomputeOperationInvalidState, ErrComputeSystemDoesNotExist, ErrElementNotFound:
}
if errors.Is(err, ErrVmcomputeOperationInvalidState) || errors.Is(err, ErrComputeSystemDoesNotExist) || errors.Is(err, ErrElementNotFound) {
if !process.stopped() {
// The process should be gone, but we have not received the notification.
// After a second, force unblock the process wait to work around a possible
Expand All @@ -82,9 +82,8 @@ func (process *Process) processSignalResult(ctx context.Context, err error) (boo
}()
}
return false, nil
default:
return false, err
}
return false, nil
}

// Signal signals the process with `options`.
Expand Down
21 changes: 11 additions & 10 deletions internal/hcs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,10 @@ func (computeSystem *System) Shutdown(ctx context.Context) error {

resultJSON, err := vmcompute.HcsShutdownComputeSystem(ctx, computeSystem.handle, "")
events := processHcsResult(ctx, resultJSON)
switch err { //nolint:errorlint
case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVmcomputeOperationPending:
default:
if err != nil &&
!errors.Is(err, ErrVmcomputeAlreadyStopped) &&
!errors.Is(err, ErrComputeSystemDoesNotExist) &&
!errors.Is(err, ErrVmcomputeOperationPending) {
return makeSystemError(computeSystem, operation, err, events)
}
return nil
Expand All @@ -259,9 +260,10 @@ func (computeSystem *System) Terminate(ctx context.Context) error {

resultJSON, err := vmcompute.HcsTerminateComputeSystem(ctx, computeSystem.handle, "")
events := processHcsResult(ctx, resultJSON)
switch err { //nolint:errorlint
case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVmcomputeOperationPending:
default:
if err != nil &&
!errors.Is(err, ErrVmcomputeAlreadyStopped) &&
!errors.Is(err, ErrComputeSystemDoesNotExist) &&
!errors.Is(err, ErrVmcomputeOperationPending) {
return makeSystemError(computeSystem, operation, err, events)
}
return nil
Expand All @@ -279,14 +281,13 @@ func (computeSystem *System) waitBackground() {
span.AddAttributes(trace.StringAttribute("cid", computeSystem.id))

err := waitForNotification(ctx, computeSystem.callbackNumber, hcsNotificationSystemExited, nil)
switch err { //nolint:errorlint
case nil:
if err == nil {
log.G(ctx).Debug("system exited")
case ErrVmcomputeUnexpectedExit:
} else if errors.Is(err, ErrVmcomputeUnexpectedExit) {
log.G(ctx).Debug("unexpected system exit")
computeSystem.exitError = makeSystemError(computeSystem, operation, err, nil)
err = nil
default:
} else {
err = makeSystemError(computeSystem, operation, err, nil)
}
computeSystem.closedWaitOnce.Do(func() {
Expand Down
4 changes: 2 additions & 2 deletions internal/hns/hnsaccelnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func (nnvManagementMacList *HNSNnvManagementMacList) Set() (*HNSNnvManagementMac
func GetNnvManagementMacAddressList() (*HNSNnvManagementMacList, error) {
operation := "Get"
title := "hcsshim::nnvManagementMacList::" + operation
logrus.Debugf(title)
logrus.Debug(title)
return HNSNnvManagementMacRequest("GET", "", "")
}

// Delete ManagementMacAddressList by sending "DELETE" NnvManagementMacRequest to HNS.
func DeleteNnvManagementMacAddressList() (*HNSNnvManagementMacList, error) {
operation := "Delete"
title := "hcsshim::nnvManagementMacList::" + operation
logrus.Debugf(title)
logrus.Debug(title)
return HNSNnvManagementMacRequest("DELETE", "", "")
}
2 changes: 1 addition & 1 deletion internal/regopolicyinterpreter/regopolicyinterpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func (r *RegoPolicyInterpreter) query(rule string, input map[string]interface{})
resultSet, err := query.Eval(ctx)
output := buf.String()

r.logInfo(output)
r.logInfo("%s", output)

return resultSet, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/vmcompute/vmcompute.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func execute(ctx gcontext.Context, timeout time.Duration, f func() error) error
}()
select {
case <-ctx.Done():
if ctx.Err() == gcontext.DeadlineExceeded { //nolint:errorlint
if ctx.Err() == gcontext.DeadlineExceeded {
log.G(ctx).WithField(logfields.Timeout, trueTimeout).
Warning("Syscall did not complete within operation timeout. This may indicate a platform issue. " +
"If it appears to be making no forward progress, obtain the stacks and see if there is a syscall " +
Expand Down

0 comments on commit 2a6673b

Please sign in to comment.