fix kubectl rolling-update when GC is enabled
This commit is contained in:
@@ -33,7 +33,7 @@ type ReplicationControllerInterface interface {
|
|||||||
Create(ctrl *api.ReplicationController) (*api.ReplicationController, error)
|
Create(ctrl *api.ReplicationController) (*api.ReplicationController, error)
|
||||||
Update(ctrl *api.ReplicationController) (*api.ReplicationController, error)
|
Update(ctrl *api.ReplicationController) (*api.ReplicationController, error)
|
||||||
UpdateStatus(ctrl *api.ReplicationController) (*api.ReplicationController, error)
|
UpdateStatus(ctrl *api.ReplicationController) (*api.ReplicationController, error)
|
||||||
Delete(name string) error
|
Delete(name string, options *api.DeleteOptions) error
|
||||||
Watch(opts api.ListOptions) (watch.Interface, error)
|
Watch(opts api.ListOptions) (watch.Interface, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,8 +84,8 @@ func (c *replicationControllers) UpdateStatus(controller *api.ReplicationControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete deletes an existing replication controller.
|
// Delete deletes an existing replication controller.
|
||||||
func (c *replicationControllers) Delete(name string) error {
|
func (c *replicationControllers) Delete(name string, options *api.DeleteOptions) error {
|
||||||
return c.r.Delete().Namespace(c.ns).Resource("replicationControllers").Name(name).Do().Error()
|
return c.r.Delete().Namespace(c.ns).Resource("replicationControllers").Name(name).Body(options).Do().Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watch returns a watch.Interface that watches the requested controllers.
|
// Watch returns a watch.Interface that watches the requested controllers.
|
||||||
|
@@ -165,7 +165,7 @@ func TestDeleteController(t *testing.T) {
|
|||||||
Request: simple.Request{Method: "DELETE", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
|
Request: simple.Request{Method: "DELETE", Path: testapi.Default.ResourcePath(getRCResourceName(), ns, "foo"), Query: simple.BuildQueryValues(nil)},
|
||||||
Response: simple.Response{StatusCode: 200},
|
Response: simple.Response{StatusCode: 200},
|
||||||
}
|
}
|
||||||
err := c.Setup(t).ReplicationControllers(ns).Delete("foo")
|
err := c.Setup(t).ReplicationControllers(ns).Delete("foo", nil)
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
c.Validate(t, nil, err)
|
c.Validate(t, nil, err)
|
||||||
}
|
}
|
||||||
|
@@ -72,7 +72,7 @@ func (c *FakeReplicationControllers) UpdateStatus(controller *api.ReplicationCon
|
|||||||
return obj.(*api.ReplicationController), err
|
return obj.(*api.ReplicationController), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FakeReplicationControllers) Delete(name string) error {
|
func (c *FakeReplicationControllers) Delete(name string, options *api.DeleteOptions) error {
|
||||||
_, err := c.Fake.Invokes(NewDeleteAction("replicationcontrollers", c.Namespace, name), &api.ReplicationController{})
|
_, err := c.Fake.Invokes(NewDeleteAction("replicationcontrollers", c.Namespace, name), &api.ReplicationController{})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -513,11 +513,11 @@ func (r *RollingUpdater) cleanupWithClients(oldRc, newRc *api.ReplicationControl
|
|||||||
case DeleteRollingUpdateCleanupPolicy:
|
case DeleteRollingUpdateCleanupPolicy:
|
||||||
// delete old rc
|
// delete old rc
|
||||||
fmt.Fprintf(config.Out, "Update succeeded. Deleting %s\n", oldRc.Name)
|
fmt.Fprintf(config.Out, "Update succeeded. Deleting %s\n", oldRc.Name)
|
||||||
return r.c.ReplicationControllers(r.ns).Delete(oldRc.Name)
|
return r.c.ReplicationControllers(r.ns).Delete(oldRc.Name, nil)
|
||||||
case RenameRollingUpdateCleanupPolicy:
|
case RenameRollingUpdateCleanupPolicy:
|
||||||
// delete old rc
|
// delete old rc
|
||||||
fmt.Fprintf(config.Out, "Update succeeded. Deleting old controller: %s\n", oldRc.Name)
|
fmt.Fprintf(config.Out, "Update succeeded. Deleting old controller: %s\n", oldRc.Name)
|
||||||
if err := r.c.ReplicationControllers(r.ns).Delete(oldRc.Name); err != nil {
|
if err := r.c.ReplicationControllers(r.ns).Delete(oldRc.Name, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(config.Out, "Renaming %s to %s\n", newRc.Name, oldRc.Name)
|
fmt.Fprintf(config.Out, "Renaming %s to %s\n", newRc.Name, oldRc.Name)
|
||||||
@@ -533,13 +533,28 @@ func Rename(c client.ReplicationControllersNamespacer, rc *api.ReplicationContro
|
|||||||
oldName := rc.Name
|
oldName := rc.Name
|
||||||
rc.Name = newName
|
rc.Name = newName
|
||||||
rc.ResourceVersion = ""
|
rc.ResourceVersion = ""
|
||||||
|
// First delete the oldName RC and orphan its pods.
|
||||||
_, err := c.ReplicationControllers(rc.Namespace).Create(rc)
|
trueVar := true
|
||||||
|
err := c.ReplicationControllers(rc.Namespace).Delete(oldName, &api.DeleteOptions{OrphanDependents: &trueVar})
|
||||||
|
if err != nil && !errors.IsNotFound(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = wait.Poll(5*time.Second, 60*time.Second, func() (bool, error) {
|
||||||
|
_, err := c.ReplicationControllers(rc.Namespace).Get(oldName)
|
||||||
|
if err == nil {
|
||||||
|
return false, nil
|
||||||
|
} else if errors.IsNotFound(err) {
|
||||||
|
return true, nil
|
||||||
|
} else {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = c.ReplicationControllers(rc.Namespace).Delete(oldName)
|
// Then create the same RC with the new name.
|
||||||
if err != nil && !errors.IsNotFound(err) {
|
_, err = c.ReplicationControllers(rc.Namespace).Create(rc)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@@ -27,6 +27,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
"k8s.io/kubernetes/pkg/api/errors"
|
||||||
"k8s.io/kubernetes/pkg/api/testapi"
|
"k8s.io/kubernetes/pkg/api/testapi"
|
||||||
apitesting "k8s.io/kubernetes/pkg/api/testing"
|
apitesting "k8s.io/kubernetes/pkg/api/testing"
|
||||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||||
@@ -1143,20 +1144,27 @@ func TestRollingUpdater_cleanupWithClients(t *testing.T) {
|
|||||||
"delete",
|
"delete",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
//{
|
||||||
name: "rename",
|
// This cases is separated to a standalone
|
||||||
policy: RenameRollingUpdateCleanupPolicy,
|
// TestRollingUpdater_cleanupWithClients_Rename. We have to do this
|
||||||
responses: []runtime.Object{rcExisting},
|
// because the unversioned fake client is unable to delete objects.
|
||||||
expected: []string{
|
// TODO: uncomment this case when the unversioned fake client uses
|
||||||
"get",
|
// pkg/client/testing/core.
|
||||||
"update",
|
// {
|
||||||
"get",
|
// name: "rename",
|
||||||
"get",
|
// policy: RenameRollingUpdateCleanupPolicy,
|
||||||
"delete",
|
// responses: []runtime.Object{rcExisting},
|
||||||
"create",
|
// expected: []string{
|
||||||
"delete",
|
// "get",
|
||||||
},
|
// "update",
|
||||||
},
|
// "get",
|
||||||
|
// "get",
|
||||||
|
// "delete",
|
||||||
|
// "create",
|
||||||
|
// "delete",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
//},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@@ -1189,6 +1197,39 @@ func TestRollingUpdater_cleanupWithClients(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestRollingUpdater_cleanupWithClients_Rename tests the rename cleanup policy. It's separated to
|
||||||
|
// a standalone test because the unversioned fake client is unable to delete
|
||||||
|
// objects.
|
||||||
|
// TODO: move this test back to TestRollingUpdater_cleanupWithClients
|
||||||
|
// when the fake client uses pkg/client/testing/core in the future.
|
||||||
|
func TestRollingUpdater_cleanupWithClients_Rename(t *testing.T) {
|
||||||
|
rc := oldRc(2, 2)
|
||||||
|
rcExisting := newRc(1, 3)
|
||||||
|
expectedActions := []string{"delete", "get", "create"}
|
||||||
|
fake := &testclient.Fake{}
|
||||||
|
fake.AddReactor("*", "*", func(action testclient.Action) (handled bool, ret runtime.Object, err error) {
|
||||||
|
switch action.(type) {
|
||||||
|
case testclient.CreateAction:
|
||||||
|
return true, nil, nil
|
||||||
|
case testclient.GetAction:
|
||||||
|
return true, nil, errors.NewNotFound(unversioned.GroupResource{}, "")
|
||||||
|
case testclient.DeleteAction:
|
||||||
|
return true, nil, nil
|
||||||
|
}
|
||||||
|
return false, nil, nil
|
||||||
|
})
|
||||||
|
|
||||||
|
err := Rename(fake, rcExisting, rc.Name)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for j, action := range fake.Actions() {
|
||||||
|
if e, a := expectedActions[j], action.GetVerb(); e != a {
|
||||||
|
t.Errorf("unexpected action: expected %s, got %s", e, a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestFindSourceController(t *testing.T) {
|
func TestFindSourceController(t *testing.T) {
|
||||||
ctrl1 := api.ReplicationController{
|
ctrl1 := api.ReplicationController{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
@@ -202,7 +202,7 @@ func (reaper *ReplicationControllerReaper) Stop(namespace, name string, timeout
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rc.Delete(name)
|
return rc.Delete(name, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(madhusudancs): Implement it when controllerRef is implemented - https://github.com/kubernetes/kubernetes/issues/2210
|
// TODO(madhusudancs): Implement it when controllerRef is implemented - https://github.com/kubernetes/kubernetes/issues/2210
|
||||||
|
@@ -628,7 +628,7 @@ var _ = framework.KubeDescribe("Density", func() {
|
|||||||
By("Removing additional replication controllers if any")
|
By("Removing additional replication controllers if any")
|
||||||
for i := 1; i <= nodeCount; i++ {
|
for i := 1; i <= nodeCount; i++ {
|
||||||
name := additionalPodsPrefix + "-" + strconv.Itoa(i)
|
name := additionalPodsPrefix + "-" + strconv.Itoa(i)
|
||||||
c.ReplicationControllers(ns).Delete(name)
|
c.ReplicationControllers(ns).Delete(name, nil)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -258,7 +258,7 @@ var _ = framework.KubeDescribe("ResourceQuota", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
By("Deleting a ReplicationController")
|
By("Deleting a ReplicationController")
|
||||||
err = f.Client.ReplicationControllers(f.Namespace.Name).Delete(replicationController.Name)
|
err = f.Client.ReplicationControllers(f.Namespace.Name).Delete(replicationController.Name, nil)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
By("Ensuring resource quota status released usage")
|
By("Ensuring resource quota status released usage")
|
||||||
|
@@ -1970,7 +1970,7 @@ func (t *ServiceTestFixture) Cleanup() []error {
|
|||||||
// TODO(mikedanese): Wait.
|
// TODO(mikedanese): Wait.
|
||||||
|
|
||||||
// Then, delete the RC altogether.
|
// Then, delete the RC altogether.
|
||||||
if err := t.Client.ReplicationControllers(t.Namespace).Delete(rcName); err != nil {
|
if err := t.Client.ReplicationControllers(t.Namespace).Delete(rcName, nil); err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -136,7 +136,7 @@ func (h *haproxyControllerTester) start(namespace string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *haproxyControllerTester) stop() error {
|
func (h *haproxyControllerTester) stop() error {
|
||||||
return h.client.ReplicationControllers(h.rcNamespace).Delete(h.rcName)
|
return h.client.ReplicationControllers(h.rcNamespace).Delete(h.rcName, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *haproxyControllerTester) lookup(ingressKey string) string {
|
func (h *haproxyControllerTester) lookup(ingressKey string) string {
|
||||||
|
@@ -351,7 +351,7 @@ func StartPods(namespace string, numPods int, host string, restClient *client.Cl
|
|||||||
} else {
|
} else {
|
||||||
// Delete the rc, otherwise when we restart master components for the next benchmark
|
// Delete the rc, otherwise when we restart master components for the next benchmark
|
||||||
// the rc controller will race with the pods controller in the rc manager.
|
// the rc controller will race with the pods controller in the rc manager.
|
||||||
return restClient.ReplicationControllers(namespace).Delete(rc.Name)
|
return restClient.ReplicationControllers(namespace).Delete(rc.Name, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user