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
d624c7de
Commit
d624c7de
authored
Oct 06, 2015
by
feisky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass the ContainerGCPolicy in Runtime.GarbageCollect
parent
69867fb5
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
31 additions
and
32 deletions
+31
-32
server.go
cmd/kubelet/app/server.go
+1
-1
container_gc.go
pkg/kubelet/container/container_gc.go
+6
-8
fake_runtime.go
pkg/kubelet/container/fake_runtime.go
+1
-1
runtime.go
pkg/kubelet/container/runtime.go
+2
-3
container_gc.go
pkg/kubelet/dockertools/container_gc.go
+10
-9
container_gc_test.go
pkg/kubelet/dockertools/container_gc_test.go
+5
-4
manager.go
pkg/kubelet/dockertools/manager.go
+2
-2
kubelet.go
pkg/kubelet/kubelet.go
+3
-3
rkt.go
pkg/kubelet/rkt/rkt.go
+1
-1
No files found.
cmd/kubelet/app/server.go
View file @
d624c7de
...
...
@@ -860,7 +860,7 @@ func CreateAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.Pod
kubeClient
=
kc
.
KubeClient
}
gcPolicy
:=
kube
let
.
ContainerGCPolicy
{
gcPolicy
:=
kube
container
.
ContainerGCPolicy
{
MinAge
:
kc
.
MinimumGCAge
,
MaxPerPodContainer
:
kc
.
MaxPerPodContainerCount
,
MaxContainers
:
kc
.
MaxContainerCount
,
...
...
pkg/kubelet/container_gc.go
→
pkg/kubelet/container
/container
_gc.go
View file @
d624c7de
...
...
@@ -14,13 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package
kubelet
package
container
import
(
"fmt"
"time"
"k8s.io/kubernetes/pkg/kubelet/container"
)
// Specified a policy for garbage collecting containers.
...
...
@@ -39,7 +37,7 @@ type ContainerGCPolicy struct {
// Manages garbage collection of dead containers.
//
// Implementation is thread-compatible.
type
c
ontainerGC
interface
{
type
C
ontainerGC
interface
{
// Garbage collect containers.
GarbageCollect
()
error
}
...
...
@@ -47,14 +45,14 @@ type containerGC interface {
// TODO(vmarmol): Preferentially remove pod infra containers.
type
realContainerGC
struct
{
// Container runtime
runtime
container
.
Runtime
runtime
Runtime
// Policy for garbage collection.
policy
ContainerGCPolicy
}
// New
c
ontainerGC instance with the specified policy.
func
newContainerGC
(
runtime
container
.
Runtime
,
policy
ContainerGCPolicy
)
(
c
ontainerGC
,
error
)
{
// New
C
ontainerGC instance with the specified policy.
func
NewContainerGC
(
runtime
Runtime
,
policy
ContainerGCPolicy
)
(
C
ontainerGC
,
error
)
{
if
policy
.
MinAge
<
0
{
return
nil
,
fmt
.
Errorf
(
"invalid minimum garbage collection age: %v"
,
policy
.
MinAge
)
}
...
...
@@ -66,5 +64,5 @@ func newContainerGC(runtime container.Runtime, policy ContainerGCPolicy) (contai
}
func
(
cgc
*
realContainerGC
)
GarbageCollect
()
error
{
return
cgc
.
runtime
.
GarbageCollect
(
cgc
.
policy
.
MaxPerPodContainer
,
cgc
.
policy
.
MaxContainers
,
cgc
.
policy
.
MinAge
)
return
cgc
.
runtime
.
GarbageCollect
(
cgc
.
policy
)
}
pkg/kubelet/container/fake_runtime.go
View file @
d624c7de
...
...
@@ -305,7 +305,7 @@ func (f *FakeRuntime) PortForward(pod *Pod, port uint16, stream io.ReadWriteClos
return
f
.
Err
}
func
(
f
*
FakeRuntime
)
GarbageCollect
(
maxPerPodContainer
,
maxContainers
int
,
minAge
time
.
Duration
)
error
{
func
(
f
*
FakeRuntime
)
GarbageCollect
(
gcPolicy
ContainerGCPolicy
)
error
{
f
.
Lock
()
defer
f
.
Unlock
()
...
...
pkg/kubelet/container/runtime.go
View file @
d624c7de
...
...
@@ -22,7 +22,6 @@ import (
"io"
"reflect"
"strings"
"time"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
...
...
@@ -75,8 +74,8 @@ type Runtime interface {
// specifies whether the runtime returns all containers including those already
// exited and dead containers (used for garbage collection).
GetPods
(
all
bool
)
([]
*
Pod
,
error
)
// Garbage
collection of dead containers
GarbageCollect
(
maxPerPodContainer
,
maxContainers
int
,
minAge
time
.
Duration
)
error
// Garbage
Collect removes dead containers using the specified container gc policy
GarbageCollect
(
gcPolicy
ContainerGCPolicy
)
error
// Syncs the running pod into the desired pod.
SyncPod
(
pod
*
api
.
Pod
,
runningPod
Pod
,
podStatus
api
.
PodStatus
,
pullSecrets
[]
api
.
Secret
,
backOff
*
util
.
Backoff
)
error
// KillPod kills all the containers of a pod. Pod may be nil, running pod must not be.
...
...
pkg/kubelet/dockertools/container_gc.go
View file @
d624c7de
...
...
@@ -26,6 +26,7 @@ import (
docker
"github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/types"
)
...
...
@@ -172,10 +173,10 @@ func (cgc *containerGC) evictableContainers(minAge time.Duration) (containersByE
return
evictUnits
,
unidentifiedContainers
,
nil
}
// Garbage
collection of dead containers
func
(
cgc
*
containerGC
)
GarbageCollect
(
maxPerPodContainer
,
maxContainers
int
,
minAge
time
.
Duration
)
error
{
// Garbage
Collect removes dead containers using the specified container gc policy
func
(
cgc
*
containerGC
)
GarbageCollect
(
gcPolicy
kubecontainer
.
ContainerGCPolicy
)
error
{
// Separate containers by evict units.
evictUnits
,
unidentifiedContainers
,
err
:=
cgc
.
evictableContainers
(
m
inAge
)
evictUnits
,
unidentifiedContainers
,
err
:=
cgc
.
evictableContainers
(
gcPolicy
.
M
inAge
)
if
err
!=
nil
{
return
err
}
...
...
@@ -190,14 +191,14 @@ func (cgc *containerGC) GarbageCollect(maxPerPodContainer, maxContainers int, mi
}
// Enforce max containers per evict unit.
if
m
axPerPodContainer
>=
0
{
cgc
.
enforceMaxContainersPerEvictUnit
(
evictUnits
,
m
axPerPodContainer
)
if
gcPolicy
.
M
axPerPodContainer
>=
0
{
cgc
.
enforceMaxContainersPerEvictUnit
(
evictUnits
,
gcPolicy
.
M
axPerPodContainer
)
}
// Enforce max total number of containers.
if
maxContainers
>=
0
&&
evictUnits
.
NumContainers
()
>
m
axContainers
{
if
gcPolicy
.
MaxContainers
>=
0
&&
evictUnits
.
NumContainers
()
>
gcPolicy
.
M
axContainers
{
// Leave an equal number of containers per evict unit (min: 1).
numContainersPerEvictUnit
:=
m
axContainers
/
evictUnits
.
NumEvictUnits
()
numContainersPerEvictUnit
:=
gcPolicy
.
M
axContainers
/
evictUnits
.
NumEvictUnits
()
if
numContainersPerEvictUnit
<
1
{
numContainersPerEvictUnit
=
1
}
...
...
@@ -205,14 +206,14 @@ func (cgc *containerGC) GarbageCollect(maxPerPodContainer, maxContainers int, mi
// If we still need to evict, evict oldest first.
numContainers
:=
evictUnits
.
NumContainers
()
if
numContainers
>
m
axContainers
{
if
numContainers
>
gcPolicy
.
M
axContainers
{
flattened
:=
make
([]
containerGCInfo
,
0
,
numContainers
)
for
uid
:=
range
evictUnits
{
flattened
=
append
(
flattened
,
evictUnits
[
uid
]
...
)
}
sort
.
Sort
(
byCreated
(
flattened
))
cgc
.
removeOldestN
(
flattened
,
numContainers
-
m
axContainers
)
cgc
.
removeOldestN
(
flattened
,
numContainers
-
gcPolicy
.
M
axContainers
)
}
}
...
...
pkg/kubelet/dockertools/container_gc_test.go
View file @
d624c7de
...
...
@@ -25,6 +25,7 @@ import (
docker
"github.com/fsouza/go-dockerclient"
"github.com/stretchr/testify/assert"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
)
func
newTestContainerGC
(
t
*
testing
.
T
)
(
*
containerGC
,
*
FakeDockerClient
)
{
...
...
@@ -92,7 +93,7 @@ func TestGarbageCollectZeroMaxContainers(t *testing.T) {
makeContainerDetail
(
"1876"
,
false
,
makeTime
(
0
)),
)
assert
.
Nil
(
t
,
gc
.
GarbageCollect
(
1
,
0
,
time
.
Minute
))
assert
.
Nil
(
t
,
gc
.
GarbageCollect
(
kubecontainer
.
ContainerGCPolicy
{
time
.
Minute
,
1
,
0
}
))
assert
.
Len
(
t
,
fakeDocker
.
Removed
,
1
)
}
...
...
@@ -113,7 +114,7 @@ func TestGarbageCollectNoMaxPerPodContainerLimit(t *testing.T) {
makeContainerDetail
(
"5876"
,
false
,
makeTime
(
4
)),
)
assert
.
Nil
(
t
,
gc
.
GarbageCollect
(
-
1
,
4
,
time
.
Minute
))
assert
.
Nil
(
t
,
gc
.
GarbageCollect
(
kubecontainer
.
ContainerGCPolicy
{
time
.
Minute
,
-
1
,
4
}
))
assert
.
Len
(
t
,
fakeDocker
.
Removed
,
1
)
}
...
...
@@ -134,7 +135,7 @@ func TestGarbageCollectNoMaxLimit(t *testing.T) {
makeContainerDetail
(
"5876"
,
false
,
makeTime
(
0
)),
)
assert
.
Nil
(
t
,
gc
.
GarbageCollect
(
1
,
-
1
,
time
.
Minute
))
assert
.
Nil
(
t
,
gc
.
GarbageCollect
(
kubecontainer
.
ContainerGCPolicy
{
time
.
Minute
,
1
,
-
1
}
))
assert
.
Len
(
t
,
fakeDocker
.
Removed
,
0
)
}
...
...
@@ -306,7 +307,7 @@ func TestGarbageCollect(t *testing.T) {
gc
,
fakeDocker
:=
newTestContainerGC
(
t
)
fakeDocker
.
ContainerList
=
test
.
containers
fakeDocker
.
ContainerMap
=
test
.
containerDetails
assert
.
Nil
(
t
,
gc
.
GarbageCollect
(
2
,
6
,
time
.
Hour
))
assert
.
Nil
(
t
,
gc
.
GarbageCollect
(
kubecontainer
.
ContainerGCPolicy
{
time
.
Hour
,
2
,
6
}
))
verifyStringArrayEqualsAnyOrder
(
t
,
fakeDocker
.
Removed
,
test
.
expectedRemoved
)
}
}
pkg/kubelet/dockertools/manager.go
View file @
d624c7de
...
...
@@ -2025,6 +2025,6 @@ func (dm *DockerManager) GetNetNs(containerID kubecontainer.ContainerID) (string
}
// Garbage collection of dead containers
func
(
dm
*
DockerManager
)
GarbageCollect
(
maxPerPodContainer
,
maxContainers
int
,
minAge
time
.
Duration
)
error
{
return
dm
.
containerGC
.
GarbageCollect
(
maxPerPodContainer
,
maxContainers
,
minAge
)
func
(
dm
*
DockerManager
)
GarbageCollect
(
gcPolicy
kubecontainer
.
ContainerGCPolicy
)
error
{
return
dm
.
containerGC
.
GarbageCollect
(
gcPolicy
)
}
pkg/kubelet/kubelet.go
View file @
d624c7de
...
...
@@ -147,7 +147,7 @@ func NewMainKubelet(
pullBurst
int
,
eventQPS
float32
,
eventBurst
int
,
containerGCPolicy
ContainerGCPolicy
,
containerGCPolicy
kubecontainer
.
ContainerGCPolicy
,
sourcesReady
SourcesReadyFn
,
registerNode
bool
,
standaloneMode
bool
,
...
...
@@ -356,7 +356,7 @@ func NewMainKubelet(
}
// setup containerGC
containerGC
,
err
:=
n
ewContainerGC
(
klet
.
containerRuntime
,
containerGCPolicy
)
containerGC
,
err
:=
kubecontainer
.
N
ewContainerGC
(
klet
.
containerRuntime
,
containerGCPolicy
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -511,7 +511,7 @@ type Kubelet struct {
recorder
record
.
EventRecorder
// Policy for handling garbage collection of dead containers.
containerGC
c
ontainerGC
containerGC
kubecontainer
.
C
ontainerGC
// Manager for images.
imageManager
imageManager
...
...
pkg/kubelet/rkt/rkt.go
View file @
d624c7de
...
...
@@ -1083,7 +1083,7 @@ func (r *Runtime) GetContainerLogs(pod *api.Pod, containerID kubecontainer.Conta
// GarbageCollect collects the pods/containers.
// TODO(yifan): Enforce the gc policy, also, it would be better if we can
// just GC kubernetes pods.
func
(
r
*
runtime
)
GarbageCollect
(
maxPerPodContainer
,
maxContainers
int
,
minAge
time
.
Duration
)
error
{
func
(
r
*
runtime
)
GarbageCollect
(
gcPolicy
kubecontainer
.
ContainerGCPolicy
)
error
{
if
err
:=
exec
.
Command
(
"systemctl"
,
"reset-failed"
)
.
Run
();
err
!=
nil
{
glog
.
Errorf
(
"rkt: Failed to reset failed systemd services: %v"
,
err
)
}
...
...
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