Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions npm/iptm/iptm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ https://github.com/kubernetes/kubernetes/blob/master/pkg/util/iptables
package iptm

import (
"fmt"
"os"
"os/exec"
"strings"
"syscall"
"time"

Expand All @@ -21,11 +23,13 @@ import (

// IptEntry represents an iptables rule.
type IptEntry struct {
Name string
HashedName string
Chain string
Flag string
Specs []string
Command string
Name string
HashedName string
Chain string
Flag string
LockWaitTimeInSeconds string
Specs []string
}

// IptablesManager stores iptables entries.
Expand Down Expand Up @@ -329,10 +333,15 @@ func (iptMgr *IptablesManager) Delete(entry *IptEntry) error {

// Run execute an iptables command to update iptables.
func (iptMgr *IptablesManager) Run(entry *IptEntry) (int, error) {
cmdName := util.Iptables
cmdArgs := append([]string{util.IptablesWaitFlag, iptMgr.OperationFlag, entry.Chain}, entry.Specs...)
if entry.Command == "" {
entry.Command = util.Iptables
}

waitFlag := fmt.Sprintf("%s %s", util.IptablesWaitFlag, entry.LockWaitTimeInSeconds)
waitFlag = strings.TrimSpace(waitFlag)
cmdArgs := append([]string{waitFlag, iptMgr.OperationFlag, entry.Chain}, entry.Specs...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

append([]string{util.IptablesWaitFlag, entry.LockWaitTimeInSeconds, iptMgr.OperationFlag, entry.Chain}, entry.Specs...)

if you think the line is too long, we can line break too.
This way we don't need to import fmt & strings packages.


cmdOut, err := exec.Command(cmdName, cmdArgs...).Output()
cmdOut, err := exec.Command(entry.Command, cmdArgs...).Output()
log.Printf("%s\n", string(cmdOut))

if msg, failed := err.(*exec.ExitError); failed {
Expand Down
5 changes: 5 additions & 0 deletions npm/util/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
//iptables related constants.
const (
Iptables string = "iptables"
Ip6tables string = "ip6tables"
IptablesSave string = "iptables-save"
IptablesRestore string = "iptables-restore"
IptablesConfigFile string = "/var/log/iptables.conf"
Expand Down Expand Up @@ -47,8 +48,11 @@ const (
IptablesMatchSetFlag string = "--match-set"
IptablesStateFlag string = "state"
IptablesMatchStateFlag string = "--state"
IptablesMultiportFlag string = "multiport"
IptablesMultiDestportFlag string = "--dports"
IptablesRelatedState string = "RELATED"
IptablesEstablishedState string = "ESTABLISHED"
IptablesFilterTable string = "filter"
IptablesAzureChain string = "AZURE-NPM"
IptablesAzureIngressPortChain string = "AZURE-NPM-INGRESS-PORT"
IptablesAzureIngressFromChain string = "AZURE-NPM-INGRESS-FROM"
Expand All @@ -60,6 +64,7 @@ const (
IptablesAzureEgressToPodChain string = "AZURE-NPM-EGRESS-TO-POD"
IptablesAzureTargetSetsChain string = "AZURE-NPM-TARGET-SETS"
IptablesForwardChain string = "FORWARD"
IptablesInputChain string = "INPUT"
)

//ipset related constants.
Expand Down