mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
use an aggressive delete option when deleting pods in the pod garbage collector
This commit is contained in:
parent
273c9ce503
commit
66ddde9fea
@ -42,9 +42,9 @@ const (
|
|||||||
|
|
||||||
type GCController struct {
|
type GCController struct {
|
||||||
kubeClient client.Interface
|
kubeClient client.Interface
|
||||||
podControl controller.PodControlInterface
|
|
||||||
podStore cache.StoreToPodLister
|
podStore cache.StoreToPodLister
|
||||||
podStoreSyncer *framework.Controller
|
podStoreSyncer *framework.Controller
|
||||||
|
deletePod func(namespace, name string) error
|
||||||
threshold int
|
threshold int
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,11 +55,10 @@ func New(kubeClient client.Interface, resyncPeriod controller.ResyncPeriodFunc,
|
|||||||
|
|
||||||
gcc := &GCController{
|
gcc := &GCController{
|
||||||
kubeClient: kubeClient,
|
kubeClient: kubeClient,
|
||||||
podControl: controller.RealPodControl{
|
|
||||||
Recorder: eventBroadcaster.NewRecorder(api.EventSource{Component: "pod-garbage-collector"}),
|
|
||||||
KubeClient: kubeClient,
|
|
||||||
},
|
|
||||||
threshold: threshold,
|
threshold: threshold,
|
||||||
|
deletePod: func(namespace, name string) error {
|
||||||
|
return kubeClient.Pods(namespace).Delete(name, api.NewDeleteOptions(0))
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
terminatedSelector := compileTerminatedPodSelector()
|
terminatedSelector := compileTerminatedPodSelector()
|
||||||
@ -105,7 +104,7 @@ func (gcc *GCController) gc() {
|
|||||||
wait.Add(1)
|
wait.Add(1)
|
||||||
go func(namespace string, name string) {
|
go func(namespace string, name string) {
|
||||||
defer wait.Done()
|
defer wait.Done()
|
||||||
if err := gcc.podControl.DeletePod(namespace, name); err != nil {
|
if err := gcc.deletePod(namespace, name); err != nil {
|
||||||
// ignore not founds
|
// ignore not founds
|
||||||
defer util.HandleError(err)
|
defer util.HandleError(err)
|
||||||
}
|
}
|
||||||
|
@ -25,41 +25,9 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||||
"k8s.io/kubernetes/pkg/controller"
|
"k8s.io/kubernetes/pkg/controller"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
|
||||||
"k8s.io/kubernetes/pkg/util/sets"
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FakePodControl struct {
|
|
||||||
podSpec []api.PodTemplateSpec
|
|
||||||
deletePodName []string
|
|
||||||
lock sync.Mutex
|
|
||||||
err error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakePodControl) CreatePods(namespace string, spec *api.PodTemplateSpec, object runtime.Object) error {
|
|
||||||
panic("unimplemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakePodControl) CreatePodsOnNode(nodeName, namespace string, spec *api.PodTemplateSpec, object runtime.Object) error {
|
|
||||||
panic("unimplemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakePodControl) DeletePod(namespace string, podName string) error {
|
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
if f.err != nil {
|
|
||||||
return f.err
|
|
||||||
}
|
|
||||||
f.deletePodName = append(f.deletePodName, podName)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (f *FakePodControl) clear() {
|
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
f.deletePodName = []string{}
|
|
||||||
f.podSpec = []api.PodTemplateSpec{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGC(t *testing.T) {
|
func TestGC(t *testing.T) {
|
||||||
type nameToPhase struct {
|
type nameToPhase struct {
|
||||||
name string
|
name string
|
||||||
@ -100,8 +68,14 @@ func TestGC(t *testing.T) {
|
|||||||
for i, test := range testCases {
|
for i, test := range testCases {
|
||||||
client := testclient.NewSimpleFake()
|
client := testclient.NewSimpleFake()
|
||||||
gcc := New(client, controller.NoResyncPeriodFunc, test.threshold)
|
gcc := New(client, controller.NoResyncPeriodFunc, test.threshold)
|
||||||
fake := &FakePodControl{}
|
deletedPodNames := make([]string, 0)
|
||||||
gcc.podControl = fake
|
var lock sync.Mutex
|
||||||
|
gcc.deletePod = func(_, name string) error {
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
deletedPodNames = append(deletedPodNames, name)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
creationTime := time.Unix(0, 0)
|
creationTime := time.Unix(0, 0)
|
||||||
for _, pod := range test.pods {
|
for _, pod := range test.pods {
|
||||||
@ -115,16 +89,16 @@ func TestGC(t *testing.T) {
|
|||||||
gcc.gc()
|
gcc.gc()
|
||||||
|
|
||||||
pass := true
|
pass := true
|
||||||
for _, pod := range fake.deletePodName {
|
for _, pod := range deletedPodNames {
|
||||||
if !test.deletedPodNames.Has(pod) {
|
if !test.deletedPodNames.Has(pod) {
|
||||||
pass = false
|
pass = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(fake.deletePodName) != len(test.deletedPodNames) {
|
if len(deletedPodNames) != len(test.deletedPodNames) {
|
||||||
pass = false
|
pass = false
|
||||||
}
|
}
|
||||||
if !pass {
|
if !pass {
|
||||||
t.Errorf("[%v]pod's deleted expected and actual did not match.\n\texpected: %v\n\tactual: %v", i, test.deletedPodNames, fake.deletePodName)
|
t.Errorf("[%v]pod's deleted expected and actual did not match.\n\texpected: %v\n\tactual: %v", i, test.deletedPodNames, deletedPodNames)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user