Scale deployments fall-back to regular deployment update

This commit is contained in:
Maciej Szulik
2016-02-11 11:39:44 +01:00
parent 0ea31b56ed
commit b929424135
4 changed files with 160 additions and 217 deletions

View File

@@ -488,145 +488,118 @@ func TestValidateJob(t *testing.T) {
}
}
// TODO(madhusudancs): Fix this when Scale group issues are resolved (see issue #18528).
type ErrorDeployments struct {
testclient.FakeDeployments
invalid bool
}
// type ErrorScales struct {
// testclient.FakeScales
// invalid bool
// }
func (c *ErrorDeployments) Update(deployment *extensions.Deployment) (*extensions.Deployment, error) {
if c.invalid {
return nil, kerrors.NewInvalid(extensions.Kind(deployment.Kind), deployment.Name, nil)
}
return nil, errors.New("deployment update failure")
}
// func (c *ErrorScales) Update(kind string, scale *extensions.Scale) (*extensions.Scale, error) {
// if c.invalid {
// return nil, kerrors.NewInvalid(extensions.Kind(scale.Kind), scale.Name, nil)
// }
// return nil, errors.New("scale update failure")
// }
func (c *ErrorDeployments) Get(name string) (*extensions.Deployment, error) {
return &extensions.Deployment{
Spec: extensions.DeploymentSpec{
Replicas: 0,
},
}, nil
}
// func (c *ErrorScales) Get(kind, name string) (*extensions.Scale, error) {
// return &extensions.Scale{
// Spec: extensions.ScaleSpec{
// Replicas: 0,
// },
// }, nil
// }
type ErrorDeploymentClient struct {
testclient.FakeExperimental
invalid bool
}
// type ErrorDeployments struct {
// testclient.FakeDeployments
// invalid bool
// }
func (c *ErrorDeploymentClient) Deployments(namespace string) client.DeploymentInterface {
return &ErrorDeployments{testclient.FakeDeployments{Fake: &c.FakeExperimental, Namespace: namespace}, c.invalid}
}
// func (c *ErrorDeployments) Update(deployment *extensions.Deployment) (*extensions.Deployment, error) {
// if c.invalid {
// return nil, kerrors.NewInvalid(extensions.Kind(deployment.Kind), deployment.Name, nil)
// }
// return nil, errors.New("deployment update failure")
// }
func TestDeploymentScaleRetry(t *testing.T) {
fake := &ErrorDeploymentClient{FakeExperimental: testclient.FakeExperimental{Fake: &testclient.Fake{}}, invalid: false}
scaler := &DeploymentScaler{fake}
preconditions := &ScalePrecondition{-1, ""}
count := uint(3)
name := "foo"
namespace := "default"
// func (c *ErrorDeployments) Get(name string) (*extensions.Deployment, error) {
// return &extensions.Deployment{
// Spec: extensions.DeploymentSpec{
// Replicas: 0,
// },
// }, nil
// }
scaleFunc := ScaleCondition(scaler, preconditions, namespace, name, count)
pass, err := scaleFunc()
if pass != false {
t.Errorf("Expected an update failure to return pass = false, got pass = %v", pass)
}
if err != nil {
t.Errorf("Did not expect an error on update failure, got %v", err)
}
preconditions = &ScalePrecondition{3, ""}
scaleFunc = ScaleCondition(scaler, preconditions, namespace, name, count)
pass, err = scaleFunc()
if err == nil {
t.Errorf("Expected error on precondition failure")
}
}
// type ErrorDeploymentClient struct {
// testclient.FakeExperimental
// invalid bool
// }
func TestDeploymentScale(t *testing.T) {
fake := &testclient.FakeExperimental{Fake: &testclient.Fake{}}
scaler := DeploymentScaler{fake}
preconditions := ScalePrecondition{-1, ""}
count := uint(3)
name := "foo"
scaler.Scale("default", name, count, &preconditions, nil, nil)
// func (c *ErrorDeploymentClient) Deployments(namespace string) client.DeploymentInterface {
// return &ErrorDeployments{testclient.FakeDeployments{Fake: &c.FakeExperimental, Namespace: namespace}, c.invalid}
// }
actions := fake.Actions()
if len(actions) != 2 {
t.Errorf("unexpected actions: %v, expected 2 actions (get, update)", actions)
}
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "deployments" || action.GetName() != name {
t.Errorf("unexpected action: %v, expected get-replicationController %s", actions[0], name)
}
if action, ok := actions[1].(testclient.UpdateAction); !ok || action.GetResource() != "deployments" || action.GetObject().(*extensions.Deployment).Spec.Replicas != int(count) {
t.Errorf("unexpected action %v, expected update-deployment with replicas = %d", actions[1], count)
}
}
// func (c *ErrorDeploymentClient) Scales(namespace string) client.ScaleInterface {
// return &ErrorScales{testclient.FakeScales{Fake: &c.FakeExperimental, Namespace: namespace}, c.invalid}
// }
func TestDeploymentScaleInvalid(t *testing.T) {
fake := &ErrorDeploymentClient{FakeExperimental: testclient.FakeExperimental{Fake: &testclient.Fake{}}, invalid: true}
scaler := DeploymentScaler{fake}
preconditions := ScalePrecondition{-1, ""}
count := uint(3)
name := "foo"
namespace := "default"
// func TestDeploymentScaleRetry(t *testing.T) {
// fake := &ErrorDeploymentClient{FakeExperimental: testclient.FakeExperimental{Fake: &testclient.Fake{}}, invalid: false}
// scaler := &DeploymentScaler{fake}
// preconditions := &ScalePrecondition{-1, ""}
// count := uint(3)
// name := "foo"
// namespace := "default"
scaleFunc := ScaleCondition(&scaler, &preconditions, namespace, name, count)
pass, err := scaleFunc()
if pass {
t.Errorf("Expected an update failure to return pass = false, got pass = %v", pass)
}
e, ok := err.(ScaleError)
if err == nil || !ok || e.FailureType != ScaleUpdateInvalidFailure {
t.Errorf("Expected error on invalid update failure, got %v", err)
}
}
// scaleFunc := ScaleCondition(scaler, preconditions, namespace, name, count)
// pass, err := scaleFunc()
// if pass != false {
// t.Errorf("Expected an update failure to return pass = false, got pass = %v", pass)
// }
// if err != nil {
// t.Errorf("Did not expect an error on update failure, got %v", err)
// }
// preconditions = &ScalePrecondition{3, ""}
// scaleFunc = ScaleCondition(scaler, preconditions, namespace, name, count)
// pass, err = scaleFunc()
// if err == nil {
// t.Errorf("Expected error on precondition failure")
// }
// }
func TestDeploymentScaleFailsPreconditions(t *testing.T) {
fake := testclient.NewSimpleFake(&extensions.Deployment{
Spec: extensions.DeploymentSpec{
Replicas: 10,
},
})
scaler := DeploymentScaler{&testclient.FakeExperimental{fake}}
preconditions := ScalePrecondition{2, ""}
count := uint(3)
name := "foo"
scaler.Scale("default", name, count, &preconditions, nil, nil)
// func TestDeploymentScale(t *testing.T) {
// fake := &testclient.FakeExperimental{Fake: &testclient.Fake{}}
// scaler := DeploymentScaler{fake}
// preconditions := ScalePrecondition{-1, ""}
// count := uint(3)
// name := "foo"
// scaler.Scale("default", name, count, &preconditions, nil, nil)
// actions := fake.Actions()
// if len(actions) != 2 {
// t.Errorf("unexpected actions: %v, expected 2 actions (get, update)", actions)
// }
// if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "deployments" || action.GetName() != name {
// t.Errorf("unexpected action: %v, expected get-replicationController %s", actions[0], name)
// }
// // TODO: The testclient needs to support subresources
// if action, ok := actions[1].(testclient.UpdateAction); !ok || action.GetResource() != "Deployment" || action.GetObject().(*extensions.Scale).Spec.Replicas != int(count) {
// t.Errorf("unexpected action %v, expected update-deployment-scale with replicas = %d", actions[1], count)
// }
// }
// func TestDeploymentScaleInvalid(t *testing.T) {
// fake := &ErrorDeploymentClient{FakeExperimental: testclient.FakeExperimental{Fake: &testclient.Fake{}}, invalid: true}
// scaler := DeploymentScaler{fake}
// preconditions := ScalePrecondition{-1, ""}
// count := uint(3)
// name := "foo"
// namespace := "default"
// scaleFunc := ScaleCondition(&scaler, &preconditions, namespace, name, count)
// pass, err := scaleFunc()
// if pass {
// t.Errorf("Expected an update failure to return pass = false, got pass = %v", pass)
// }
// e, ok := err.(ScaleError)
// if err == nil || !ok || e.FailureType != ScaleUpdateInvalidFailure {
// t.Errorf("Expected error on invalid update failure, got %v", err)
// }
// }
// func TestDeploymentScaleFailsPreconditions(t *testing.T) {
// fake := testclient.NewSimpleFake(&extensions.Deployment{
// Spec: extensions.DeploymentSpec{
// Replicas: 10,
// },
// })
// scaler := DeploymentScaler{&testclient.FakeExperimental{fake}}
// preconditions := ScalePrecondition{2, ""}
// count := uint(3)
// name := "foo"
// scaler.Scale("default", name, count, &preconditions, nil, nil)
// actions := fake.Actions()
// if len(actions) != 1 {
// t.Errorf("unexpected actions: %v, expected 1 actions (get)", actions)
// }
// if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "deployments" || action.GetName() != name {
// t.Errorf("unexpected action: %v, expected get-deployment %s", actions[0], name)
// }
// }
actions := fake.Actions()
if len(actions) != 1 {
t.Errorf("unexpected actions: %v, expected 1 actions (get)", actions)
}
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "deployments" || action.GetName() != name {
t.Errorf("unexpected action: %v, expected get-deployment %s", actions[0], name)
}
}
func TestValidateDeployment(t *testing.T) {
zero, ten, twenty := 0, 10, 20