Skip to content

Commit c149095

Browse files
committed
style: fix lints
Signed-off-by: Hunter Gregory <[email protected]>
1 parent b399ec0 commit c149095

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

npm/pkg/dataplane/policies/chain-management_linux.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const (
2626
minLineNumberStringLength int = 3
2727

2828
detectingErrMsg = "failed to detect iptables version. failed to run iptables-legacy-save, run iptables-nft-save, and get kernel version. NPM will crash to retry"
29+
30+
minNftKernelVersion = 5
2931
)
3032

3133
var (
@@ -281,7 +283,7 @@ func (pMgr *PolicyManager) detectIptablesVersion() error {
281283
return errDetectingIptablesVersion
282284
}
283285

284-
if majorVersion >= 5 {
286+
if majorVersion >= minNftKernelVersion {
285287
msg := "detected iptables version on third attempt. found kernel version >= 5. NPM will use iptables-nft. kernel version: %d"
286288
klog.Infof(msg, majorVersion)
287289
metrics.SendLog(util.IptmID, fmt.Sprintf(msg, majorVersion), metrics.DonotPrint)
@@ -304,7 +306,7 @@ func (pMgr *PolicyManager) hintOrCanaryChainExist(iptablesCmd string) bool {
304306
klog.Infof("failed to list hint chain. cmd: %s. error: %s", iptablesCmd, hintErr.Error())
305307
metrics.SendErrorLogAndMetric(util.IptmID, "failed to list hint chain. cmd: %s. error: %s", iptablesCmd, hintErr.Error())
306308
} else {
307-
metrics.SendLog(util.IptmID, fmt.Sprintf("found hint chain. will use iptables version: %s", iptablesCmd), metrics.DonotPrint)
309+
metrics.SendLog(util.IptmID, "found hint chain. will use iptables version: %s"+iptablesCmd, metrics.DonotPrint)
308310
return true
309311
}
310312

@@ -317,7 +319,7 @@ func (pMgr *PolicyManager) hintOrCanaryChainExist(iptablesCmd string) bool {
317319
return false
318320
}
319321

320-
metrics.SendLog(util.IptmID, fmt.Sprintf("found canary chain. will use iptables version: %s", iptablesCmd), metrics.DonotPrint)
322+
metrics.SendLog(util.IptmID, "found canary chain. will use iptables version: "+iptablesCmd, metrics.DonotPrint)
321323
return true
322324
}
323325

@@ -401,9 +403,9 @@ func (pMgr *PolicyManager) cleanupOtherIptables() error {
401403

402404
creator := pMgr.creatorForCleanup(chains)
403405
if err := restore(creator); err != nil {
404-
msg := fmt.Sprintf("[cleanup] failed to flush all chains with error: %s", err.Error())
405-
klog.Info(msg)
406-
metrics.SendErrorLogAndMetric(util.IptmID, msg)
406+
msg := "[cleanup] failed to flush all chains with error: %s"
407+
klog.Infof(msg, err.Error())
408+
metrics.SendErrorLogAndMetric(util.IptmID, msg, err.Error())
407409

408410
// 3.2. if we failed to flush all chains, then try to flush and delete them one by one
409411
var aggregateError error
@@ -432,7 +434,7 @@ func (pMgr *PolicyManager) cleanupOtherIptables() error {
432434
if aggregateError == nil {
433435
aggregateError = npmerrors.SimpleError(currentErrString)
434436
} else {
435-
aggregateError = npmerrors.SimpleErrorWrapper(fmt.Sprintf("%s and had previous error", currentErrString), aggregateError)
437+
aggregateError = npmerrors.SimpleErrorWrapper(currentErrString+" and had previous error", aggregateError)
436438
}
437439
}
438440
}
@@ -455,7 +457,7 @@ func (pMgr *PolicyManager) cleanupOtherIptables() error {
455457
if aggregateError == nil {
456458
aggregateError = npmerrors.SimpleError(currentErrString)
457459
} else {
458-
aggregateError = npmerrors.SimpleErrorWrapper(fmt.Sprintf("%s and had previous error", currentErrString), aggregateError)
460+
aggregateError = npmerrors.SimpleErrorWrapper(currentErrString+" and had previous error", aggregateError)
459461
}
460462
}
461463
}
@@ -473,7 +475,7 @@ func (pMgr *PolicyManager) creatorForCleanup(chains []string) *ioutil.FileCreato
473475
// pass nil because we don't need to add any lines like ":CHAIN-NAME - -" because that is for creating chains
474476
creator := pMgr.newCreatorWithChains(nil)
475477
for _, chain := range chains {
476-
creator.AddLine("", nil, fmt.Sprintf("-F %s", chain))
478+
creator.AddLine("", nil, "-F "+chain)
477479
}
478480
creator.AddLine("", nil, util.IptablesRestoreCommit)
479481
return creator

npm/pkg/dataplane/policies/chain-management_linux_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package policies
22

33
import (
4+
"errors"
45
"fmt"
56
"sort"
67
"strings"
@@ -44,6 +45,8 @@ Chain AZURE-NPM-INGRESS (1 references)
4445
`
4546
)
4647

48+
var errKernelVersion = errors.New("kernel error")
49+
4750
func TestStaleChainsForceLock(t *testing.T) {
4851
testChains := []string{}
4952
for i := 0; i < 100000; i++ {
@@ -1003,7 +1006,7 @@ func TestDetectIptablesVersion(t *testing.T) {
10031006
},
10041007
{
10051008
name: "no kube chains: kernel version error",
1006-
kernelVersionErr: fmt.Errorf("kernel version error"),
1009+
kernelVersionErr: errKernelVersion,
10071010
calls: []testutils.TestCmd{
10081011
{
10091012
Cmd: []string{"iptables-nft", "-w", "60", "-t", "mangle", "-n", "-L", "KUBE-IPTABLES-HINT"},

npm/pkg/dataplane/policies/policymanager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ const (
3030

3131
type PolicyManagerCfg struct {
3232
// debug is only used for testing. Currently just indicating whether to use debug kernel version
33-
debug bool
33+
debug bool //nolint:unused // only used in linux
3434
// debugKernelVersion is only used for testing
35-
debugKernelVersion int
35+
debugKernelVersion int //nolint:unused // only used in linux
3636
// debugKernelVersionErr is only used for testing
37-
debugKernelVersionErr error
37+
debugKernelVersionErr error //nolint:unused // only used in linux
3838

3939
// NodeIP is only used in Windows
4040
NodeIP string

npm/util/sysinfo_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package util
33
// this file has bits copied from github.com/zcalusic/sysinfo (v1.1.2)
44

55
import (
6+
"errors"
67
"fmt"
78
"os"
89
"strconv"
@@ -11,7 +12,7 @@ import (
1112

1213
const kernelReleaseFilepath = "/proc/sys/kernel/osrelease"
1314

14-
var errNoKernelRelease = fmt.Errorf("error finding kernel release")
15+
var errNoKernelRelease = errors.New("error finding kernel release")
1516

1617
func KernelReleaseMajorVersion() (int, error) {
1718
rel, err := slurpFile(kernelReleaseFilepath)

0 commit comments

Comments
 (0)