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) {
}
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
)
if
err
!=
nil
{
return
nil
,
err
return
err
}
data
:=
bytes
.
NewBuffer
(
nil
)
data
.
WriteString
(
fmt
.
Sprintf
(
"*%s
\n
"
,
table
.
name
))
buffer
.
WriteString
(
fmt
.
Sprintf
(
"*%s
\n
"
,
table
.
name
))
rules
:=
bytes
.
NewBuffer
(
nil
)
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
)
}
data
.
Write
(
rules
.
Bytes
())
data
.
WriteString
(
"COMMIT
\n
"
)
return
data
.
Bytes
(),
nil
buffer
.
Write
(
rules
.
Bytes
())
buffer
.
WriteString
(
"COMMIT
\n
"
)
return
nil
}
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
}}
}
func
(
eic
execInContainer
)
Run
()
error
{
return
fmt
.
Errorf
(
"unimplemented"
)
}
func
(
eic
execInContainer
)
CombinedOutput
()
([]
byte
,
error
)
{
return
eic
.
run
()
}
...
...
@@ -257,6 +261,10 @@ func (eic execInContainer) SetStdout(out io.Writer) {
//unimplemented
}
func
(
eic
execInContainer
)
SetStderr
(
out
io
.
Writer
)
{
//unimplemented
}
func
(
eic
execInContainer
)
Stop
()
{
//unimplemented
}
pkg/probe/exec/exec_test.go
View file @
bcfae7e1
...
...
@@ -30,6 +30,10 @@ type FakeCmd struct {
err
error
}
func
(
f
*
FakeCmd
)
Run
()
error
{
return
nil
}
func
(
f
*
FakeCmd
)
CombinedOutput
()
([]
byte
,
error
)
{
return
f
.
out
,
f
.
err
}
...
...
@@ -44,6 +48,8 @@ func (f *FakeCmd) SetStdin(in io.Reader) {}
func
(
f
*
FakeCmd
)
SetStdout
(
out
io
.
Writer
)
{}
func
(
f
*
FakeCmd
)
SetStderr
(
out
io
.
Writer
)
{}
func
(
f
*
FakeCmd
)
Stop
()
{}
type
fakeExitError
struct
{
...
...
pkg/util/exec/exec.go
View file @
bcfae7e1
...
...
@@ -41,6 +41,8 @@ type Interface interface {
// As more functionality is needed, this can grow. Since Cmd is a struct, we will have
// to replace fields with get/set method pairs.
type
Cmd
interface
{
// Run runs the command to the completion.
Run
()
error
// CombinedOutput runs the command and returns its combined standard output
// and standard error. This follows the pattern of package os/exec.
CombinedOutput
()
([]
byte
,
error
)
...
...
@@ -49,6 +51,7 @@ type Cmd interface {
SetDir
(
dir
string
)
SetStdin
(
in
io
.
Reader
)
SetStdout
(
out
io
.
Writer
)
SetStderr
(
out
io
.
Writer
)
// Stops the command by sending SIGTERM. It is not guaranteed the
// process will stop before this function returns. If the process is not
// responding, an internal timer function will send a SIGKILL to force
...
...
@@ -99,6 +102,15 @@ func (cmd *cmdWrapper) SetStdout(out io.Writer) {
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.
func
(
cmd
*
cmdWrapper
)
CombinedOutput
()
([]
byte
,
error
)
{
out
,
err
:=
(
*
osexec
.
Cmd
)(
cmd
)
.
CombinedOutput
()
...
...
pkg/util/exec/fake_exec.go
View file @
bcfae7e1
...
...
@@ -52,6 +52,7 @@ type FakeCmd struct {
Dirs
[]
string
Stdin
io
.
Reader
Stdout
io
.
Writer
Stderr
io
.
Writer
}
func
InitFakeCmd
(
fake
*
FakeCmd
,
cmd
string
,
args
...
string
)
Cmd
{
...
...
@@ -73,6 +74,14 @@ func (fake *FakeCmd) SetStdout(out io.Writer) {
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
)
{
if
fake
.
CombinedOutputCalls
>
len
(
fake
.
CombinedOutputScript
)
-
1
{
panic
(
"ran out of CombinedOutput() actions"
)
...
...
pkg/util/iptables/iptables.go
View file @
bcfae7e1
...
...
@@ -56,6 +56,8 @@ type Interface interface {
IsIpv6
()
bool
// Save calls `iptables-save` for table.
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.
// table is the Table to restore
// data should be formatted like the output of Save()
...
...
@@ -315,6 +317,20 @@ func (runner *runner) Save(table Table) ([]byte, error) {
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.
func
(
runner
*
runner
)
Restore
(
table
Table
,
data
[]
byte
,
flush
FlushFlag
,
counters
RestoreCountersFlag
)
error
{
// setup args
...
...
pkg/util/iptables/testing/fake.go
View file @
bcfae7e1
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
testing
import
(
"bytes"
"fmt"
"strings"
...
...
@@ -78,6 +79,11 @@ func (f *FakeIPTables) Save(table iptables.Table) ([]byte, error) {
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
{
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