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
0f551035
Commit
0f551035
authored
Jun 19, 2015
by
Satnam Singh
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9346 from yifan-gu/cleanup_kubelet_tests
kubelet: clean up tests
parents
c3856508
40e46bbb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
109 additions
and
2 deletions
+109
-2
runtime.go
pkg/kubelet/container/runtime.go
+6
-0
container_gc_test.go
pkg/kubelet/container_gc_test.go
+16
-0
manager.go
pkg/kubelet/dockertools/manager.go
+5
-1
manager_test.go
pkg/kubelet/dockertools/manager_test.go
+79
-1
kubelet.go
pkg/kubelet/kubelet.go
+3
-0
kubelet_test.go
pkg/kubelet/kubelet_test.go
+0
-0
No files found.
pkg/kubelet/container/runtime.go
View file @
0f551035
...
@@ -19,6 +19,7 @@ package container
...
@@ -19,6 +19,7 @@ package container
import
(
import
(
"fmt"
"fmt"
"io"
"io"
"reflect"
"strings"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
...
@@ -282,6 +283,11 @@ func (p *Pod) FindContainerByName(containerName string) *Container {
...
@@ -282,6 +283,11 @@ func (p *Pod) FindContainerByName(containerName string) *Container {
return
nil
return
nil
}
}
// IsEmpty returns true if the pod is empty.
func
(
p
*
Pod
)
IsEmpty
()
bool
{
return
reflect
.
DeepEqual
(
p
,
&
Pod
{})
}
// GetPodFullName returns a name that uniquely identifies a pod.
// GetPodFullName returns a name that uniquely identifies a pod.
func
GetPodFullName
(
pod
*
api
.
Pod
)
string
{
func
GetPodFullName
(
pod
*
api
.
Pod
)
string
{
// Use underscore as the delimiter because it is not allowed in pod name
// Use underscore as the delimiter because it is not allowed in pod name
...
...
pkg/kubelet/container_gc_test.go
View file @
0f551035
...
@@ -18,6 +18,8 @@ package kubelet
...
@@ -18,6 +18,8 @@ package kubelet
import
(
import
(
"fmt"
"fmt"
"reflect"
"sort"
"testing"
"testing"
"time"
"time"
...
@@ -73,6 +75,20 @@ func makeContainerDetailMap(funcs ...func(map[string]*docker.Container)) map[str
...
@@ -73,6 +75,20 @@ func makeContainerDetailMap(funcs ...func(map[string]*docker.Container)) map[str
return
m
return
m
}
}
func
verifyStringArrayEqualsAnyOrder
(
t
*
testing
.
T
,
actual
,
expected
[]
string
)
{
act
:=
make
([]
string
,
len
(
actual
))
exp
:=
make
([]
string
,
len
(
expected
))
copy
(
act
,
actual
)
copy
(
exp
,
expected
)
sort
.
StringSlice
(
act
)
.
Sort
()
sort
.
StringSlice
(
exp
)
.
Sort
()
if
!
reflect
.
DeepEqual
(
exp
,
act
)
{
t
.
Errorf
(
"Expected(sorted): %#v, Actual(sorted): %#v"
,
exp
,
act
)
}
}
func
TestGarbageCollectZeroMaxContainers
(
t
*
testing
.
T
)
{
func
TestGarbageCollectZeroMaxContainers
(
t
*
testing
.
T
)
{
gc
,
fakeDocker
:=
newTestContainerGC
(
t
,
time
.
Minute
,
1
,
0
)
gc
,
fakeDocker
:=
newTestContainerGC
(
t
,
time
.
Minute
,
1
,
0
)
fakeDocker
.
ContainerList
=
[]
docker
.
APIContainers
{
fakeDocker
.
ContainerList
=
[]
docker
.
APIContainers
{
...
...
pkg/kubelet/dockertools/manager.go
View file @
0f551035
...
@@ -1006,6 +1006,10 @@ func (dm *DockerManager) ExecInContainer(containerId string, cmd []string, stdin
...
@@ -1006,6 +1006,10 @@ func (dm *DockerManager) ExecInContainer(containerId string, cmd []string, stdin
return
dm
.
execHandler
.
ExecInContainer
(
dm
.
client
,
container
,
cmd
,
stdin
,
stdout
,
stderr
,
tty
)
return
dm
.
execHandler
.
ExecInContainer
(
dm
.
client
,
container
,
cmd
,
stdin
,
stdout
,
stderr
,
tty
)
}
}
func
noPodInfraContainerError
(
podName
,
podNamespace
string
)
error
{
return
fmt
.
Errorf
(
"cannot find pod infra container in pod %q"
,
kubecontainer
.
BuildPodFullName
(
podName
,
podNamespace
))
}
// PortForward executes socat in the pod's network namespace and copies
// PortForward executes socat in the pod's network namespace and copies
// data between stream (representing the user's local connection on their
// data between stream (representing the user's local connection on their
// computer) and the specified port in the container.
// computer) and the specified port in the container.
...
@@ -1017,7 +1021,7 @@ func (dm *DockerManager) ExecInContainer(containerId string, cmd []string, stdin
...
@@ -1017,7 +1021,7 @@ func (dm *DockerManager) ExecInContainer(containerId string, cmd []string, stdin
func
(
dm
*
DockerManager
)
PortForward
(
pod
*
kubecontainer
.
Pod
,
port
uint16
,
stream
io
.
ReadWriteCloser
)
error
{
func
(
dm
*
DockerManager
)
PortForward
(
pod
*
kubecontainer
.
Pod
,
port
uint16
,
stream
io
.
ReadWriteCloser
)
error
{
podInfraContainer
:=
pod
.
FindContainerByName
(
PodInfraContainerName
)
podInfraContainer
:=
pod
.
FindContainerByName
(
PodInfraContainerName
)
if
podInfraContainer
==
nil
{
if
podInfraContainer
==
nil
{
return
fmt
.
Errorf
(
"cannot find pod infra container in pod %q"
,
kubecontainer
.
BuildPodFullName
(
pod
.
Name
,
pod
.
Namespace
)
)
return
noPodInfraContainerError
(
pod
.
Name
,
pod
.
Namespace
)
}
}
container
,
err
:=
dm
.
client
.
InspectContainer
(
string
(
podInfraContainer
.
ID
))
container
,
err
:=
dm
.
client
.
InspectContainer
(
string
(
podInfraContainer
.
ID
))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/kubelet/dockertools/manager_test.go
View file @
0f551035
...
@@ -19,7 +19,9 @@ package dockertools
...
@@ -19,7 +19,9 @@ package dockertools
import
(
import
(
"errors"
"errors"
"fmt"
"fmt"
"io/ioutil"
"net/http"
"net/http"
"os"
"reflect"
"reflect"
"regexp"
"regexp"
"sort"
"sort"
...
@@ -84,8 +86,19 @@ type fakeOptionGenerator struct{}
...
@@ -84,8 +86,19 @@ type fakeOptionGenerator struct{}
var
_
kubecontainer
.
RunContainerOptionsGenerator
=
&
fakeOptionGenerator
{}
var
_
kubecontainer
.
RunContainerOptionsGenerator
=
&
fakeOptionGenerator
{}
var
testPodContainerDir
string
func
(
*
fakeOptionGenerator
)
GenerateRunContainerOptions
(
pod
*
api
.
Pod
,
container
*
api
.
Container
)
(
*
kubecontainer
.
RunContainerOptions
,
error
)
{
func
(
*
fakeOptionGenerator
)
GenerateRunContainerOptions
(
pod
*
api
.
Pod
,
container
*
api
.
Container
)
(
*
kubecontainer
.
RunContainerOptions
,
error
)
{
return
&
kubecontainer
.
RunContainerOptions
{},
nil
var
opts
kubecontainer
.
RunContainerOptions
var
err
error
if
len
(
container
.
TerminationMessagePath
)
!=
0
{
testPodContainerDir
,
err
=
ioutil
.
TempDir
(
""
,
"fooPodContainerDir"
)
if
err
!=
nil
{
return
nil
,
err
}
opts
.
PodContainerDir
=
testPodContainerDir
}
return
&
opts
,
nil
}
}
func
newTestDockerManagerWithHTTPClient
(
fakeHTTPClient
*
fakeHTTP
)
(
*
DockerManager
,
*
FakeDockerClient
)
{
func
newTestDockerManagerWithHTTPClient
(
fakeHTTPClient
*
fakeHTTP
)
(
*
DockerManager
,
*
FakeDockerClient
)
{
...
@@ -1914,3 +1927,68 @@ func TestSyncPodEventHandlerFails(t *testing.T) {
...
@@ -1914,3 +1927,68 @@ func TestSyncPodEventHandlerFails(t *testing.T) {
t
.
Errorf
(
"Wrong stopped container, expected: bar, get: %q"
,
dockerName
.
ContainerName
)
t
.
Errorf
(
"Wrong stopped container, expected: bar, get: %q"
,
dockerName
.
ContainerName
)
}
}
}
}
func
TestPortForwardNoSuchContainer
(
t
*
testing
.
T
)
{
dm
,
_
:=
newTestDockerManager
()
podName
,
podNamespace
:=
"podName"
,
"podNamespace"
err
:=
dm
.
PortForward
(
&
kubecontainer
.
Pod
{
ID
:
"podID"
,
Name
:
podName
,
Namespace
:
podNamespace
,
Containers
:
nil
,
},
5000
,
nil
,
)
if
err
==
nil
{
t
.
Fatal
(
"unexpected non-error"
)
}
expectedErr
:=
noPodInfraContainerError
(
podName
,
podNamespace
)
if
!
reflect
.
DeepEqual
(
err
,
expectedErr
)
{
t
.
Fatalf
(
"expected %v, but saw %v"
,
expectedErr
,
err
)
}
}
func
TestSyncPodWithTerminationLog
(
t
*
testing
.
T
)
{
dm
,
fakeDocker
:=
newTestDockerManager
()
container
:=
api
.
Container
{
Name
:
"bar"
,
TerminationMessagePath
:
"/dev/somepath"
,
}
fakeDocker
.
ContainerList
=
[]
docker
.
APIContainers
{}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"12345678"
,
Name
:
"foo"
,
Namespace
:
"new"
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
container
,
},
},
}
runSyncPod
(
t
,
dm
,
fakeDocker
,
pod
)
verifyCalls
(
t
,
fakeDocker
,
[]
string
{
// Create pod infra container.
"create"
,
"start"
,
"inspect_container"
,
// Create container.
"create"
,
"start"
,
"inspect_container"
,
})
defer
os
.
Remove
(
testPodContainerDir
)
fakeDocker
.
Lock
()
defer
fakeDocker
.
Unlock
()
parts
:=
strings
.
Split
(
fakeDocker
.
Container
.
HostConfig
.
Binds
[
0
],
":"
)
if
!
matchString
(
t
,
testPodContainerDir
+
"/k8s_bar
\\
.[a-f0-9]"
,
parts
[
0
])
{
t
.
Errorf
(
"Unexpected host path: %s"
,
parts
[
0
])
}
if
parts
[
1
]
!=
"/dev/somepath"
{
t
.
Errorf
(
"Unexpected container path: %s"
,
parts
[
1
])
}
}
pkg/kubelet/kubelet.go
View file @
0f551035
...
@@ -2235,6 +2235,9 @@ func (kl *Kubelet) PortForward(podFullName string, podUID types.UID, port uint16
...
@@ -2235,6 +2235,9 @@ func (kl *Kubelet) PortForward(podFullName string, podUID types.UID, port uint16
return
err
return
err
}
}
pod
:=
kubecontainer
.
Pods
(
pods
)
.
FindPod
(
podFullName
,
podUID
)
pod
:=
kubecontainer
.
Pods
(
pods
)
.
FindPod
(
podFullName
,
podUID
)
if
pod
.
IsEmpty
()
{
return
fmt
.
Errorf
(
"pod not found (%q)"
,
podFullName
)
}
return
kl
.
runner
.
PortForward
(
&
pod
,
port
,
stream
)
return
kl
.
runner
.
PortForward
(
&
pod
,
port
,
stream
)
}
}
...
...
pkg/kubelet/kubelet_test.go
View file @
0f551035
This diff is collapsed.
Click to expand it.
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