Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use an aggressive delete option when deleting pods in the pod garbage collector #15429

Merged
merged 1 commit into from
Oct 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions pkg/controller/gc/gc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const (

type GCController struct {
kubeClient client.Interface
podControl controller.PodControlInterface
podStore cache.StoreToPodLister
podStoreSyncer *framework.Controller
deletePod func(namespace, name string) error
threshold int
}

Expand All @@ -55,11 +55,10 @@ func New(kubeClient client.Interface, resyncPeriod controller.ResyncPeriodFunc,

gcc := &GCController{
kubeClient: kubeClient,
podControl: controller.RealPodControl{
Recorder: eventBroadcaster.NewRecorder(api.EventSource{Component: "pod-garbage-collector"}),
KubeClient: kubeClient,
threshold: threshold,
deletePod: func(namespace, name string) error {
return kubeClient.Pods(namespace).Delete(name, api.NewDeleteOptions(0))
},
threshold: threshold,
}

terminatedSelector := compileTerminatedPodSelector()
Expand Down Expand Up @@ -105,7 +104,7 @@ func (gcc *GCController) gc() {
wait.Add(1)
go func(namespace string, name string) {
defer wait.Done()
if err := gcc.podControl.DeletePod(namespace, name); err != nil {
if err := gcc.deletePod(namespace, name); err != nil {
// ignore not founds
defer util.HandleError(err)
}
Expand Down
48 changes: 11 additions & 37 deletions pkg/controller/gc/gc_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,9 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/runtime"
"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) {
type nameToPhase struct {
name string
Expand Down Expand Up @@ -100,8 +68,14 @@ func TestGC(t *testing.T) {
for i, test := range testCases {
client := testclient.NewSimpleFake()
gcc := New(client, controller.NoResyncPeriodFunc, test.threshold)
fake := &FakePodControl{}
gcc.podControl = fake
deletedPodNames := make([]string, 0)
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)
for _, pod := range test.pods {
Expand All @@ -115,16 +89,16 @@ func TestGC(t *testing.T) {
gcc.gc()

pass := true
for _, pod := range fake.deletePodName {
for _, pod := range deletedPodNames {
if !test.deletedPodNames.Has(pod) {
pass = false
}
}
if len(fake.deletePodName) != len(test.deletedPodNames) {
if len(deletedPodNames) != len(test.deletedPodNames) {
pass = false
}
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)
}
}
}
Expand Down