Skip to content

Commit 5fb1d7f

Browse files
Added config option for disabling iptable lock (Azure#470)
* added config option for disabling iptable lock * added log for iptable and ebtable version * moved logging dependency package details to platform specific file
1 parent 94759f5 commit 5fb1d7f

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

cni/netconfig.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type NetworkConfig struct {
5555
MultiTenancy bool `json:"multiTenancy,omitempty"`
5656
EnableSnatOnHost bool `json:"enableSnatOnHost,omitempty"`
5757
EnableExactMatchForPodName bool `json:"enableExactMatchForPodName,omitempty"`
58+
DisableIPTableLock bool `json:"disableIPTableLock,omitempty"`
5859
CNSUrl string `json:"cnsurl,omitempty"`
5960
Ipam struct {
6061
Type string `json:"type"`

cni/network/network.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/Azure/azure-container-networking/cns"
1818
"github.com/Azure/azure-container-networking/cns/cnsclient"
1919
"github.com/Azure/azure-container-networking/common"
20+
"github.com/Azure/azure-container-networking/iptables"
2021
"github.com/Azure/azure-container-networking/log"
2122
"github.com/Azure/azure-container-networking/network"
2223
"github.com/Azure/azure-container-networking/platform"
@@ -106,6 +107,7 @@ func (plugin *netPlugin) Start(config *common.PluginConfig) error {
106107
// Log platform information.
107108
log.Printf("[cni-net] Plugin %v version %v.", plugin.Name, plugin.Version)
108109
log.Printf("[cni-net] Running on %v", platform.GetOSInfo())
110+
platform.PrintDependencyPackageDetails()
109111
common.LogNetworkInterfaces()
110112

111113
// Initialize network manager.
@@ -239,6 +241,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
239241
}
240242
}
241243

244+
iptables.DisableIPTableLock = nwCfg.DisableIPTableLock
242245
plugin.setCNIReportDetails(nwCfg, CNI_ADD, "")
243246

244247
defer func() {
@@ -587,6 +590,8 @@ func (plugin *netPlugin) Get(args *cniSkel.CmdArgs) error {
587590

588591
log.Printf("[cni-net] Read network configuration %+v.", nwCfg)
589592

593+
iptables.DisableIPTableLock = nwCfg.DisableIPTableLock
594+
590595
// Parse Pod arguments.
591596
if k8sPodName, k8sNamespace, err = plugin.getPodInfo(args.Args); err != nil {
592597
return err
@@ -665,6 +670,7 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error {
665670

666671
log.Printf("[cni-net] Read network configuration %+v.", nwCfg)
667672

673+
iptables.DisableIPTableLock = nwCfg.DisableIPTableLock
668674
plugin.setCNIReportDetails(nwCfg, CNI_DEL, "")
669675

670676
// Parse Pod arguments.
@@ -758,6 +764,7 @@ func (plugin *netPlugin) Update(args *cniSkel.CmdArgs) error {
758764

759765
log.Printf("[cni-net] Read network configuration %+v.", nwCfg)
760766

767+
iptables.DisableIPTableLock = nwCfg.DisableIPTableLock
761768
plugin.setCNIReportDetails(nwCfg, CNI_UPDATE, "")
762769

763770
defer func() {

iptables/iptables.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,20 @@ const (
5555
lockTimeout = 60
5656
)
5757

58+
var (
59+
DisableIPTableLock bool
60+
)
61+
5862
// Run iptables command
5963
func runCmd(params string) error {
60-
cmd := fmt.Sprintf("%s -w %d %s", iptables, lockTimeout, params)
64+
var cmd string
65+
66+
if DisableIPTableLock {
67+
cmd = fmt.Sprintf("%s %s", iptables, params)
68+
} else {
69+
cmd = fmt.Sprintf("%s -w %d %s", iptables, lockTimeout, params)
70+
}
71+
6172
if _, err := platform.ExecuteCommand(cmd); err != nil {
6273
return err
6374
}

platform/os_linux.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,12 @@ func GetProcessNameByID(pidstr string) (string, error) {
149149

150150
return out, nil
151151
}
152+
153+
func PrintDependencyPackageDetails() {
154+
out, err := ExecuteCommand("iptables --version")
155+
out = strings.TrimSuffix(out, "\n")
156+
log.Printf("[cni-net] iptable version:%s, err:%v", out, err)
157+
out, err = ExecuteCommand("ebtables --version")
158+
out = strings.TrimSuffix(out, "\n")
159+
log.Printf("[cni-net] ebtable version %s, err:%v", out, err)
160+
}

platform/os_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,6 @@ func GetProcessNameByID(pidstr string) (string, error) {
226226

227227
return "", fmt.Errorf("Process not found")
228228
}
229+
230+
func PrintDependencyPackageDetails() {
231+
}

0 commit comments

Comments
 (0)