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
ee4e8871
Commit
ee4e8871
authored
Mar 12, 2015
by
Dawn Chen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5395 from vmarmol/fix
Garbage collect unidentified Kubernetes containers.
parents
4420e045
51122998
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
0 deletions
+74
-0
kubelet.go
pkg/kubelet/kubelet.go
+37
-0
kubelet_test.go
pkg/kubelet/kubelet_test.go
+37
-0
No files found.
pkg/kubelet/kubelet.go
View file @
ee4e8871
...
@@ -466,12 +466,48 @@ func (kl *Kubelet) GarbageCollectContainers() error {
...
@@ -466,12 +466,48 @@ func (kl *Kubelet) GarbageCollectContainers() error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
type
unidentifiedContainer
struct
{
// Docker ID.
id
string
// Docker container name
name
string
}
unidentifiedContainers
:=
make
([]
unidentifiedContainer
,
0
)
uidToIDMap
:=
map
[
string
][]
string
{}
uidToIDMap
:=
map
[
string
][]
string
{}
for
_
,
container
:=
range
containers
{
for
_
,
container
:=
range
containers
{
_
,
uid
,
name
,
_
:=
dockertools
.
ParseDockerName
(
container
.
Names
[
0
])
_
,
uid
,
name
,
_
:=
dockertools
.
ParseDockerName
(
container
.
Names
[
0
])
if
uid
==
""
&&
name
==
""
{
unidentifiedContainers
=
append
(
unidentifiedContainers
,
unidentifiedContainer
{
id
:
container
.
ID
,
name
:
container
.
Names
[
0
],
})
continue
}
uidName
:=
string
(
uid
)
+
"."
+
name
uidName
:=
string
(
uid
)
+
"."
+
name
uidToIDMap
[
uidName
]
=
append
(
uidToIDMap
[
uidName
],
container
.
ID
)
uidToIDMap
[
uidName
]
=
append
(
uidToIDMap
[
uidName
],
container
.
ID
)
}
}
// Remove all non-running unidentified containers.
for
_
,
container
:=
range
unidentifiedContainers
{
data
,
err
:=
kl
.
dockerClient
.
InspectContainer
(
container
.
id
)
if
err
!=
nil
{
return
err
}
if
data
.
State
.
Running
{
continue
}
glog
.
Infof
(
"Removing unidentified dead container %q with ID %q"
,
container
.
name
,
container
.
id
)
err
=
kl
.
dockerClient
.
RemoveContainer
(
docker
.
RemoveContainerOptions
{
ID
:
container
.
id
})
if
err
!=
nil
{
return
err
}
}
// Evict dead containers according to our policies.
for
_
,
list
:=
range
uidToIDMap
{
for
_
,
list
:=
range
uidToIDMap
{
if
len
(
list
)
<=
kl
.
maxContainerCount
{
if
len
(
list
)
<=
kl
.
maxContainerCount
{
continue
continue
...
@@ -480,6 +516,7 @@ func (kl *Kubelet) GarbageCollectContainers() error {
...
@@ -480,6 +516,7 @@ func (kl *Kubelet) GarbageCollectContainers() error {
return
err
return
err
}
}
}
}
return
nil
return
nil
}
}
...
...
pkg/kubelet/kubelet_test.go
View file @
ee4e8871
...
@@ -1741,6 +1741,43 @@ func TestKubeletGarbageCollection(t *testing.T) {
...
@@ -1741,6 +1741,43 @@ func TestKubeletGarbageCollection(t *testing.T) {
},
},
expectedRemoved
:
[]
string
{
"1706"
,
"1876"
},
expectedRemoved
:
[]
string
{
"1706"
,
"1876"
},
},
},
// Remove non-running unidentified Kubernetes containers.
{
containers
:
[]
docker
.
APIContainers
{
{
// Unidentified Kubernetes container.
Names
:
[]
string
{
"/k8s_unidentified"
},
ID
:
"1876"
,
},
{
// Unidentified (non-running) Kubernetes container.
Names
:
[]
string
{
"/k8s_unidentified"
},
ID
:
"2309"
,
},
{
// Regular Kubernetes container.
Names
:
[]
string
{
"/k8s_POD_foo_new_.deadbeef_42"
},
ID
:
"3876"
,
},
},
containerDetails
:
map
[
string
]
*
docker
.
Container
{
"1876"
:
{
State
:
docker
.
State
{
Running
:
false
,
},
ID
:
"1876"
,
Created
:
time
.
Now
(),
},
"2309"
:
{
State
:
docker
.
State
{
Running
:
true
,
},
ID
:
"2309"
,
Created
:
time
.
Now
(),
},
},
expectedRemoved
:
[]
string
{
"1876"
},
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
kubelet
,
fakeDocker
,
_
,
_
:=
newTestKubelet
(
t
)
kubelet
,
fakeDocker
,
_
,
_
:=
newTestKubelet
(
t
)
...
...
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