Skip to content

Commit 7070daa

Browse files
committed
align getting iptables legacy with iptables
1 parent 8f842ce commit 7070daa

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

cns/restserver/internalapi_linux.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func (c *IPtablesProvider) GetIPTables() (iptablesClient, error) {
2323
client, err := goiptables.New()
2424
return client, errors.Wrap(err, "failed to get iptables client")
2525
}
26-
func (c *IPtablesProvider) GetIPTablesLegacy() iptablesLegacyClient {
27-
return &iptablesLegacy{}
26+
func (c *IPtablesProvider) GetIPTablesLegacy() (iptablesLegacyClient, error) {
27+
return &iptablesLegacy{}, nil
2828
}
2929

3030
type iptablesLegacy struct{}
@@ -43,8 +43,12 @@ func (service *HTTPRestService) programSNATRules(req *cns.CreateNetworkContainer
4343
// in podsubnet case, ncPrimaryIP is the pod subnet's primary ip
4444
// in vnet scale case, ncPrimaryIP is the node's ip
4545
ncPrimaryIP, _, _ := net.ParseCIDR(req.IPConfiguration.IPSubnet.IPAddress + "/" + fmt.Sprintf("%d", req.IPConfiguration.IPSubnet.PrefixLength))
46-
iptl := service.iptables.GetIPTablesLegacy()
47-
err := iptl.Delete(iptables.Nat, iptables.Postrouting, "-j", SWIFTPOSTROUTING)
46+
47+
iptl, err := service.iptables.GetIPTablesLegacy()
48+
if err != nil {
49+
return types.UnexpectedError, fmt.Sprintf("[Azure CNS] Error. Failed to create iptables legacy interface : %v", err)
50+
}
51+
err = iptl.Delete(iptables.Nat, iptables.Postrouting, "-j", SWIFTPOSTROUTING)
4852
// ignore if command fails
4953
if err == nil {
5054
logger.Printf("[Azure CNS] Deleted legacy jump to SWIFT-POSTROUTING Chain")

cns/restserver/internalapi_linux_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ func (c *FakeIPTablesProvider) GetIPTables() (iptablesClient, error) {
2727
return c.iptables, nil
2828
}
2929

30-
func (c *FakeIPTablesProvider) GetIPTablesLegacy() iptablesLegacyClient {
30+
func (c *FakeIPTablesProvider) GetIPTablesLegacy() (iptablesLegacyClient, error) {
3131
if c.iptablesLegacy == nil {
3232
c.iptablesLegacy = &fakes.IPTablesLegacyMock{}
3333
}
34-
return c.iptablesLegacy
34+
return c.iptablesLegacy, nil
3535
}
3636

3737
func TestAddSNATRules(t *testing.T) {

cns/restserver/restserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type iptablesLegacyClient interface {
7070

7171
type iptablesGetter interface {
7272
GetIPTables() (iptablesClient, error)
73-
GetIPTablesLegacy() iptablesLegacyClient
73+
GetIPTablesLegacy() (iptablesLegacyClient, error)
7474
}
7575

7676
// HTTPRestService represents http listener for CNS - Container Networking Service.

0 commit comments

Comments
 (0)