From 2a538e317fdcefed3e0866a29056bae915319b9e Mon Sep 17 00:00:00 2001 From: nikhiljindal Date: Wed, 24 Feb 2016 13:00:45 -0800 Subject: [PATCH] Moving deployment deletion at the end --- pkg/kubectl/stop.go | 10 ++++------ pkg/kubectl/stop_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/kubectl/stop.go b/pkg/kubectl/stop.go index a6fd7c7ae7..ff97e4ff37 100644 --- a/pkg/kubectl/stop.go +++ b/pkg/kubectl/stop.go @@ -382,11 +382,6 @@ func (reaper *DeploymentReaper) Stop(namespace, name string, timeout time.Durati return err } - // Delete deployment. - if err := deployments.Delete(name, gracePeriod); err != nil { - return err - } - // Stop all replica sets. selector, err := unversioned.LabelSelectorAsSelector(deployment.Spec.Selector) if err != nil { @@ -409,7 +404,10 @@ func (reaper *DeploymentReaper) Stop(namespace, name string, timeout time.Durati if len(errList) > 0 { return utilerrors.NewAggregate(errList) } - return nil + + // Delete deployment at the end. + // Note: We delete deployment at the end so that if removing RSs fails, we atleast have the deployment to retry. + return deployments.Delete(name, gracePeriod) } type updateDeploymentFunc func(d *extensions.Deployment) diff --git a/pkg/kubectl/stop_test.go b/pkg/kubectl/stop_test.go index ceee15fed6..13fdc8bc19 100644 --- a/pkg/kubectl/stop_test.go +++ b/pkg/kubectl/stop_test.go @@ -538,7 +538,7 @@ func TestDeploymentStop(t *testing.T) { }, StopError: nil, ExpectedActions: []string{"get:deployments", "update:deployments", - "get:deployments", "delete:deployments", "list:replicasets"}, + "get:deployments", "list:replicasets", "delete:deployments"}, }, { Name: "Deployment with single replicaset", @@ -560,9 +560,9 @@ func TestDeploymentStop(t *testing.T) { }, StopError: nil, ExpectedActions: []string{"get:deployments", "update:deployments", - "get:deployments", "delete:deployments", "list:replicasets", - "get:replicasets", "get:replicasets", "update:replicasets", - "get:replicasets", "get:replicasets", "delete:replicasets"}, + "get:deployments", "list:replicasets", "get:replicasets", + "get:replicasets", "update:replicasets", "get:replicasets", + "get:replicasets", "delete:replicasets", "delete:deployments"}, }, }