Skip to content

Commit

Permalink
Properly reap replication controllers in e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
bprashanth committed Mar 9, 2015
1 parent b650e48 commit 0e484f2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
15 changes: 9 additions & 6 deletions pkg/kubectl/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import (
)

const (
interval = time.Second * 3
timeout = time.Minute * 5
shortInterval = time.Millisecond * 100
interval = time.Second * 3
timeout = time.Minute * 5
)

// A Reaper handles terminating an object as gracefully as possible.
Expand Down Expand Up @@ -69,10 +70,12 @@ func (reaper *ReplicationControllerReaper) Stop(namespace, name string) (string,
if err != nil {
return "", err
}

controller.Spec.Replicas = 0
// TODO: do retry on 409 errors here?
if _, err := rc.Update(controller); err != nil {
resizer, err := ResizerFor("ReplicationController", *reaper)
if err != nil {
return "", err
}
cond := ResizeCondition(resizer, &ResizePrecondition{-1, ""}, namespace, name, 0)
if err = wait.Poll(shortInterval, reaper.timeout, cond); err != nil {
return "", err
}
if err := wait.Poll(reaper.pollInterval, reaper.timeout,
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ func TestReplicationControllerStop(t *testing.T) {
if s != expected {
t.Errorf("expected %s, got %s", expected, s)
}
if len(fake.Actions) != 4 {
if len(fake.Actions) != 5 {
t.Errorf("unexpected actions: %v, expected 4 actions (get, update, get, delete)", fake.Actions)
}
for i, action := range []string{"get", "update", "get", "delete"} {
for i, action := range []string{"get", "get", "update", "get", "delete"} {
if fake.Actions[i].Action != action+"-controller" {
t.Errorf("unexpected action: %v, expected %s-controller", fake.Actions[i], action)
}
Expand Down
11 changes: 6 additions & 5 deletions test/e2e/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -123,13 +124,13 @@ var _ = Describe("Networking", func() {
defer func() {
defer GinkgoRecover()
By("Cleaning up the replication controller")
rc.Spec.Replicas = 0
rc, err = c.ReplicationControllers(ns).Update(rc)
// Resize the replication controller to zero to get rid of pods.
rcReaper, err := kubectl.ReaperFor("ReplicationController", c)
if err != nil {
Fail(fmt.Sprintf("unable to modify replica count for rc %v: %v", rc.Name, err))
Fail(fmt.Sprintf("unable to stop rc %v: %v", rc.Name, err))
}
if err = c.ReplicationControllers(ns).Delete(rc.Name); err != nil {
Fail(fmt.Sprintf("unable to delete rc %v: %v", rc.Name, err))
if _, err = rcReaper.Stop(ns, rc.Name); err != nil {
Fail(fmt.Sprintf("unable to stop rc %v: %v", rc.Name, err))
}
}()

Expand Down
14 changes: 7 additions & 7 deletions test/e2e/rc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"

Expand Down Expand Up @@ -97,14 +98,13 @@ func ServeImageOrFail(c *client.Client, test string, image string) {
// Cleanup the replication controller when we are done.
defer func() {
// Resize the replication controller to zero to get rid of pods.
controller.Spec.Replicas = 0
if _, err = c.ReplicationControllers(ns).Update(controller); err != nil {
Logf("Failed to resize replication controller %s to zero: %v", name, err)
By("Cleaning up the replication controller")
rcReaper, err := kubectl.ReaperFor("ReplicationController", c)
if err != nil {
Logf("Failed to cleanup replication controller %v: %v.", controller.Name, err)
}

// Delete the replication controller.
if err = c.ReplicationControllers(ns).Delete(name); err != nil {
Logf("Failed to delete replication controller %s: %v", name, err)
if _, err = rcReaper.Stop(ns, controller.Name); err != nil {
Logf("Failed to stop replication controller %v: %v.", controller.Name, err)
}
}()

Expand Down

0 comments on commit 0e484f2

Please sign in to comment.