Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
34ce573e
Commit
34ce573e
authored
Mar 09, 2018
by
Dan Winship
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix use of "-w" flag to iptables-restore
iptables accepts "-w5" but iptables-restore requires "-w 5"
parent
8d02b2b3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
22 deletions
+20
-22
iptables.go
pkg/util/iptables/iptables.go
+3
-3
iptables_test.go
pkg/util/iptables/iptables_test.go
+17
-19
No files found.
pkg/util/iptables/iptables.go
View file @
34ce573e
...
@@ -124,7 +124,7 @@ const MinCheckVersion = "1.4.11"
...
@@ -124,7 +124,7 @@ const MinCheckVersion = "1.4.11"
const
WaitMinVersion
=
"1.4.20"
const
WaitMinVersion
=
"1.4.20"
const
WaitSecondsMinVersion
=
"1.4.22"
const
WaitSecondsMinVersion
=
"1.4.22"
const
WaitString
=
"-w"
const
WaitString
=
"-w"
const
WaitSeconds
String
=
"-w
5"
const
WaitSeconds
Value
=
"
5"
const
LockfilePath16x
=
"/run/xtables.lock"
const
LockfilePath16x
=
"/run/xtables.lock"
...
@@ -558,7 +558,7 @@ func getIPTablesWaitFlag(vstring string) []string {
...
@@ -558,7 +558,7 @@ func getIPTablesWaitFlag(vstring string) []string {
if
version
.
LessThan
(
minVersion
)
{
if
version
.
LessThan
(
minVersion
)
{
return
[]
string
{
WaitString
}
return
[]
string
{
WaitString
}
}
else
{
}
else
{
return
[]
string
{
WaitS
econdsString
}
return
[]
string
{
WaitS
tring
,
WaitSecondsValue
}
}
}
}
}
...
@@ -594,7 +594,7 @@ func getIPTablesRestoreWaitFlag(exec utilexec.Interface, protocol Protocol) []st
...
@@ -594,7 +594,7 @@ func getIPTablesRestoreWaitFlag(exec utilexec.Interface, protocol Protocol) []st
return
nil
return
nil
}
}
return
[]
string
{
WaitS
econdsString
}
return
[]
string
{
WaitS
tring
,
WaitSecondsValue
}
}
}
// getIPTablesRestoreVersionString runs "iptables-restore --version" to get the version string
// getIPTablesRestoreVersionString runs "iptables-restore --version" to get the version string
...
...
pkg/util/iptables/iptables_test.go
View file @
34ce573e
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"fmt"
"fmt"
"net"
"net"
"os"
"os"
"reflect"
"strings"
"strings"
"testing"
"testing"
"time"
"time"
...
@@ -681,21 +682,21 @@ COMMIT
...
@@ -681,21 +682,21 @@ COMMIT
func
TestIPTablesWaitFlag
(
t
*
testing
.
T
)
{
func
TestIPTablesWaitFlag
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
Version
string
Version
string
Result
string
Result
[]
string
}{
}{
{
"0.55.55"
,
""
},
{
"0.55.55"
,
nil
},
{
"1.0.55"
,
""
},
{
"1.0.55"
,
nil
},
{
"1.4.19"
,
""
},
{
"1.4.19"
,
nil
},
{
"1.4.20"
,
WaitString
},
{
"1.4.20"
,
[]
string
{
WaitString
}
},
{
"1.4.21"
,
WaitString
},
{
"1.4.21"
,
[]
string
{
WaitString
}
},
{
"1.4.22"
,
WaitSecondsString
},
{
"1.4.22"
,
[]
string
{
WaitString
,
WaitSecondsValue
}
},
{
"1.5.0"
,
WaitSecondsString
},
{
"1.5.0"
,
[]
string
{
WaitString
,
WaitSecondsValue
}
},
{
"2.0.0"
,
WaitSecondsString
},
{
"2.0.0"
,
[]
string
{
WaitString
,
WaitSecondsValue
}
},
}
}
for
_
,
testCase
:=
range
testCases
{
for
_
,
testCase
:=
range
testCases
{
result
:=
getIPTablesWaitFlag
(
testCase
.
Version
)
result
:=
getIPTablesWaitFlag
(
testCase
.
Version
)
if
strings
.
Join
(
result
,
""
)
!=
testCase
.
Result
{
if
!
reflect
.
DeepEqual
(
result
,
testCase
.
Result
)
{
t
.
Errorf
(
"For %s expected %v got %v"
,
testCase
.
Version
,
testCase
.
Result
,
result
)
t
.
Errorf
(
"For %s expected %v got %v"
,
testCase
.
Version
,
testCase
.
Result
,
result
)
}
}
}
}
...
@@ -730,7 +731,7 @@ func TestWaitFlagUnavailable(t *testing.T) {
...
@@ -730,7 +731,7 @@ func TestWaitFlagUnavailable(t *testing.T) {
if
fcmd
.
CombinedOutputCalls
!=
3
{
if
fcmd
.
CombinedOutputCalls
!=
3
{
t
.
Errorf
(
"expected 3 CombinedOutput() calls, got %d"
,
fcmd
.
CombinedOutputCalls
)
t
.
Errorf
(
"expected 3 CombinedOutput() calls, got %d"
,
fcmd
.
CombinedOutputCalls
)
}
}
if
sets
.
NewString
(
fcmd
.
CombinedOutputLog
[
2
]
...
)
.
Has
Any
(
WaitString
,
WaitSeconds
String
)
{
if
sets
.
NewString
(
fcmd
.
CombinedOutputLog
[
2
]
...
)
.
Has
(
Wait
String
)
{
t
.
Errorf
(
"wrong CombinedOutput() log, got %s"
,
fcmd
.
CombinedOutputLog
[
2
])
t
.
Errorf
(
"wrong CombinedOutput() log, got %s"
,
fcmd
.
CombinedOutputLog
[
2
])
}
}
}
}
...
@@ -765,7 +766,7 @@ func TestWaitFlagOld(t *testing.T) {
...
@@ -765,7 +766,7 @@ func TestWaitFlagOld(t *testing.T) {
if
!
sets
.
NewString
(
fcmd
.
CombinedOutputLog
[
2
]
...
)
.
HasAll
(
"iptables"
,
WaitString
)
{
if
!
sets
.
NewString
(
fcmd
.
CombinedOutputLog
[
2
]
...
)
.
HasAll
(
"iptables"
,
WaitString
)
{
t
.
Errorf
(
"wrong CombinedOutput() log, got %s"
,
fcmd
.
CombinedOutputLog
[
2
])
t
.
Errorf
(
"wrong CombinedOutput() log, got %s"
,
fcmd
.
CombinedOutputLog
[
2
])
}
}
if
sets
.
NewString
(
fcmd
.
CombinedOutputLog
[
2
]
...
)
.
Has
Any
(
WaitSecondsString
)
{
if
sets
.
NewString
(
fcmd
.
CombinedOutputLog
[
2
]
...
)
.
Has
(
WaitSecondsValue
)
{
t
.
Errorf
(
"wrong CombinedOutput() log, got %s"
,
fcmd
.
CombinedOutputLog
[
2
])
t
.
Errorf
(
"wrong CombinedOutput() log, got %s"
,
fcmd
.
CombinedOutputLog
[
2
])
}
}
}
}
...
@@ -797,10 +798,7 @@ func TestWaitFlagNew(t *testing.T) {
...
@@ -797,10 +798,7 @@ func TestWaitFlagNew(t *testing.T) {
if
fcmd
.
CombinedOutputCalls
!=
3
{
if
fcmd
.
CombinedOutputCalls
!=
3
{
t
.
Errorf
(
"expected 3 CombinedOutput() calls, got %d"
,
fcmd
.
CombinedOutputCalls
)
t
.
Errorf
(
"expected 3 CombinedOutput() calls, got %d"
,
fcmd
.
CombinedOutputCalls
)
}
}
if
!
sets
.
NewString
(
fcmd
.
CombinedOutputLog
[
2
]
...
)
.
HasAll
(
"iptables"
,
WaitSecondsString
)
{
if
!
sets
.
NewString
(
fcmd
.
CombinedOutputLog
[
2
]
...
)
.
HasAll
(
"iptables"
,
WaitString
,
WaitSecondsValue
)
{
t
.
Errorf
(
"wrong CombinedOutput() log, got %s"
,
fcmd
.
CombinedOutputLog
[
2
])
}
if
sets
.
NewString
(
fcmd
.
CombinedOutputLog
[
2
]
...
)
.
HasAny
(
WaitString
)
{
t
.
Errorf
(
"wrong CombinedOutput() log, got %s"
,
fcmd
.
CombinedOutputLog
[
2
])
t
.
Errorf
(
"wrong CombinedOutput() log, got %s"
,
fcmd
.
CombinedOutputLog
[
2
])
}
}
}
}
...
@@ -1165,7 +1163,7 @@ func TestRestoreAllWait(t *testing.T) {
...
@@ -1165,7 +1163,7 @@ func TestRestoreAllWait(t *testing.T) {
}
}
commandSet
:=
sets
.
NewString
(
fcmd
.
CombinedOutputLog
[
2
]
...
)
commandSet
:=
sets
.
NewString
(
fcmd
.
CombinedOutputLog
[
2
]
...
)
if
!
commandSet
.
HasAll
(
"iptables-restore"
,
WaitS
econdsString
,
"--counters"
,
"--noflush"
)
{
if
!
commandSet
.
HasAll
(
"iptables-restore"
,
WaitS
tring
,
WaitSecondsValue
,
"--counters"
,
"--noflush"
)
{
t
.
Errorf
(
"wrong CombinedOutput() log, got %s"
,
fcmd
.
CombinedOutputLog
[
2
])
t
.
Errorf
(
"wrong CombinedOutput() log, got %s"
,
fcmd
.
CombinedOutputLog
[
2
])
}
}
...
@@ -1214,8 +1212,8 @@ func TestRestoreAllWaitOldIptablesRestore(t *testing.T) {
...
@@ -1214,8 +1212,8 @@ func TestRestoreAllWaitOldIptablesRestore(t *testing.T) {
if
!
commandSet
.
HasAll
(
"iptables-restore"
,
"--counters"
,
"--noflush"
)
{
if
!
commandSet
.
HasAll
(
"iptables-restore"
,
"--counters"
,
"--noflush"
)
{
t
.
Errorf
(
"wrong CombinedOutput() log, got %s"
,
fcmd
.
CombinedOutputLog
[
2
])
t
.
Errorf
(
"wrong CombinedOutput() log, got %s"
,
fcmd
.
CombinedOutputLog
[
2
])
}
}
if
commandSet
.
HasA
ny
(
WaitSecondsString
)
{
if
commandSet
.
HasA
ll
(
WaitString
,
WaitSecondsValue
)
{
t
.
Errorf
(
"wrong CombinedOutput() log (unexpected %s option), got %s"
,
WaitS
econdsS
tring
,
fcmd
.
CombinedOutputLog
[
2
])
t
.
Errorf
(
"wrong CombinedOutput() log (unexpected %s option), got %s"
,
WaitString
,
fcmd
.
CombinedOutputLog
[
2
])
}
}
if
fcmd
.
CombinedOutputCalls
!=
3
{
if
fcmd
.
CombinedOutputCalls
!=
3
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment