Skip to content

Commit

Permalink
Added config option for disabling iptable lock (#470)
Browse files Browse the repository at this point in the history
* added config option for disabling iptable lock

* added log for iptable and ebtable version

* moved logging dependency package details to platform specific file
  • Loading branch information
tamilmani1989 authored Jan 4, 2020
1 parent 94759f5 commit 5fb1d7f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions cni/netconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type NetworkConfig struct {
MultiTenancy bool `json:"multiTenancy,omitempty"`
EnableSnatOnHost bool `json:"enableSnatOnHost,omitempty"`
EnableExactMatchForPodName bool `json:"enableExactMatchForPodName,omitempty"`
DisableIPTableLock bool `json:"disableIPTableLock,omitempty"`
CNSUrl string `json:"cnsurl,omitempty"`
Ipam struct {
Type string `json:"type"`
Expand Down
7 changes: 7 additions & 0 deletions cni/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/Azure/azure-container-networking/cns"
"github.com/Azure/azure-container-networking/cns/cnsclient"
"github.com/Azure/azure-container-networking/common"
"github.com/Azure/azure-container-networking/iptables"
"github.com/Azure/azure-container-networking/log"
"github.com/Azure/azure-container-networking/network"
"github.com/Azure/azure-container-networking/platform"
Expand Down Expand Up @@ -106,6 +107,7 @@ func (plugin *netPlugin) Start(config *common.PluginConfig) error {
// Log platform information.
log.Printf("[cni-net] Plugin %v version %v.", plugin.Name, plugin.Version)
log.Printf("[cni-net] Running on %v", platform.GetOSInfo())
platform.PrintDependencyPackageDetails()
common.LogNetworkInterfaces()

// Initialize network manager.
Expand Down Expand Up @@ -239,6 +241,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
}
}

iptables.DisableIPTableLock = nwCfg.DisableIPTableLock
plugin.setCNIReportDetails(nwCfg, CNI_ADD, "")

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

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

iptables.DisableIPTableLock = nwCfg.DisableIPTableLock

// Parse Pod arguments.
if k8sPodName, k8sNamespace, err = plugin.getPodInfo(args.Args); err != nil {
return err
Expand Down Expand Up @@ -665,6 +670,7 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error {

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

iptables.DisableIPTableLock = nwCfg.DisableIPTableLock
plugin.setCNIReportDetails(nwCfg, CNI_DEL, "")

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

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

iptables.DisableIPTableLock = nwCfg.DisableIPTableLock
plugin.setCNIReportDetails(nwCfg, CNI_UPDATE, "")

defer func() {
Expand Down
13 changes: 12 additions & 1 deletion iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,20 @@ const (
lockTimeout = 60
)

var (
DisableIPTableLock bool
)

// Run iptables command
func runCmd(params string) error {
cmd := fmt.Sprintf("%s -w %d %s", iptables, lockTimeout, params)
var cmd string

if DisableIPTableLock {
cmd = fmt.Sprintf("%s %s", iptables, params)
} else {
cmd = fmt.Sprintf("%s -w %d %s", iptables, lockTimeout, params)
}

if _, err := platform.ExecuteCommand(cmd); err != nil {
return err
}
Expand Down
9 changes: 9 additions & 0 deletions platform/os_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,12 @@ func GetProcessNameByID(pidstr string) (string, error) {

return out, nil
}

func PrintDependencyPackageDetails() {
out, err := ExecuteCommand("iptables --version")
out = strings.TrimSuffix(out, "\n")
log.Printf("[cni-net] iptable version:%s, err:%v", out, err)
out, err = ExecuteCommand("ebtables --version")
out = strings.TrimSuffix(out, "\n")
log.Printf("[cni-net] ebtable version %s, err:%v", out, err)
}
3 changes: 3 additions & 0 deletions platform/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,6 @@ func GetProcessNameByID(pidstr string) (string, error) {

return "", fmt.Errorf("Process not found")
}

func PrintDependencyPackageDetails() {
}

0 comments on commit 5fb1d7f

Please sign in to comment.