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
517301df
Unverified
Commit
517301df
authored
Feb 13, 2018
by
Shyam Jeedigunta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fake docker-client assigns random IPs to containers
parent
46df8313
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
12 deletions
+20
-12
docker_sandbox_test.go
pkg/kubelet/dockershim/docker_sandbox_test.go
+7
-10
docker_service_test.go
pkg/kubelet/dockershim/docker_service_test.go
+2
-1
fake_client.go
pkg/kubelet/dockershim/libdocker/fake_client.go
+11
-1
No files found.
pkg/kubelet/dockershim/docker_sandbox_test.go
View file @
517301df
...
...
@@ -19,6 +19,7 @@ package dockershim
import
(
"errors"
"fmt"
"math/rand"
"net"
"testing"
"time"
...
...
@@ -96,10 +97,8 @@ func TestSandboxStatus(t *testing.T) {
labels
:=
map
[
string
]
string
{
"label"
:
"foobar1"
}
annotations
:=
map
[
string
]
string
{
"annotation"
:
"abc"
}
config
:=
makeSandboxConfigWithLabelsAndAnnotations
(
"foo"
,
"bar"
,
"1"
,
0
,
labels
,
annotations
)
// TODO: The following variables depend on the internal
// implementation of FakeDockerClient, and should be fixed.
fakeIP
:=
"2.3.4.5"
r
:=
rand
.
New
(
rand
.
NewSource
(
0
))
.
Uint32
()
podIP
:=
fmt
.
Sprintf
(
"10.%d.%d.%d"
,
byte
(
r
>>
16
),
byte
(
r
>>
8
),
byte
(
r
))
state
:=
runtimeapi
.
PodSandboxState_SANDBOX_READY
ct
:=
int64
(
0
)
...
...
@@ -107,7 +106,7 @@ func TestSandboxStatus(t *testing.T) {
State
:
state
,
CreatedAt
:
ct
,
Metadata
:
config
.
Metadata
,
Network
:
&
runtimeapi
.
PodSandboxNetworkStatus
{
Ip
:
fake
IP
},
Network
:
&
runtimeapi
.
PodSandboxNetworkStatus
{
Ip
:
pod
IP
},
Linux
:
&
runtimeapi
.
LinuxPodSandboxStatus
{
Namespaces
:
&
runtimeapi
.
Namespace
{
Options
:
&
runtimeapi
.
NamespaceOption
{
...
...
@@ -160,10 +159,8 @@ func TestSandboxStatus(t *testing.T) {
func
TestSandboxStatusAfterRestart
(
t
*
testing
.
T
)
{
ds
,
_
,
fClock
:=
newTestDockerService
()
config
:=
makeSandboxConfig
(
"foo"
,
"bar"
,
"1"
,
0
)
// TODO: The following variables depend on the internal
// implementation of FakeDockerClient, and should be fixed.
fakeIP
:=
"2.3.4.5"
r
:=
rand
.
New
(
rand
.
NewSource
(
0
))
.
Uint32
()
podIP
:=
fmt
.
Sprintf
(
"10.%d.%d.%d"
,
byte
(
r
>>
16
),
byte
(
r
>>
8
),
byte
(
r
))
state
:=
runtimeapi
.
PodSandboxState_SANDBOX_READY
ct
:=
int64
(
0
)
...
...
@@ -171,7 +168,7 @@ func TestSandboxStatusAfterRestart(t *testing.T) {
State
:
state
,
CreatedAt
:
ct
,
Metadata
:
config
.
Metadata
,
Network
:
&
runtimeapi
.
PodSandboxNetworkStatus
{
Ip
:
fake
IP
},
Network
:
&
runtimeapi
.
PodSandboxNetworkStatus
{
Ip
:
pod
IP
},
Linux
:
&
runtimeapi
.
LinuxPodSandboxStatus
{
Namespaces
:
&
runtimeapi
.
Namespace
{
Options
:
&
runtimeapi
.
NamespaceOption
{
...
...
pkg/kubelet/dockershim/docker_service_test.go
View file @
517301df
...
...
@@ -18,6 +18,7 @@ package dockershim
import
(
"errors"
"math/rand"
"testing"
"time"
...
...
@@ -44,7 +45,7 @@ func newTestNetworkPlugin(t *testing.T) *nettest.MockNetworkPlugin {
func
newTestDockerService
()
(
*
dockerService
,
*
libdocker
.
FakeDockerClient
,
*
clock
.
FakeClock
)
{
fakeClock
:=
clock
.
NewFakeClock
(
time
.
Time
{})
c
:=
libdocker
.
NewFakeDockerClient
()
.
WithClock
(
fakeClock
)
.
WithVersion
(
"1.11.2"
,
"1.23"
)
c
:=
libdocker
.
NewFakeDockerClient
()
.
WithClock
(
fakeClock
)
.
WithVersion
(
"1.11.2"
,
"1.23"
)
.
WithRandSource
(
rand
.
NewSource
(
0
))
pm
:=
network
.
NewPluginManager
(
&
network
.
NoopNetworkPlugin
{})
return
&
dockerService
{
client
:
c
,
...
...
pkg/kubelet/dockershim/libdocker/fake_client.go
View file @
517301df
...
...
@@ -61,6 +61,7 @@ type FakeDockerClient struct {
called
[]
calledDetail
pulled
[]
string
EnableTrace
bool
RandGenerator
*
rand
.
Rand
// Created, Started, Stopped and Removed all contain container docker ID
Created
[]
string
...
...
@@ -99,6 +100,7 @@ func NewFakeDockerClient() *FakeDockerClient {
EnableTrace
:
true
,
ImageInspects
:
make
(
map
[
string
]
*
dockertypes
.
ImageInspect
),
ImageIDsNeedingAuth
:
make
(
map
[
string
]
dockertypes
.
AuthConfig
),
RandGenerator
:
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
())),
}
}
...
...
@@ -123,6 +125,13 @@ func (f *FakeDockerClient) WithTraceDisabled() *FakeDockerClient {
return
f
}
func
(
f
*
FakeDockerClient
)
WithRandSource
(
source
rand
.
Source
)
*
FakeDockerClient
{
f
.
Lock
()
defer
f
.
Unlock
()
f
.
RandGenerator
=
rand
.
New
(
source
)
return
f
}
func
(
f
*
FakeDockerClient
)
appendCalled
(
callDetail
calledDetail
)
{
if
f
.
EnableTrace
{
f
.
called
=
append
(
f
.
called
,
callDetail
)
...
...
@@ -597,7 +606,8 @@ func (f *FakeDockerClient) StartContainer(id string) error {
container
.
State
.
Running
=
true
container
.
State
.
Pid
=
os
.
Getpid
()
container
.
State
.
StartedAt
=
dockerTimestampToString
(
timestamp
)
container
.
NetworkSettings
.
IPAddress
=
"2.3.4.5"
r
:=
f
.
RandGenerator
.
Uint32
()
container
.
NetworkSettings
.
IPAddress
=
fmt
.
Sprintf
(
"10.%d.%d.%d"
,
byte
(
r
>>
16
),
byte
(
r
>>
8
),
byte
(
r
))
f
.
ContainerMap
[
id
]
=
container
f
.
updateContainerStatus
(
id
,
StatusRunningPrefix
)
f
.
normalSleep
(
200
,
50
,
50
)
...
...
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