@@ -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
3133var (
@@ -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
0 commit comments