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
8420abee
Commit
8420abee
authored
Apr 14, 2015
by
Dawn Chen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6786 from yifan-gu/cleankube
kubelet: Remove unused docker functions.
parents
4cdb1412
7fedb14c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
144 additions
and
139 deletions
+144
-139
docker.go
pkg/kubelet/dockertools/docker.go
+0
-24
docker_test.go
pkg/kubelet/dockertools/docker_test.go
+144
-104
kubelet.go
pkg/kubelet/kubelet.go
+0
-11
No files found.
pkg/kubelet/dockertools/docker.go
View file @
8420abee
...
...
@@ -409,30 +409,6 @@ func (c DockerContainers) FindPodContainer(podFullName string, uid types.UID, co
return
nil
,
false
,
0
}
// RemoveContainerWithID removes the container with the given containerID.
func
(
c
DockerContainers
)
RemoveContainerWithID
(
containerID
DockerID
)
{
delete
(
c
,
containerID
)
}
// FindContainersByPod returns the containers that belong to the pod.
func
(
c
DockerContainers
)
FindContainersByPod
(
podUID
types
.
UID
,
podFullName
string
)
DockerContainers
{
containers
:=
make
(
DockerContainers
)
for
_
,
dockerContainer
:=
range
c
{
if
len
(
dockerContainer
.
Names
)
==
0
{
continue
}
dockerName
,
_
,
err
:=
ParseDockerName
(
dockerContainer
.
Names
[
0
])
if
err
!=
nil
{
continue
}
if
podUID
==
dockerName
.
PodUID
||
(
podUID
==
""
&&
podFullName
==
dockerName
.
PodFullName
)
{
containers
[
DockerID
(
dockerContainer
.
ID
)]
=
dockerContainer
}
}
return
containers
}
const
containerNamePrefix
=
"k8s"
func
HashContainer
(
container
*
api
.
Container
)
uint64
{
...
...
pkg/kubelet/dockertools/docker_test.go
View file @
8420abee
...
...
@@ -20,11 +20,13 @@ import (
"fmt"
"hash/adler32"
"reflect"
"sort"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
"github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider"
kubecontainer
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
docker
"github.com/fsouza/go-dockerclient"
...
...
@@ -500,145 +502,183 @@ func TestGetRunningContainers(t *testing.T) {
}
}
type
podsByID
[]
*
kubecontainer
.
Pod
func
(
b
podsByID
)
Len
()
int
{
return
len
(
b
)
}
func
(
b
podsByID
)
Swap
(
i
,
j
int
)
{
b
[
i
],
b
[
j
]
=
b
[
j
],
b
[
i
]
}
func
(
b
podsByID
)
Less
(
i
,
j
int
)
bool
{
return
b
[
i
]
.
ID
<
b
[
j
]
.
ID
}
type
containersByID
[]
*
kubecontainer
.
Container
func
(
b
containersByID
)
Len
()
int
{
return
len
(
b
)
}
func
(
b
containersByID
)
Swap
(
i
,
j
int
)
{
b
[
i
],
b
[
j
]
=
b
[
j
],
b
[
i
]
}
func
(
b
containersByID
)
Less
(
i
,
j
int
)
bool
{
return
b
[
i
]
.
ID
<
b
[
j
]
.
ID
}
func
TestFindContainersByPod
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
testContainers
Docker
Containers
inputPodID
types
.
UID
inputPodFullName
string
expected
Containers
DockerContainers
containerList
[]
docker
.
API
Containers
exitedContainerList
[]
docker
.
APIContainers
all
bool
expected
Pods
[]
*
kubecontainer
.
Pod
}{
{
DockerContainers
{
"foobar"
:
&
docker
.
APIContainers
{
ID
:
"foobar"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_1234_42"
},
},
"barbar"
:
&
docker
.
APIContainers
{
ID
:
"barbar"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_1234_42"
},
},
"baz"
:
&
docker
.
APIContainers
{
ID
:
"baz"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_1234_42"
},
},
},
types
.
UID
(
"1234"
),
""
,
DockerContainers
{
"foobar"
:
&
docker
.
APIContainers
{
[]
docker
.
APIContainers
{
{
ID
:
"foobar"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_1234_42"
},
Names
:
[]
string
{
"/k8s_foo
bar.1234
_qux_ns_1234_42"
},
},
"barbar"
:
&
docker
.
APIContainers
{
{
ID
:
"barbar"
,
Names
:
[]
string
{
"/k8s_
foo_qux_ns_1234
_42"
},
Names
:
[]
string
{
"/k8s_
barbar.1234_qux_ns_2343
_42"
},
},
"baz"
:
&
docker
.
APIContainers
{
{
ID
:
"baz"
,
Names
:
[]
string
{
"/k8s_
foo
_qux_ns_1234_42"
},
Names
:
[]
string
{
"/k8s_
baz.1234
_qux_ns_1234_42"
},
},
},
},
{
DockerContainers
{
"foobar"
:
&
docker
.
APIContainers
{
ID
:
"foobar"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_1234_42"
},
[]
docker
.
APIContainers
{
{
ID
:
"barfoo"
,
Names
:
[]
string
{
"/k8s_barfoo.1234_qux_ns_1234_42"
},
},
"barbar"
:
&
docker
.
APIContainers
{
ID
:
"barbar"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_2343_42"
},
},
"baz"
:
&
docker
.
APIContainers
{
ID
:
"baz"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_1234_42"
},
{
ID
:
"bazbaz"
,
Names
:
[]
string
{
"/k8s_bazbaz.1234_qux_ns_5678_42"
},
},
},
types
.
UID
(
"1234"
),
""
,
DockerContainers
{
"foobar"
:
&
docker
.
APIContainers
{
ID
:
"foobar"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_1234_42"
},
false
,
[]
*
kubecontainer
.
Pod
{
{
ID
:
"1234"
,
Name
:
"qux"
,
Namespace
:
"ns"
,
Containers
:
[]
*
kubecontainer
.
Container
{
{
ID
:
"foobar"
,
Name
:
"foobar"
,
Hash
:
0x1234
,
},
{
ID
:
"baz"
,
Name
:
"baz"
,
Hash
:
0x1234
,
},
},
},
"baz"
:
&
docker
.
APIContainers
{
ID
:
"baz"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_1234_42"
},
{
ID
:
"2343"
,
Name
:
"qux"
,
Namespace
:
"ns"
,
Containers
:
[]
*
kubecontainer
.
Container
{
{
ID
:
"barbar"
,
Name
:
"barbar"
,
Hash
:
0x1234
,
},
},
},
},
},
{
Docker
Containers
{
"foobar"
:
&
docker
.
APIContainers
{
[]
docker
.
API
Containers
{
{
ID
:
"foobar"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_1234_42"
},
Names
:
[]
string
{
"/k8s_foo
bar.1234
_qux_ns_1234_42"
},
},
"barbar"
:
&
docker
.
APIContainers
{
{
ID
:
"barbar"
,
Names
:
[]
string
{
"/k8s_
foo
_qux_ns_2343_42"
},
Names
:
[]
string
{
"/k8s_
barbar.1234
_qux_ns_2343_42"
},
},
"baz"
:
&
docker
.
APIContainers
{
{
ID
:
"baz"
,
Names
:
[]
string
{
"/k8s_
foo
_qux_ns_1234_42"
},
Names
:
[]
string
{
"/k8s_
baz.1234
_qux_ns_1234_42"
},
},
},
types
.
UID
(
"5678"
),
""
,
DockerContainers
{},
},
{
DockerContainers
{
"foobar"
:
&
docker
.
APIContainers
{
ID
:
"foobar"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_1234_42"
},
},
"barbar"
:
&
docker
.
APIContainers
{
ID
:
"barbar"
,
Names
:
nil
,
[]
docker
.
APIContainers
{
{
ID
:
"barfoo"
,
Names
:
[]
string
{
"/k8s_barfoo.1234_qux_ns_1234_42"
},
},
"baz"
:
&
docker
.
APIContainers
{
ID
:
"baz"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_5678_42"
},
},
},
types
.
UID
(
"5678"
),
""
,
DockerContainers
{
"baz"
:
&
docker
.
APIContainers
{
ID
:
"baz"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_5678_42"
},
{
ID
:
"bazbaz"
,
Names
:
[]
string
{
"/k8s_bazbaz.1234_qux_ns_5678_42"
},
},
},
},
{
DockerContainers
{
"foobar"
:
&
docker
.
APIContainers
{
ID
:
"foobar"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_1234_42"
},
},
"barbar"
:
&
docker
.
APIContainers
{
ID
:
"barbar"
,
Names
:
[]
string
{
"/k8s_foo_abc_ns_5678_42"
},
true
,
[]
*
kubecontainer
.
Pod
{
{
ID
:
"1234"
,
Name
:
"qux"
,
Namespace
:
"ns"
,
Containers
:
[]
*
kubecontainer
.
Container
{
{
ID
:
"foobar"
,
Name
:
"foobar"
,
Hash
:
0x1234
,
},
{
ID
:
"barfoo"
,
Name
:
"barfoo"
,
Hash
:
0x1234
,
},
{
ID
:
"baz"
,
Name
:
"baz"
,
Hash
:
0x1234
,
},
},
},
"baz"
:
&
docker
.
APIContainers
{
ID
:
"baz"
,
Names
:
[]
string
{
"/k8s_foo_qux_ns_5678_42"
},
{
ID
:
"2343"
,
Name
:
"qux"
,
Namespace
:
"ns"
,
Containers
:
[]
*
kubecontainer
.
Container
{
{
ID
:
"barbar"
,
Name
:
"barbar"
,
Hash
:
0x1234
,
},
},
},
},
""
,
"abc_ns"
,
DockerContainers
{
"barbar"
:
&
docker
.
APIContainers
{
ID
:
"barbar"
,
Names
:
[]
string
{
"/k8s_foo_abc_ns_5678_42"
},
{
ID
:
"5678"
,
Name
:
"qux"
,
Namespace
:
"ns"
,
Containers
:
[]
*
kubecontainer
.
Container
{
{
ID
:
"bazbaz"
,
Name
:
"bazbaz"
,
Hash
:
0x1234
,
},
},
},
},
},
{
[]
docker
.
APIContainers
{},
[]
docker
.
APIContainers
{},
true
,
nil
,
},
}
for
_
,
test
:=
range
tests
{
result
:=
test
.
testContainers
.
FindContainersByPod
(
test
.
inputPodID
,
test
.
inputPodFullName
)
if
!
reflect
.
DeepEqual
(
result
,
test
.
expectedContainers
)
{
t
.
Errorf
(
"expected: %v, saw: %v"
,
test
.
expectedContainers
,
result
)
fakeClient
:=
&
FakeDockerClient
{}
containerManager
:=
NewDockerManager
(
fakeClient
,
&
record
.
FakeRecorder
{},
PodInfraContainerImage
,
0
,
0
)
for
i
,
test
:=
range
tests
{
fakeClient
.
ContainerList
=
test
.
containerList
fakeClient
.
ExitedContainerList
=
test
.
exitedContainerList
result
,
_
:=
containerManager
.
GetPods
(
test
.
all
)
for
i
:=
range
result
{
sort
.
Sort
(
containersByID
(
result
[
i
]
.
Containers
))
}
for
i
:=
range
test
.
expectedPods
{
sort
.
Sort
(
containersByID
(
test
.
expectedPods
[
i
]
.
Containers
))
}
sort
.
Sort
(
podsByID
(
result
))
sort
.
Sort
(
podsByID
(
test
.
expectedPods
))
if
!
reflect
.
DeepEqual
(
test
.
expectedPods
,
result
)
{
t
.
Errorf
(
"%d: expected: %#v, saw: %#v"
,
i
,
test
.
expectedPods
,
result
)
}
}
}
...
...
pkg/kubelet/kubelet.go
View file @
8420abee
...
...
@@ -1001,17 +1001,6 @@ func (kl *Kubelet) shouldContainerBeRestarted(container *api.Container, pod *api
return
true
}
// Finds an infra container for a pod given by podFullName and UID in dockerContainers. If there is an infra container
// return its ID and true, otherwise it returns empty ID and false.
func
(
kl
*
Kubelet
)
getPodInfraContainer
(
podFullName
string
,
uid
types
.
UID
,
dockerContainers
dockertools
.
DockerContainers
)
(
dockertools
.
DockerID
,
bool
)
{
if
podInfraDockerContainer
,
found
,
_
:=
dockerContainers
.
FindPodContainer
(
podFullName
,
uid
,
dockertools
.
PodInfraContainerName
);
found
{
podInfraContainerID
:=
dockertools
.
DockerID
(
podInfraDockerContainer
.
ID
)
return
podInfraContainerID
,
true
}
return
""
,
false
}
// Attempts to start a container pulling the image before that if necessary. It returns DockerID of a started container
// if it was successful, and a non-nil error otherwise.
func
(
kl
*
Kubelet
)
pullImageAndRunContainer
(
pod
*
api
.
Pod
,
container
*
api
.
Container
,
podVolumes
*
volumeMap
,
...
...
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