Skip to content

Commit c58b632

Browse files
authored
Merge pull request kubernetes#85562 from gkarthiks/master
golint fixes for /pkg/util/iptables/testing
2 parents 5a51c46 + c38e79e commit c58b632

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

hack/.golint_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ pkg/ssh
217217
pkg/util/config
218218
pkg/util/ebtables
219219
pkg/util/goroutinemap/exponentialbackoff
220-
pkg/util/iptables/testing
221220
pkg/util/labels # See previous effort in PR #80685
222221
pkg/util/oom
223222
pkg/util/procfs

pkg/util/iptables/testing/fake.go

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,80 +26,105 @@ import (
2626
)
2727

2828
const (
29+
// Destination represents the destination address flag
2930
Destination = "-d "
30-
Source = "-s "
31-
DPort = "--dport "
32-
Protocol = "-p "
33-
Jump = "-j "
34-
Reject = "REJECT"
35-
ToDest = "--to-destination "
36-
Recent = "recent "
37-
MatchSet = "--match-set "
38-
SrcType = "--src-type "
39-
Masquerade = "MASQUERADE "
31+
// Source represents the source address flag
32+
Source = "-s "
33+
// DPort represents the destination port flag
34+
DPort = "--dport "
35+
// Protocol represents the protocol flag
36+
Protocol = "-p "
37+
// Jump represents jump flag specifies the jump target
38+
Jump = "-j "
39+
// Reject specifies the reject target
40+
Reject = "REJECT"
41+
// ToDest represents the flag used to specify the destination address in DNAT
42+
ToDest = "--to-destination "
43+
// Recent represents the sub-command recent that allows to dynamically create list of IP address to match against
44+
Recent = "recent "
45+
// MatchSet represents the flag which match packets against the specified set
46+
MatchSet = "--match-set "
47+
// SrcType represents the --src-type flag which matches if the source address is of given type
48+
SrcType = "--src-type "
49+
// Masquerade represents the target that is used in nat table.
50+
Masquerade = "MASQUERADE "
4051
)
4152

53+
// Rule holds a map of rules.
4254
type Rule map[string]string
4355

44-
// no-op implementation of iptables Interface
56+
// FakeIPTables is no-op implementation of iptables Interface.
4557
type FakeIPTables struct {
4658
hasRandomFully bool
4759
Lines []byte
4860
}
4961

62+
// NewFake returns a no-op iptables.Interface
5063
func NewFake() *FakeIPTables {
5164
return &FakeIPTables{}
5265
}
5366

67+
// SetHasRandomFully is part of iptables.Interface
5468
func (f *FakeIPTables) SetHasRandomFully(can bool) *FakeIPTables {
5569
f.hasRandomFully = can
5670
return f
5771
}
5872

73+
// EnsureChain is part of iptables.Interface
5974
func (*FakeIPTables) EnsureChain(table iptables.Table, chain iptables.Chain) (bool, error) {
6075
return true, nil
6176
}
6277

78+
// FlushChain is part of iptables.Interface
6379
func (*FakeIPTables) FlushChain(table iptables.Table, chain iptables.Chain) error {
6480
return nil
6581
}
6682

83+
// DeleteChain is part of iptables.Interface
6784
func (*FakeIPTables) DeleteChain(table iptables.Table, chain iptables.Chain) error {
6885
return nil
6986
}
7087

88+
// EnsureRule is part of iptables.Interface
7189
func (*FakeIPTables) EnsureRule(position iptables.RulePosition, table iptables.Table, chain iptables.Chain, args ...string) (bool, error) {
7290
return true, nil
7391
}
7492

93+
// DeleteRule is part of iptables.Interface
7594
func (*FakeIPTables) DeleteRule(table iptables.Table, chain iptables.Chain, args ...string) error {
7695
return nil
7796
}
7897

98+
// IsIpv6 is part of iptables.Interface
7999
func (*FakeIPTables) IsIpv6() bool {
80100
return false
81101
}
82102

103+
// Save is part of iptables.Interface
83104
func (f *FakeIPTables) Save(table iptables.Table) ([]byte, error) {
84105
lines := make([]byte, len(f.Lines))
85106
copy(lines, f.Lines)
86107
return lines, nil
87108
}
88109

110+
// SaveInto is part of iptables.Interface
89111
func (f *FakeIPTables) SaveInto(table iptables.Table, buffer *bytes.Buffer) error {
90112
buffer.Write(f.Lines)
91113
return nil
92114
}
93115

116+
// Restore is part of iptables.Interface
94117
func (*FakeIPTables) Restore(table iptables.Table, data []byte, flush iptables.FlushFlag, counters iptables.RestoreCountersFlag) error {
95118
return nil
96119
}
97120

121+
// RestoreAll is part of iptables.Interface
98122
func (f *FakeIPTables) RestoreAll(data []byte, flush iptables.FlushFlag, counters iptables.RestoreCountersFlag) error {
99123
f.Lines = data
100124
return nil
101125
}
102126

127+
// Monitor is part of iptables.Interface
103128
func (f *FakeIPTables) Monitor(canary iptables.Chain, tables []iptables.Table, reloadFunc func(), interval time.Duration, stopCh <-chan struct{}) {
104129
}
105130

@@ -111,9 +136,7 @@ func getToken(line, separator string) string {
111136
return ""
112137
}
113138

114-
// GetChain returns a list of rules for the given chain.
115-
// The chain name must match exactly.
116-
// The matching is pretty dumb, don't rely on it for anything but testing.
139+
// GetRules is part of iptables.Interface
117140
func (f *FakeIPTables) GetRules(chainName string) (rules []Rule) {
118141
for _, l := range strings.Split(string(f.Lines), "\n") {
119142
if strings.Contains(l, fmt.Sprintf("-A %v", chainName)) {
@@ -130,6 +153,7 @@ func (f *FakeIPTables) GetRules(chainName string) (rules []Rule) {
130153
return
131154
}
132155

156+
// HasRandomFully is part of iptables.Interface
133157
func (f *FakeIPTables) HasRandomFully() bool {
134158
return f.hasRandomFully
135159
}

0 commit comments

Comments
 (0)