Skip to content

Commit 1900edf

Browse files
authored
Merge pull request kubernetes#85440 from gkarthiks/master
Fix lint in /pkg/util/iptables
2 parents 300ca89 + b05749c commit 1900edf

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

hack/.golint_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ pkg/ssh
219219
pkg/util/config
220220
pkg/util/ebtables
221221
pkg/util/goroutinemap/exponentialbackoff
222-
pkg/util/iptables
223222
pkg/util/iptables/testing
224223
pkg/util/labels # See previous effort in PR #80685
225224
pkg/util/oom

pkg/util/iptables/iptables.go

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ import (
3333
utiltrace "k8s.io/utils/trace"
3434
)
3535

36+
// RulePosition holds the -I/-A flags for iptable
3637
type RulePosition string
3738

3839
const (
40+
// Prepend is the insert flag for iptable
3941
Prepend RulePosition = "-I"
40-
Append RulePosition = "-A"
42+
// Append is the append flag for iptable
43+
Append RulePosition = "-A"
4144
)
4245

43-
// An injectable interface for running iptables commands. Implementations must be goroutine-safe.
46+
// Interface is an injectable interface for running iptables commands. Implementations must be goroutine-safe.
4447
type Interface interface {
4548
// EnsureChain checks if the specified chain exists and, if not, creates it. If the chain existed, return true.
4649
EnsureChain(table Table, chain Chain) (bool, error)
@@ -83,29 +86,42 @@ type Interface interface {
8386
HasRandomFully() bool
8487
}
8588

89+
// Protocol defines the ip protocol either ipv4 or ipv6
8690
type Protocol byte
8791

8892
const (
93+
// ProtocolIpv4 represents ipv4 protocol in iptables
8994
ProtocolIpv4 Protocol = iota + 1
95+
// ProtocolIpv6 represents ipv6 protocol in iptables
9096
ProtocolIpv6
9197
)
9298

99+
// Table represents different iptable like filter,nat, mangle and raw
93100
type Table string
94101

95102
const (
96-
TableNAT Table = "nat"
103+
// TableNAT represents the built-in nat table
104+
TableNAT Table = "nat"
105+
// TableFilter represents the built-in filter table
97106
TableFilter Table = "filter"
107+
// TableMangle represents the built-in mangle table
98108
TableMangle Table = "mangle"
99109
)
100110

111+
// Chain represents the different rules
101112
type Chain string
102113

103114
const (
115+
// ChainPostrouting used for source NAT in nat table
104116
ChainPostrouting Chain = "POSTROUTING"
105-
ChainPrerouting Chain = "PREROUTING"
106-
ChainOutput Chain = "OUTPUT"
107-
ChainInput Chain = "INPUT"
108-
ChainForward Chain = "FORWARD"
117+
// ChainPrerouting used for DNAT (destination NAT) in nat table
118+
ChainPrerouting Chain = "PREROUTING"
119+
// ChainOutput used for the packets going out from local
120+
ChainOutput Chain = "OUTPUT"
121+
// ChainInput used for incoming packets
122+
ChainInput Chain = "INPUT"
123+
// ChainForward used for the packets for another NIC
124+
ChainForward Chain = "FORWARD"
109125
)
110126

111127
const (
@@ -117,32 +133,49 @@ const (
117133
cmdIP6Tables string = "ip6tables"
118134
)
119135

120-
// Option flag for Restore
136+
// RestoreCountersFlag is an option flag for Restore
121137
type RestoreCountersFlag bool
122138

139+
// RestoreCounters a boolean true constant for the option flag RestoreCountersFlag
123140
const RestoreCounters RestoreCountersFlag = true
141+
142+
// NoRestoreCounters a boolean false constant for the option flag RestoreCountersFlag
124143
const NoRestoreCounters RestoreCountersFlag = false
125144

126-
// Option flag for Flush
145+
// FlushFlag an option flag for Flush
127146
type FlushFlag bool
128147

148+
// FlushTables a boolean true constant for option flag FlushFlag
129149
const FlushTables FlushFlag = true
150+
151+
// NoFlushTables a boolean false constant for option flag FlushFlag
130152
const NoFlushTables FlushFlag = false
131153

154+
// MinCheckVersion minimum version to be checked
132155
// Versions of iptables less than this do not support the -C / --check flag
133156
// (test whether a rule exists).
134157
var MinCheckVersion = utilversion.MustParseGeneric("1.4.11")
135158

159+
// RandomFullyMinVersion is the minimum version from which the --random-fully flag is supported,
160+
// used for port mapping to be fully randomized
136161
var RandomFullyMinVersion = utilversion.MustParseGeneric("1.6.2")
137162

138-
// Minimum iptables versions supporting the -w and -w<seconds> flags
163+
// WaitMinVersion a minimum iptables versions supporting the -w and -w<seconds> flags
139164
var WaitMinVersion = utilversion.MustParseGeneric("1.4.20")
165+
166+
// WaitSecondsMinVersion a minimum iptables versions supporting the wait seconds
140167
var WaitSecondsMinVersion = utilversion.MustParseGeneric("1.4.22")
168+
169+
// WaitRestoreMinVersion a minimum iptables versions supporting the wait restore seconds
141170
var WaitRestoreMinVersion = utilversion.MustParseGeneric("1.6.2")
142171

172+
// WaitString a constant for specifying the wait flag
143173
const WaitString = "-w"
174+
175+
// WaitSecondsValue a constant for specifying the default wait seconds
144176
const WaitSecondsValue = "5"
145177

178+
// LockfilePath16x is the iptables lock file acquired by any process that's making any change in the iptable rule
146179
const LockfilePath16x = "/run/xtables.lock"
147180

148181
// runner implements Interface in terms of exec("iptables").
@@ -706,7 +739,6 @@ const iptablesStatusResourceProblem = 4
706739
func isResourceError(err error) bool {
707740
if ee, isExitError := err.(utilexec.ExitError); isExitError {
708741
return ee.ExitStatus() == iptablesStatusResourceProblem
709-
} else {
710-
return false
711742
}
743+
return false
712744
}

pkg/util/iptables/monitor_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ func (mfc *monitorFakeCmd) CombinedOutput() ([]byte, error) {
130130
case opListChain:
131131
if table.Has(chainName) {
132132
return []byte{}, nil
133-
} else {
134-
return []byte{}, fmt.Errorf("no such chain %q", chainName)
135133
}
134+
return []byte{}, fmt.Errorf("no such chain %q", chainName)
136135
case opDeleteChain:
137136
table.Delete(chainName)
138137
return []byte{}, nil

0 commit comments

Comments
 (0)