Revert "Use scale subresource"
This commit is contained in:

committed by
GitHub

parent
4389446d4e
commit
e240aff741
@@ -28,52 +28,38 @@ import (
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||
)
|
||||
|
||||
type ErrorScales struct {
|
||||
testclient.FakeScales
|
||||
type ErrorReplicationControllers struct {
|
||||
testclient.FakeReplicationControllers
|
||||
conflict bool
|
||||
invalid bool
|
||||
}
|
||||
|
||||
func (c *ErrorScales) Update(kind string, scale *extensions.Scale) (*extensions.Scale, error) {
|
||||
func (c *ErrorReplicationControllers) Update(controller *api.ReplicationController) (*api.ReplicationController, error) {
|
||||
switch {
|
||||
case c.invalid:
|
||||
return nil, kerrors.NewInvalid(api.Kind(kind), scale.Name, nil)
|
||||
return nil, kerrors.NewInvalid(api.Kind(controller.Kind), controller.Name, nil)
|
||||
case c.conflict:
|
||||
return nil, kerrors.NewConflict(api.Resource(kind), scale.Name, nil)
|
||||
return nil, kerrors.NewConflict(api.Resource(controller.Kind), controller.Name, nil)
|
||||
}
|
||||
return nil, errors.New("Scale update failure")
|
||||
return nil, errors.New("Replication controller update failure")
|
||||
}
|
||||
|
||||
type ErrorExtensions struct {
|
||||
testclient.FakeExperimental
|
||||
conflict bool
|
||||
invalid bool
|
||||
}
|
||||
|
||||
func (c *ErrorExtensions) Scales(namespace string) client.ScaleInterface {
|
||||
return &ErrorScales{
|
||||
FakeScales: testclient.FakeScales{Fake: &c.FakeExperimental, Namespace: namespace},
|
||||
conflict: c.conflict,
|
||||
invalid: c.invalid,
|
||||
}
|
||||
}
|
||||
|
||||
type ErrorExtensionsClient struct {
|
||||
type ErrorReplicationControllerClient struct {
|
||||
testclient.Fake
|
||||
conflict bool
|
||||
invalid bool
|
||||
}
|
||||
|
||||
func (c *ErrorExtensionsClient) Extensions() client.ExtensionsInterface {
|
||||
return &ErrorExtensions{
|
||||
FakeExperimental: testclient.FakeExperimental{Fake: &c.Fake},
|
||||
conflict: c.conflict,
|
||||
invalid: c.invalid,
|
||||
func (c *ErrorReplicationControllerClient) ReplicationControllers(namespace string) client.ReplicationControllerInterface {
|
||||
return &ErrorReplicationControllers{
|
||||
FakeReplicationControllers: testclient.FakeReplicationControllers{Fake: &c.Fake, Namespace: namespace},
|
||||
conflict: c.conflict,
|
||||
invalid: c.invalid,
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplicationControllerScaleRetry(t *testing.T) {
|
||||
fake := &ErrorExtensionsClient{Fake: testclient.Fake{}, conflict: true}
|
||||
fake := &ErrorReplicationControllerClient{Fake: testclient.Fake{}, conflict: true}
|
||||
scaler := ReplicationControllerScaler{fake}
|
||||
preconditions := ScalePrecondition{-1, ""}
|
||||
count := uint(3)
|
||||
@@ -97,7 +83,7 @@ func TestReplicationControllerScaleRetry(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReplicationControllerScaleInvalid(t *testing.T) {
|
||||
fake := &ErrorExtensionsClient{Fake: testclient.Fake{}, invalid: true}
|
||||
fake := &ErrorReplicationControllerClient{Fake: testclient.Fake{}, invalid: true}
|
||||
scaler := ReplicationControllerScaler{fake}
|
||||
preconditions := ScalePrecondition{-1, ""}
|
||||
count := uint(3)
|
||||
@@ -117,7 +103,7 @@ func TestReplicationControllerScaleInvalid(t *testing.T) {
|
||||
|
||||
func TestReplicationControllerScale(t *testing.T) {
|
||||
fake := &testclient.Fake{}
|
||||
scaler := ReplicationControllerScaler{&testclient.FakeExperimental{fake}}
|
||||
scaler := ReplicationControllerScaler{fake}
|
||||
preconditions := ScalePrecondition{-1, ""}
|
||||
count := uint(3)
|
||||
name := "foo"
|
||||
@@ -127,17 +113,17 @@ func TestReplicationControllerScale(t *testing.T) {
|
||||
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() != "ReplicationController" || action.GetName() != name || action.GetSubresource() != "scale" {
|
||||
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "replicationcontrollers" || 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() != "ReplicationController" || action.GetObject().(*extensions.Scale).Spec.Replicas != int32(count) || action.GetSubresource() != "scale" {
|
||||
if action, ok := actions[1].(testclient.UpdateAction); !ok || action.GetResource() != "replicationcontrollers" || action.GetObject().(*api.ReplicationController).Spec.Replicas != int32(count) {
|
||||
t.Errorf("unexpected action %v, expected update-replicationController with replicas = %d", actions[1], count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplicationControllerScaleFailsPreconditions(t *testing.T) {
|
||||
fake := testclient.NewSimpleFake(&extensions.Scale{
|
||||
Spec: extensions.ScaleSpec{
|
||||
fake := testclient.NewSimpleFake(&api.ReplicationController{
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 10,
|
||||
},
|
||||
})
|
||||
@@ -151,15 +137,15 @@ func TestReplicationControllerScaleFailsPreconditions(t *testing.T) {
|
||||
if len(actions) != 1 {
|
||||
t.Errorf("unexpected actions: %v, expected 1 action (get)", actions)
|
||||
}
|
||||
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "ReplicationController" || action.GetName() != name || action.GetSubresource() != "scale" {
|
||||
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "replicationcontrollers" || action.GetName() != name {
|
||||
t.Errorf("unexpected action: %v, expected get-replicationController %s", actions[0], name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateScale(t *testing.T) {
|
||||
func TestValidateReplicationController(t *testing.T) {
|
||||
tests := []struct {
|
||||
preconditions ScalePrecondition
|
||||
scale extensions.Scale
|
||||
controller api.ReplicationController
|
||||
expectError bool
|
||||
test string
|
||||
}{
|
||||
@@ -170,11 +156,11 @@ func TestValidateScale(t *testing.T) {
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{-1, ""},
|
||||
scale: extensions.Scale{
|
||||
controller: api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "foo",
|
||||
},
|
||||
Spec: extensions.ScaleSpec{
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 10,
|
||||
},
|
||||
},
|
||||
@@ -183,11 +169,11 @@ func TestValidateScale(t *testing.T) {
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{0, ""},
|
||||
scale: extensions.Scale{
|
||||
controller: api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "foo",
|
||||
},
|
||||
Spec: extensions.ScaleSpec{
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 0,
|
||||
},
|
||||
},
|
||||
@@ -196,11 +182,11 @@ func TestValidateScale(t *testing.T) {
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{-1, "foo"},
|
||||
scale: extensions.Scale{
|
||||
controller: api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "foo",
|
||||
},
|
||||
Spec: extensions.ScaleSpec{
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 10,
|
||||
},
|
||||
},
|
||||
@@ -209,11 +195,11 @@ func TestValidateScale(t *testing.T) {
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{10, "foo"},
|
||||
scale: extensions.Scale{
|
||||
controller: api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "foo",
|
||||
},
|
||||
Spec: extensions.ScaleSpec{
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 10,
|
||||
},
|
||||
},
|
||||
@@ -222,11 +208,11 @@ func TestValidateScale(t *testing.T) {
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{10, "foo"},
|
||||
scale: extensions.Scale{
|
||||
controller: api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "foo",
|
||||
},
|
||||
Spec: extensions.ScaleSpec{
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 20,
|
||||
},
|
||||
},
|
||||
@@ -235,11 +221,11 @@ func TestValidateScale(t *testing.T) {
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{10, "foo"},
|
||||
scale: extensions.Scale{
|
||||
controller: api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "bar",
|
||||
},
|
||||
Spec: extensions.ScaleSpec{
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 10,
|
||||
},
|
||||
},
|
||||
@@ -248,11 +234,11 @@ func TestValidateScale(t *testing.T) {
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{10, "foo"},
|
||||
scale: extensions.Scale{
|
||||
controller: api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "bar",
|
||||
},
|
||||
Spec: extensions.ScaleSpec{
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 20,
|
||||
},
|
||||
},
|
||||
@@ -261,7 +247,7 @@ func TestValidateScale(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
err := test.preconditions.ValidateScale(&test.scale)
|
||||
err := test.preconditions.ValidateReplicationController(&test.controller)
|
||||
if err != nil && !test.expectError {
|
||||
t.Errorf("unexpected error: %v (%s)", err, test.test)
|
||||
}
|
||||
@@ -521,8 +507,46 @@ func TestValidateJob(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type ErrorDeployments struct {
|
||||
testclient.FakeDeployments
|
||||
conflict bool
|
||||
invalid bool
|
||||
}
|
||||
|
||||
func (c *ErrorDeployments) Update(deployment *extensions.Deployment) (*extensions.Deployment, error) {
|
||||
switch {
|
||||
case c.invalid:
|
||||
return nil, kerrors.NewInvalid(api.Kind(deployment.Kind), deployment.Name, nil)
|
||||
case c.conflict:
|
||||
return nil, kerrors.NewConflict(api.Resource(deployment.Kind), deployment.Name, nil)
|
||||
}
|
||||
return nil, errors.New("deployment update failure")
|
||||
}
|
||||
|
||||
func (c *ErrorDeployments) Get(name string) (*extensions.Deployment, error) {
|
||||
return &extensions.Deployment{
|
||||
Spec: extensions.DeploymentSpec{
|
||||
Replicas: 0,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
type ErrorDeploymentClient struct {
|
||||
testclient.FakeExperimental
|
||||
conflict bool
|
||||
invalid bool
|
||||
}
|
||||
|
||||
func (c *ErrorDeploymentClient) Deployments(namespace string) client.DeploymentInterface {
|
||||
return &ErrorDeployments{
|
||||
FakeDeployments: testclient.FakeDeployments{Fake: &c.FakeExperimental, Namespace: namespace},
|
||||
invalid: c.invalid,
|
||||
conflict: c.conflict,
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeploymentScaleRetry(t *testing.T) {
|
||||
fake := &ErrorExtensions{FakeExperimental: testclient.FakeExperimental{Fake: &testclient.Fake{}}, conflict: true}
|
||||
fake := &ErrorDeploymentClient{FakeExperimental: testclient.FakeExperimental{}, conflict: true}
|
||||
scaler := &DeploymentScaler{fake}
|
||||
preconditions := &ScalePrecondition{-1, ""}
|
||||
count := uint(3)
|
||||
@@ -557,16 +581,16 @@ func TestDeploymentScale(t *testing.T) {
|
||||
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() != "Deployment" || action.GetName() != name || action.GetSubresource() != "scale" {
|
||||
t.Errorf("unexpected action: %v, expected get-deployment %s", actions[0], name)
|
||||
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() != "Deployment" || action.GetObject().(*extensions.Scale).Spec.Replicas != int32(count) || action.GetSubresource() != "scale" {
|
||||
if action, ok := actions[1].(testclient.UpdateAction); !ok || action.GetResource() != "deployments" || action.GetObject().(*extensions.Deployment).Spec.Replicas != int32(count) {
|
||||
t.Errorf("unexpected action %v, expected update-deployment with replicas = %d", actions[1], count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeploymentScaleInvalid(t *testing.T) {
|
||||
fake := &ErrorExtensions{FakeExperimental: testclient.FakeExperimental{Fake: &testclient.Fake{}}, invalid: true}
|
||||
fake := &ErrorDeploymentClient{FakeExperimental: testclient.FakeExperimental{}, invalid: true}
|
||||
scaler := DeploymentScaler{fake}
|
||||
preconditions := ScalePrecondition{-1, ""}
|
||||
count := uint(3)
|
||||
@@ -585,8 +609,8 @@ func TestDeploymentScaleInvalid(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeploymentScaleFailsPreconditions(t *testing.T) {
|
||||
fake := testclient.NewSimpleFake(&extensions.Scale{
|
||||
Spec: extensions.ScaleSpec{
|
||||
fake := testclient.NewSimpleFake(&extensions.Deployment{
|
||||
Spec: extensions.DeploymentSpec{
|
||||
Replicas: 10,
|
||||
},
|
||||
})
|
||||
@@ -600,7 +624,133 @@ func TestDeploymentScaleFailsPreconditions(t *testing.T) {
|
||||
if len(actions) != 1 {
|
||||
t.Errorf("unexpected actions: %v, expected 1 actions (get)", actions)
|
||||
}
|
||||
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "Deployment" || action.GetName() != name || action.GetSubresource() != "scale" {
|
||||
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 := int32(0), int32(10), int32(20)
|
||||
tests := []struct {
|
||||
preconditions ScalePrecondition
|
||||
deployment extensions.Deployment
|
||||
expectError bool
|
||||
test string
|
||||
}{
|
||||
{
|
||||
preconditions: ScalePrecondition{-1, ""},
|
||||
expectError: false,
|
||||
test: "defaults",
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{-1, ""},
|
||||
deployment: extensions.Deployment{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "foo",
|
||||
},
|
||||
Spec: extensions.DeploymentSpec{
|
||||
Replicas: ten,
|
||||
},
|
||||
},
|
||||
expectError: false,
|
||||
test: "defaults 2",
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{0, ""},
|
||||
deployment: extensions.Deployment{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "foo",
|
||||
},
|
||||
Spec: extensions.DeploymentSpec{
|
||||
Replicas: zero,
|
||||
},
|
||||
},
|
||||
expectError: false,
|
||||
test: "size matches",
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{-1, "foo"},
|
||||
deployment: extensions.Deployment{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "foo",
|
||||
},
|
||||
Spec: extensions.DeploymentSpec{
|
||||
Replicas: ten,
|
||||
},
|
||||
},
|
||||
expectError: false,
|
||||
test: "resource version matches",
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{10, "foo"},
|
||||
deployment: extensions.Deployment{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "foo",
|
||||
},
|
||||
Spec: extensions.DeploymentSpec{
|
||||
Replicas: ten,
|
||||
},
|
||||
},
|
||||
expectError: false,
|
||||
test: "both match",
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{10, "foo"},
|
||||
deployment: extensions.Deployment{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "foo",
|
||||
},
|
||||
Spec: extensions.DeploymentSpec{
|
||||
Replicas: twenty,
|
||||
},
|
||||
},
|
||||
expectError: true,
|
||||
test: "size different",
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{10, "foo"},
|
||||
deployment: extensions.Deployment{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "foo",
|
||||
},
|
||||
},
|
||||
expectError: true,
|
||||
test: "no replicas",
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{10, "foo"},
|
||||
deployment: extensions.Deployment{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "bar",
|
||||
},
|
||||
Spec: extensions.DeploymentSpec{
|
||||
Replicas: ten,
|
||||
},
|
||||
},
|
||||
expectError: true,
|
||||
test: "version different",
|
||||
},
|
||||
{
|
||||
preconditions: ScalePrecondition{10, "foo"},
|
||||
deployment: extensions.Deployment{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ResourceVersion: "bar",
|
||||
},
|
||||
Spec: extensions.DeploymentSpec{
|
||||
Replicas: twenty,
|
||||
},
|
||||
},
|
||||
expectError: true,
|
||||
test: "both different",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
err := test.preconditions.ValidateDeployment(&test.deployment)
|
||||
if err != nil && !test.expectError {
|
||||
t.Errorf("unexpected error: %v (%s)", err, test.test)
|
||||
}
|
||||
if err == nil && test.expectError {
|
||||
t.Errorf("unexpected non-error: %v (%s)", err, test.test)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user