Skip to content

Commit

Permalink
address linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
QxBytes committed Feb 13, 2025
1 parent f4bb47a commit 8d70f3f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
18 changes: 5 additions & 13 deletions cns/fakes/iptablesfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ func NewIPTablesMock() *IPTablesMock {
}
}

type iptablesClient interface {
ChainExists(table string, chain string) (bool, error)
NewChain(table string, chain string) error
Exists(table string, chain string, rulespec ...string) (bool, error)
Append(table string, chain string, rulespec ...string) error
Insert(table string, chain string, pos int, rulespec ...string) error
}

func (c *IPTablesMock) ensureTableExists(table string) {
_, exists := c.state[table]
if !exists {
Expand Down Expand Up @@ -69,15 +61,15 @@ func (c *IPTablesMock) NewChain(table, chain string) error {
return nil
}

func (c *IPTablesMock) Exists(table string, chain string, rulespec ...string) (bool, error) {
func (c *IPTablesMock) Exists(table, chain string, rulespec ...string) (bool, error) {
c.ensureTableExists(table)

chainExists, _ := c.ChainExists(table, chain)
if !chainExists {
return false, nil
}

targetRule := strings.Join(rulespec[:], " ")
targetRule := strings.Join(rulespec, " ")
chainRules := c.state[table][chain]

for _, chainRule := range chainRules {
Expand All @@ -88,7 +80,7 @@ func (c *IPTablesMock) Exists(table string, chain string, rulespec ...string) (b
return false, nil
}

func (c *IPTablesMock) Append(table string, chain string, rulespec ...string) error {
func (c *IPTablesMock) Append(table, chain string, rulespec ...string) error {
c.ensureTableExists(table)

chainExists, _ := c.ChainExists(table, chain)
Expand All @@ -101,11 +93,11 @@ func (c *IPTablesMock) Append(table string, chain string, rulespec ...string) er
return errRuleExists
}

targetRule := strings.Join(rulespec[:], " ")
targetRule := strings.Join(rulespec, " ")
c.state[table][chain] = append(c.state[table][chain], targetRule)
return nil
}

func (c *IPTablesMock) Insert(table string, chain string, _ int, rulespec ...string) error {
func (c *IPTablesMock) Insert(table, chain string, _ int, rulespec ...string) error {
return c.Append(table, chain, rulespec...)
}
8 changes: 4 additions & 4 deletions cns/restserver/internalapi_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import (
"github.com/Azure/azure-container-networking/iptables"
"github.com/Azure/azure-container-networking/network/networkutils"
goiptables "github.com/coreos/go-iptables/iptables"
"github.com/pkg/errors"
)

const SWIFT = "SWIFT-POSTROUTING"

type IPtablesProvider struct {
iptc iptablesClient
}
type IPtablesProvider struct{}

func (c *IPtablesProvider) GetIPTables() (iptablesClient, error) {
return goiptables.New()
client, err := goiptables.New()
return client, errors.Wrap(err, "failed to get iptables client")
}

// nolint
Expand Down
2 changes: 1 addition & 1 deletion cns/restserver/internalapi_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var errUnsupportedAPI = errors.New("unsupported api")

type IPtablesProvider struct{}

func (_ *IPtablesProvider) GetIPTables() (iptablesClient, error) {
func (*IPtablesProvider) GetIPTables() (iptablesClient, error) {
return nil, errUnsupportedAPI
}

Expand Down

0 comments on commit 8d70f3f

Please sign in to comment.