Merge pull request #46798 from nikhiljindal/servicesReaper

Automatic merge from submit-queue

Deleting kubectl.ServiceReaper since there is no special service deletion logic

Ref https://github.com/kubernetes/kubernetes/pull/46471 #42594

ServiceReaper does not have any special deletion logic so we dont need it. The generic deletion logic should be enough.
By removing this reaper, service deletion also gets the new wait logic from https://github.com/kubernetes/kubernetes/pull/46471

cc @kubernetes/sig-cli-misc
This commit is contained in:
Kubernetes Submit Queue
2017-07-08 05:16:33 -07:00
committed by GitHub
2 changed files with 14 additions and 52 deletions

View File

@@ -81,9 +81,6 @@ func ReaperFor(kind schema.GroupKind, c internalclientset.Interface) (Reaper, er
case api.Kind("Pod"): case api.Kind("Pod"):
return &PodReaper{c.Core()}, nil return &PodReaper{c.Core()}, nil
case api.Kind("Service"):
return &ServiceReaper{c.Core()}, nil
case batch.Kind("Job"): case batch.Kind("Job"):
return &JobReaper{c.Batch(), c.Core(), Interval, Timeout}, nil return &JobReaper{c.Batch(), c.Core(), Interval, Timeout}, nil
@@ -126,9 +123,6 @@ type DeploymentReaper struct {
type PodReaper struct { type PodReaper struct {
client coreclient.PodsGetter client coreclient.PodsGetter
} }
type ServiceReaper struct {
client coreclient.ServicesGetter
}
type StatefulSetReaper struct { type StatefulSetReaper struct {
client appsclient.StatefulSetsGetter client appsclient.StatefulSetsGetter
podClient coreclient.PodsGetter podClient coreclient.PodsGetter
@@ -484,14 +478,3 @@ func (reaper *PodReaper) Stop(namespace, name string, timeout time.Duration, gra
} }
return pods.Delete(name, gracePeriod) return pods.Delete(name, gracePeriod)
} }
func (reaper *ServiceReaper) Stop(namespace, name string, timeout time.Duration, gracePeriod *metav1.DeleteOptions) error {
services := reaper.client.Services(namespace)
_, err := services.Get(name, metav1.GetOptions{})
if err != nil {
return err
}
falseVar := false
deleteOptions := &metav1.DeleteOptions{OrphanDependents: &falseVar}
return services.Delete(name, deleteOptions)
}

View File

@@ -558,26 +558,26 @@ func (c *noSuchPod) Get(name string, options metav1.GetOptions) (*api.Pod, error
return nil, fmt.Errorf("%s does not exist", name) return nil, fmt.Errorf("%s does not exist", name)
} }
type noDeleteService struct { type noDeletePod struct {
coreclient.ServiceInterface coreclient.PodInterface
} }
func (c *noDeleteService) Delete(service string, o *metav1.DeleteOptions) error { func (c *noDeletePod) Delete(name string, o *metav1.DeleteOptions) error {
return fmt.Errorf("I'm afraid I can't do that, Dave") return fmt.Errorf("I'm afraid I can't do that, Dave")
} }
type reaperFake struct { type reaperFake struct {
*fake.Clientset *fake.Clientset
noSuchPod, noDeleteService bool noSuchPod, noDeletePod bool
} }
func (c *reaperFake) Core() coreclient.CoreInterface { func (c *reaperFake) Core() coreclient.CoreInterface {
return &reaperCoreFake{c.Clientset.Core(), c.noSuchPod, c.noDeleteService} return &reaperCoreFake{c.Clientset.Core(), c.noSuchPod, c.noDeletePod}
} }
type reaperCoreFake struct { type reaperCoreFake struct {
coreclient.CoreInterface coreclient.CoreInterface
noSuchPod, noDeleteService bool noSuchPod, noDeletePod bool
} }
func (c *reaperCoreFake) Pods(namespace string) coreclient.PodInterface { func (c *reaperCoreFake) Pods(namespace string) coreclient.PodInterface {
@@ -585,25 +585,16 @@ func (c *reaperCoreFake) Pods(namespace string) coreclient.PodInterface {
if c.noSuchPod { if c.noSuchPod {
return &noSuchPod{pods} return &noSuchPod{pods}
} }
return pods if c.noDeletePod {
} return &noDeletePod{pods}
func (c *reaperCoreFake) Services(namespace string) coreclient.ServiceInterface {
services := c.CoreInterface.Services(namespace)
if c.noDeleteService {
return &noDeleteService{services}
} }
return services return pods
} }
func pod() *api.Pod { func pod() *api.Pod {
return &api.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceDefault, Name: "foo"}} return &api.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceDefault, Name: "foo"}}
} }
func service() *api.Service {
return &api.Service{ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceDefault, Name: "foo"}}
}
func TestSimpleStop(t *testing.T) { func TestSimpleStop(t *testing.T) {
tests := []struct { tests := []struct {
fake *reaperFake fake *reaperFake
@@ -624,18 +615,6 @@ func TestSimpleStop(t *testing.T) {
expectError: false, expectError: false,
test: "stop pod succeeds", test: "stop pod succeeds",
}, },
{
fake: &reaperFake{
Clientset: fake.NewSimpleClientset(service()),
},
kind: api.Kind("Service"),
actions: []testcore.Action{
testcore.NewGetAction(api.Resource("services").WithVersion(""), metav1.NamespaceDefault, "foo"),
testcore.NewDeleteAction(api.Resource("services").WithVersion(""), metav1.NamespaceDefault, "foo"),
},
expectError: false,
test: "stop service succeeds",
},
{ {
fake: &reaperFake{ fake: &reaperFake{
Clientset: fake.NewSimpleClientset(), Clientset: fake.NewSimpleClientset(),
@@ -648,15 +627,15 @@ func TestSimpleStop(t *testing.T) {
}, },
{ {
fake: &reaperFake{ fake: &reaperFake{
Clientset: fake.NewSimpleClientset(service()), Clientset: fake.NewSimpleClientset(pod()),
noDeleteService: true, noDeletePod: true,
}, },
kind: api.Kind("Service"), kind: api.Kind("Pod"),
actions: []testcore.Action{ actions: []testcore.Action{
testcore.NewGetAction(api.Resource("services").WithVersion(""), metav1.NamespaceDefault, "foo"), testcore.NewGetAction(api.Resource("pods").WithVersion(""), metav1.NamespaceDefault, "foo"),
}, },
expectError: true, expectError: true,
test: "stop service fails, can't delete", test: "stop pod fails, can't delete",
}, },
} }
for _, test := range tests { for _, test := range tests {