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
bcfae7e1
Commit
bcfae7e1
authored
May 18, 2017
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend Iptables interface with SaveInto
parent
028ac803
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
69 additions
and
7 deletions
+69
-7
fake_iptables.go
pkg/kubelet/network/hostport/fake_iptables.go
+12
-7
prober.go
pkg/kubelet/prober/prober.go
+8
-0
exec_test.go
pkg/probe/exec/exec_test.go
+6
-0
exec.go
pkg/util/exec/exec.go
+12
-0
fake_exec.go
pkg/util/exec/fake_exec.go
+9
-0
iptables.go
pkg/util/iptables/iptables.go
+16
-0
fake.go
pkg/util/iptables/testing/fake.go
+6
-0
No files found.
pkg/kubelet/network/hostport/fake_iptables.go
View file @
bcfae7e1
...
@@ -228,22 +228,27 @@ func saveChain(chain *fakeChain, data *bytes.Buffer) {
...
@@ -228,22 +228,27 @@ func saveChain(chain *fakeChain, data *bytes.Buffer) {
}
}
func
(
f
*
fakeIPTables
)
Save
(
tableName
utiliptables
.
Table
)
([]
byte
,
error
)
{
func
(
f
*
fakeIPTables
)
Save
(
tableName
utiliptables
.
Table
)
([]
byte
,
error
)
{
data
:=
bytes
.
NewBuffer
(
nil
)
err
:=
f
.
SaveInto
(
tableName
,
data
)
return
data
.
Bytes
(),
err
}
func
(
f
*
fakeIPTables
)
SaveInto
(
tableName
utiliptables
.
Table
,
buffer
*
bytes
.
Buffer
)
error
{
table
,
err
:=
f
.
getTable
(
tableName
)
table
,
err
:=
f
.
getTable
(
tableName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
err
}
}
data
:=
bytes
.
NewBuffer
(
nil
)
buffer
.
WriteString
(
fmt
.
Sprintf
(
"*%s
\n
"
,
table
.
name
))
data
.
WriteString
(
fmt
.
Sprintf
(
"*%s
\n
"
,
table
.
name
))
rules
:=
bytes
.
NewBuffer
(
nil
)
rules
:=
bytes
.
NewBuffer
(
nil
)
for
_
,
chain
:=
range
table
.
chains
{
for
_
,
chain
:=
range
table
.
chains
{
data
.
WriteString
(
fmt
.
Sprintf
(
":%s - [0:0]
\n
"
,
string
(
chain
.
name
)))
buffer
.
WriteString
(
fmt
.
Sprintf
(
":%s - [0:0]
\n
"
,
string
(
chain
.
name
)))
saveChain
(
chain
,
rules
)
saveChain
(
chain
,
rules
)
}
}
data
.
Write
(
rules
.
Bytes
())
buffer
.
Write
(
rules
.
Bytes
())
data
.
WriteString
(
"COMMIT
\n
"
)
buffer
.
WriteString
(
"COMMIT
\n
"
)
return
data
.
Bytes
(),
nil
return
nil
}
}
func
(
f
*
fakeIPTables
)
restore
(
restoreTableName
utiliptables
.
Table
,
data
[]
byte
,
flush
utiliptables
.
FlushFlag
)
error
{
func
(
f
*
fakeIPTables
)
restore
(
restoreTableName
utiliptables
.
Table
,
data
[]
byte
,
flush
utiliptables
.
FlushFlag
)
error
{
...
...
pkg/kubelet/prober/prober.go
View file @
bcfae7e1
...
@@ -237,6 +237,10 @@ func (pb *prober) newExecInContainer(container v1.Container, containerID kubecon
...
@@ -237,6 +237,10 @@ func (pb *prober) newExecInContainer(container v1.Container, containerID kubecon
}}
}}
}
}
func
(
eic
execInContainer
)
Run
()
error
{
return
fmt
.
Errorf
(
"unimplemented"
)
}
func
(
eic
execInContainer
)
CombinedOutput
()
([]
byte
,
error
)
{
func
(
eic
execInContainer
)
CombinedOutput
()
([]
byte
,
error
)
{
return
eic
.
run
()
return
eic
.
run
()
}
}
...
@@ -257,6 +261,10 @@ func (eic execInContainer) SetStdout(out io.Writer) {
...
@@ -257,6 +261,10 @@ func (eic execInContainer) SetStdout(out io.Writer) {
//unimplemented
//unimplemented
}
}
func
(
eic
execInContainer
)
SetStderr
(
out
io
.
Writer
)
{
//unimplemented
}
func
(
eic
execInContainer
)
Stop
()
{
func
(
eic
execInContainer
)
Stop
()
{
//unimplemented
//unimplemented
}
}
pkg/probe/exec/exec_test.go
View file @
bcfae7e1
...
@@ -30,6 +30,10 @@ type FakeCmd struct {
...
@@ -30,6 +30,10 @@ type FakeCmd struct {
err
error
err
error
}
}
func
(
f
*
FakeCmd
)
Run
()
error
{
return
nil
}
func
(
f
*
FakeCmd
)
CombinedOutput
()
([]
byte
,
error
)
{
func
(
f
*
FakeCmd
)
CombinedOutput
()
([]
byte
,
error
)
{
return
f
.
out
,
f
.
err
return
f
.
out
,
f
.
err
}
}
...
@@ -44,6 +48,8 @@ func (f *FakeCmd) SetStdin(in io.Reader) {}
...
@@ -44,6 +48,8 @@ func (f *FakeCmd) SetStdin(in io.Reader) {}
func
(
f
*
FakeCmd
)
SetStdout
(
out
io
.
Writer
)
{}
func
(
f
*
FakeCmd
)
SetStdout
(
out
io
.
Writer
)
{}
func
(
f
*
FakeCmd
)
SetStderr
(
out
io
.
Writer
)
{}
func
(
f
*
FakeCmd
)
Stop
()
{}
func
(
f
*
FakeCmd
)
Stop
()
{}
type
fakeExitError
struct
{
type
fakeExitError
struct
{
...
...
pkg/util/exec/exec.go
View file @
bcfae7e1
...
@@ -41,6 +41,8 @@ type Interface interface {
...
@@ -41,6 +41,8 @@ type Interface interface {
// As more functionality is needed, this can grow. Since Cmd is a struct, we will have
// As more functionality is needed, this can grow. Since Cmd is a struct, we will have
// to replace fields with get/set method pairs.
// to replace fields with get/set method pairs.
type
Cmd
interface
{
type
Cmd
interface
{
// Run runs the command to the completion.
Run
()
error
// CombinedOutput runs the command and returns its combined standard output
// CombinedOutput runs the command and returns its combined standard output
// and standard error. This follows the pattern of package os/exec.
// and standard error. This follows the pattern of package os/exec.
CombinedOutput
()
([]
byte
,
error
)
CombinedOutput
()
([]
byte
,
error
)
...
@@ -49,6 +51,7 @@ type Cmd interface {
...
@@ -49,6 +51,7 @@ type Cmd interface {
SetDir
(
dir
string
)
SetDir
(
dir
string
)
SetStdin
(
in
io
.
Reader
)
SetStdin
(
in
io
.
Reader
)
SetStdout
(
out
io
.
Writer
)
SetStdout
(
out
io
.
Writer
)
SetStderr
(
out
io
.
Writer
)
// Stops the command by sending SIGTERM. It is not guaranteed the
// Stops the command by sending SIGTERM. It is not guaranteed the
// process will stop before this function returns. If the process is not
// process will stop before this function returns. If the process is not
// responding, an internal timer function will send a SIGKILL to force
// responding, an internal timer function will send a SIGKILL to force
...
@@ -99,6 +102,15 @@ func (cmd *cmdWrapper) SetStdout(out io.Writer) {
...
@@ -99,6 +102,15 @@ func (cmd *cmdWrapper) SetStdout(out io.Writer) {
cmd
.
Stdout
=
out
cmd
.
Stdout
=
out
}
}
func
(
cmd
*
cmdWrapper
)
SetStderr
(
out
io
.
Writer
)
{
cmd
.
Stderr
=
out
}
// Run is part of the Cmd interface.
func
(
cmd
*
cmdWrapper
)
Run
()
error
{
return
(
*
osexec
.
Cmd
)(
cmd
)
.
Run
()
}
// CombinedOutput is part of the Cmd interface.
// CombinedOutput is part of the Cmd interface.
func
(
cmd
*
cmdWrapper
)
CombinedOutput
()
([]
byte
,
error
)
{
func
(
cmd
*
cmdWrapper
)
CombinedOutput
()
([]
byte
,
error
)
{
out
,
err
:=
(
*
osexec
.
Cmd
)(
cmd
)
.
CombinedOutput
()
out
,
err
:=
(
*
osexec
.
Cmd
)(
cmd
)
.
CombinedOutput
()
...
...
pkg/util/exec/fake_exec.go
View file @
bcfae7e1
...
@@ -52,6 +52,7 @@ type FakeCmd struct {
...
@@ -52,6 +52,7 @@ type FakeCmd struct {
Dirs
[]
string
Dirs
[]
string
Stdin
io
.
Reader
Stdin
io
.
Reader
Stdout
io
.
Writer
Stdout
io
.
Writer
Stderr
io
.
Writer
}
}
func
InitFakeCmd
(
fake
*
FakeCmd
,
cmd
string
,
args
...
string
)
Cmd
{
func
InitFakeCmd
(
fake
*
FakeCmd
,
cmd
string
,
args
...
string
)
Cmd
{
...
@@ -73,6 +74,14 @@ func (fake *FakeCmd) SetStdout(out io.Writer) {
...
@@ -73,6 +74,14 @@ func (fake *FakeCmd) SetStdout(out io.Writer) {
fake
.
Stdout
=
out
fake
.
Stdout
=
out
}
}
func
(
fake
*
FakeCmd
)
SetStderr
(
out
io
.
Writer
)
{
fake
.
Stderr
=
out
}
func
(
fake
*
FakeCmd
)
Run
()
error
{
return
fmt
.
Errorf
(
"unimplemented"
)
}
func
(
fake
*
FakeCmd
)
CombinedOutput
()
([]
byte
,
error
)
{
func
(
fake
*
FakeCmd
)
CombinedOutput
()
([]
byte
,
error
)
{
if
fake
.
CombinedOutputCalls
>
len
(
fake
.
CombinedOutputScript
)
-
1
{
if
fake
.
CombinedOutputCalls
>
len
(
fake
.
CombinedOutputScript
)
-
1
{
panic
(
"ran out of CombinedOutput() actions"
)
panic
(
"ran out of CombinedOutput() actions"
)
...
...
pkg/util/iptables/iptables.go
View file @
bcfae7e1
...
@@ -56,6 +56,8 @@ type Interface interface {
...
@@ -56,6 +56,8 @@ type Interface interface {
IsIpv6
()
bool
IsIpv6
()
bool
// Save calls `iptables-save` for table.
// Save calls `iptables-save` for table.
Save
(
table
Table
)
([]
byte
,
error
)
Save
(
table
Table
)
([]
byte
,
error
)
// SaveInto calls `iptables-save` for table and stores result in a given buffer.
SaveInto
(
table
Table
,
buffer
*
bytes
.
Buffer
)
error
// Restore runs `iptables-restore` passing data through []byte.
// Restore runs `iptables-restore` passing data through []byte.
// table is the Table to restore
// table is the Table to restore
// data should be formatted like the output of Save()
// data should be formatted like the output of Save()
...
@@ -315,6 +317,20 @@ func (runner *runner) Save(table Table) ([]byte, error) {
...
@@ -315,6 +317,20 @@ func (runner *runner) Save(table Table) ([]byte, error) {
return
runner
.
exec
.
Command
(
cmdIPTablesSave
,
args
...
)
.
CombinedOutput
()
return
runner
.
exec
.
Command
(
cmdIPTablesSave
,
args
...
)
.
CombinedOutput
()
}
}
// SaveInto is part of Interface.
func
(
runner
*
runner
)
SaveInto
(
table
Table
,
buffer
*
bytes
.
Buffer
)
error
{
runner
.
mu
.
Lock
()
defer
runner
.
mu
.
Unlock
()
// run and return
args
:=
[]
string
{
"-t"
,
string
(
table
)}
glog
.
V
(
4
)
.
Infof
(
"running iptables-save %v"
,
args
)
cmd
:=
runner
.
exec
.
Command
(
cmdIPTablesSave
,
args
...
)
cmd
.
SetStdout
(
buffer
)
cmd
.
SetStderr
(
buffer
)
return
cmd
.
Run
()
}
// Restore is part of Interface.
// Restore is part of Interface.
func
(
runner
*
runner
)
Restore
(
table
Table
,
data
[]
byte
,
flush
FlushFlag
,
counters
RestoreCountersFlag
)
error
{
func
(
runner
*
runner
)
Restore
(
table
Table
,
data
[]
byte
,
flush
FlushFlag
,
counters
RestoreCountersFlag
)
error
{
// setup args
// setup args
...
...
pkg/util/iptables/testing/fake.go
View file @
bcfae7e1
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
testing
package
testing
import
(
import
(
"bytes"
"fmt"
"fmt"
"strings"
"strings"
...
@@ -78,6 +79,11 @@ func (f *FakeIPTables) Save(table iptables.Table) ([]byte, error) {
...
@@ -78,6 +79,11 @@ func (f *FakeIPTables) Save(table iptables.Table) ([]byte, error) {
return
lines
,
nil
return
lines
,
nil
}
}
func
(
f
*
FakeIPTables
)
SaveInto
(
table
iptables
.
Table
,
buffer
*
bytes
.
Buffer
)
error
{
buffer
.
Write
(
f
.
Lines
)
return
nil
}
func
(
*
FakeIPTables
)
Restore
(
table
iptables
.
Table
,
data
[]
byte
,
flush
iptables
.
FlushFlag
,
counters
iptables
.
RestoreCountersFlag
)
error
{
func
(
*
FakeIPTables
)
Restore
(
table
iptables
.
Table
,
data
[]
byte
,
flush
iptables
.
FlushFlag
,
counters
iptables
.
RestoreCountersFlag
)
error
{
return
nil
return
nil
}
}
...
...
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