mirror of https://github.com/k3s-io/k3s
Scale deployments fall-back to regular deployment update
parent
0ea31b56ed
commit
b929424135
|
@ -966,15 +966,14 @@ __EOF__
|
||||||
# Clean-up
|
# Clean-up
|
||||||
kubectl delete job/pi "${kube_flags[@]}"
|
kubectl delete job/pi "${kube_flags[@]}"
|
||||||
|
|
||||||
# TODO(madhusudancs): Fix this when Scale group issues are resolved (see issue #18528).
|
### Scale a deployment
|
||||||
# ### Scale a deployment
|
kubectl create -f docs/user-guide/deployment.yaml "${kube_flags[@]}"
|
||||||
# kubectl create -f examples/extensions/deployment.yaml "${kube_flags[@]}"
|
# Command
|
||||||
# # Command
|
kubectl scale --current-replicas=3 --replicas=1 deployment/nginx-deployment
|
||||||
# kubectl scale --current-replicas=3 --replicas=1 deployment/nginx-deployment
|
# Post-condition: 1 replica for nginx-deployment
|
||||||
# # Post-condition: 1 replica for nginx-deployment
|
kube::test::get_object_assert 'deployment nginx-deployment' "{{$deployment_replicas}}" '1'
|
||||||
# kube::test::get_object_assert 'deployment nginx-deployment' "{{$deployment_replicas}}" '1'
|
# Clean-up
|
||||||
# # Clean-up
|
kubectl delete deployment/nginx-deployment "${kube_flags[@]}"
|
||||||
# kubectl delete deployment/nginx-deployment "${kube_flags[@]}"
|
|
||||||
|
|
||||||
### Expose a deployment as a service
|
### Expose a deployment as a service
|
||||||
kubectl create -f docs/user-guide/deployment.yaml "${kube_flags[@]}"
|
kubectl create -f docs/user-guide/deployment.yaml "${kube_flags[@]}"
|
||||||
|
|
|
@ -48,9 +48,8 @@ func ScalerFor(kind unversioned.GroupKind, c client.Interface) (Scaler, error) {
|
||||||
return &ReplicaSetScaler{c.Extensions()}, nil
|
return &ReplicaSetScaler{c.Extensions()}, nil
|
||||||
case extensions.Kind("Job"):
|
case extensions.Kind("Job"):
|
||||||
return &JobScaler{c.Extensions()}, nil
|
return &JobScaler{c.Extensions()}, nil
|
||||||
// TODO(madhusudancs): Fix this when Scale group issues are resolved (see issue #18528).
|
case extensions.Kind("Deployment"):
|
||||||
// case extensions.Kind("Deployment"):
|
return &DeploymentScaler{c.Extensions()}, nil
|
||||||
// return &DeploymentScaler{c.Extensions()}, nil
|
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("no scaler has been implemented for %q", kind)
|
return nil, fmt.Errorf("no scaler has been implemented for %q", kind)
|
||||||
}
|
}
|
||||||
|
@ -328,57 +327,55 @@ func (precondition *ScalePrecondition) ValidateDeployment(deployment *extensions
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(madhusudancs): Fix this when Scale group issues are resolved (see issue #18528).
|
type DeploymentScaler struct {
|
||||||
// type DeploymentScaler struct {
|
c client.ExtensionsInterface
|
||||||
// c client.ExtensionsInterface
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// // ScaleSimple is responsible for updating a deployment's desired replicas count.
|
// ScaleSimple is responsible for updating a deployment's desired replicas count.
|
||||||
// func (scaler *DeploymentScaler) ScaleSimple(namespace, name string, preconditions *ScalePrecondition, newSize uint) error {
|
func (scaler *DeploymentScaler) ScaleSimple(namespace, name string, preconditions *ScalePrecondition, newSize uint) error {
|
||||||
// deployment, err := scaler.c.Deployments(namespace).Get(name)
|
deployment, err := scaler.c.Deployments(namespace).Get(name)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return ScaleError{ScaleGetFailure, "Unknown", err}
|
return ScaleError{ScaleGetFailure, "Unknown", err}
|
||||||
// }
|
}
|
||||||
// if preconditions != nil {
|
if preconditions != nil {
|
||||||
// if err := preconditions.ValidateDeployment(deployment); err != nil {
|
if err := preconditions.ValidateDeployment(deployment); err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// scale, err := extensions.ScaleFromDeployment(deployment)
|
|
||||||
// if err != nil {
|
|
||||||
// return ScaleError{ScaleUpdateFailure, deployment.ResourceVersion, err}
|
|
||||||
// }
|
|
||||||
// scale.Spec.Replicas = int(newSize)
|
|
||||||
// if _, err := scaler.c.Scales(namespace).Update("Deployment", scale); err != nil {
|
|
||||||
// if errors.IsInvalid(err) {
|
|
||||||
// return ScaleError{ScaleUpdateInvalidFailure, deployment.ResourceVersion, err}
|
|
||||||
// }
|
|
||||||
// return ScaleError{ScaleUpdateFailure, deployment.ResourceVersion, err}
|
|
||||||
// }
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Scale updates a deployment to a new size, with optional precondition check (if preconditions is not nil),
|
// TODO(madhusudancs): Fix this when Scale group issues are resolved (see issue #18528).
|
||||||
// // optional retries (if retry is not nil), and then optionally waits for the status to reach desired count.
|
// For now I'm falling back to regular Deployment update operation.
|
||||||
// func (scaler *DeploymentScaler) Scale(namespace, name string, newSize uint, preconditions *ScalePrecondition, retry, waitForReplicas *RetryParams) error {
|
deployment.Spec.Replicas = int(newSize)
|
||||||
// if preconditions == nil {
|
if _, err := scaler.c.Deployments(namespace).Update(deployment); err != nil {
|
||||||
// preconditions = &ScalePrecondition{-1, ""}
|
if errors.IsInvalid(err) {
|
||||||
// }
|
return ScaleError{ScaleUpdateInvalidFailure, deployment.ResourceVersion, err}
|
||||||
// if retry == nil {
|
}
|
||||||
// // Make it try only once, immediately
|
return ScaleError{ScaleUpdateFailure, deployment.ResourceVersion, err}
|
||||||
// retry = &RetryParams{Interval: time.Millisecond, Timeout: time.Millisecond}
|
}
|
||||||
// }
|
return nil
|
||||||
// cond := ScaleCondition(scaler, preconditions, namespace, name, newSize)
|
}
|
||||||
// if err := wait.Poll(retry.Interval, retry.Timeout, cond); err != nil {
|
|
||||||
// return err
|
// Scale updates a deployment to a new size, with optional precondition check (if preconditions is not nil),
|
||||||
// }
|
// optional retries (if retry is not nil), and then optionally waits for the status to reach desired count.
|
||||||
// if waitForReplicas != nil {
|
func (scaler *DeploymentScaler) Scale(namespace, name string, newSize uint, preconditions *ScalePrecondition, retry, waitForReplicas *RetryParams) error {
|
||||||
// deployment, err := scaler.c.Deployments(namespace).Get(name)
|
if preconditions == nil {
|
||||||
// if err != nil {
|
preconditions = &ScalePrecondition{-1, ""}
|
||||||
// return err
|
}
|
||||||
// }
|
if retry == nil {
|
||||||
// return wait.Poll(waitForReplicas.Interval, waitForReplicas.Timeout,
|
// Make it try only once, immediately
|
||||||
// client.DeploymentHasDesiredReplicas(scaler.c, deployment))
|
retry = &RetryParams{Interval: time.Millisecond, Timeout: time.Millisecond}
|
||||||
// }
|
}
|
||||||
// return nil
|
cond := ScaleCondition(scaler, preconditions, namespace, name, newSize)
|
||||||
// }
|
if err := wait.Poll(retry.Interval, retry.Timeout, cond); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if waitForReplicas != nil {
|
||||||
|
deployment, err := scaler.c.Deployments(namespace).Get(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return wait.Poll(waitForReplicas.Interval, waitForReplicas.Timeout,
|
||||||
|
client.DeploymentHasDesiredReplicas(scaler.c, deployment))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -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 {
|
func (c *ErrorDeployments) Update(deployment *extensions.Deployment) (*extensions.Deployment, error) {
|
||||||
// testclient.FakeScales
|
if c.invalid {
|
||||||
// invalid bool
|
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) {
|
func (c *ErrorDeployments) Get(name string) (*extensions.Deployment, error) {
|
||||||
// if c.invalid {
|
return &extensions.Deployment{
|
||||||
// return nil, kerrors.NewInvalid(extensions.Kind(scale.Kind), scale.Name, nil)
|
Spec: extensions.DeploymentSpec{
|
||||||
// }
|
Replicas: 0,
|
||||||
// return nil, errors.New("scale update failure")
|
},
|
||||||
// }
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// func (c *ErrorScales) Get(kind, name string) (*extensions.Scale, error) {
|
type ErrorDeploymentClient struct {
|
||||||
// return &extensions.Scale{
|
testclient.FakeExperimental
|
||||||
// Spec: extensions.ScaleSpec{
|
invalid bool
|
||||||
// Replicas: 0,
|
}
|
||||||
// },
|
|
||||||
// }, nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
// type ErrorDeployments struct {
|
func (c *ErrorDeploymentClient) Deployments(namespace string) client.DeploymentInterface {
|
||||||
// testclient.FakeDeployments
|
return &ErrorDeployments{testclient.FakeDeployments{Fake: &c.FakeExperimental, Namespace: namespace}, c.invalid}
|
||||||
// invalid bool
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// func (c *ErrorDeployments) Update(deployment *extensions.Deployment) (*extensions.Deployment, error) {
|
func TestDeploymentScaleRetry(t *testing.T) {
|
||||||
// if c.invalid {
|
fake := &ErrorDeploymentClient{FakeExperimental: testclient.FakeExperimental{Fake: &testclient.Fake{}}, invalid: false}
|
||||||
// return nil, kerrors.NewInvalid(extensions.Kind(deployment.Kind), deployment.Name, nil)
|
scaler := &DeploymentScaler{fake}
|
||||||
// }
|
preconditions := &ScalePrecondition{-1, ""}
|
||||||
// return nil, errors.New("deployment update failure")
|
count := uint(3)
|
||||||
// }
|
name := "foo"
|
||||||
|
namespace := "default"
|
||||||
|
|
||||||
// func (c *ErrorDeployments) Get(name string) (*extensions.Deployment, error) {
|
scaleFunc := ScaleCondition(scaler, preconditions, namespace, name, count)
|
||||||
// return &extensions.Deployment{
|
pass, err := scaleFunc()
|
||||||
// Spec: extensions.DeploymentSpec{
|
if pass != false {
|
||||||
// Replicas: 0,
|
t.Errorf("Expected an update failure to return pass = false, got pass = %v", pass)
|
||||||
// },
|
}
|
||||||
// }, nil
|
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 {
|
func TestDeploymentScale(t *testing.T) {
|
||||||
// testclient.FakeExperimental
|
fake := &testclient.FakeExperimental{Fake: &testclient.Fake{}}
|
||||||
// invalid bool
|
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 {
|
actions := fake.Actions()
|
||||||
// return &ErrorDeployments{testclient.FakeDeployments{Fake: &c.FakeExperimental, Namespace: namespace}, c.invalid}
|
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 {
|
func TestDeploymentScaleInvalid(t *testing.T) {
|
||||||
// return &ErrorScales{testclient.FakeScales{Fake: &c.FakeExperimental, Namespace: namespace}, c.invalid}
|
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) {
|
scaleFunc := ScaleCondition(&scaler, &preconditions, namespace, name, count)
|
||||||
// fake := &ErrorDeploymentClient{FakeExperimental: testclient.FakeExperimental{Fake: &testclient.Fake{}}, invalid: false}
|
pass, err := scaleFunc()
|
||||||
// scaler := &DeploymentScaler{fake}
|
if pass {
|
||||||
// preconditions := &ScalePrecondition{-1, ""}
|
t.Errorf("Expected an update failure to return pass = false, got pass = %v", pass)
|
||||||
// count := uint(3)
|
}
|
||||||
// name := "foo"
|
e, ok := err.(ScaleError)
|
||||||
// namespace := "default"
|
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)
|
func TestDeploymentScaleFailsPreconditions(t *testing.T) {
|
||||||
// pass, err := scaleFunc()
|
fake := testclient.NewSimpleFake(&extensions.Deployment{
|
||||||
// if pass != false {
|
Spec: extensions.DeploymentSpec{
|
||||||
// t.Errorf("Expected an update failure to return pass = false, got pass = %v", pass)
|
Replicas: 10,
|
||||||
// }
|
},
|
||||||
// if err != nil {
|
})
|
||||||
// t.Errorf("Did not expect an error on update failure, got %v", err)
|
scaler := DeploymentScaler{&testclient.FakeExperimental{fake}}
|
||||||
// }
|
preconditions := ScalePrecondition{2, ""}
|
||||||
// preconditions = &ScalePrecondition{3, ""}
|
count := uint(3)
|
||||||
// scaleFunc = ScaleCondition(scaler, preconditions, namespace, name, count)
|
name := "foo"
|
||||||
// pass, err = scaleFunc()
|
scaler.Scale("default", name, count, &preconditions, nil, nil)
|
||||||
// if err == nil {
|
|
||||||
// t.Errorf("Expected error on precondition failure")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func TestDeploymentScale(t *testing.T) {
|
actions := fake.Actions()
|
||||||
// fake := &testclient.FakeExperimental{Fake: &testclient.Fake{}}
|
if len(actions) != 1 {
|
||||||
// scaler := DeploymentScaler{fake}
|
t.Errorf("unexpected actions: %v, expected 1 actions (get)", actions)
|
||||||
// preconditions := ScalePrecondition{-1, ""}
|
}
|
||||||
// count := uint(3)
|
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "deployments" || action.GetName() != name {
|
||||||
// name := "foo"
|
t.Errorf("unexpected action: %v, expected get-deployment %s", actions[0], name)
|
||||||
// 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)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
func TestValidateDeployment(t *testing.T) {
|
func TestValidateDeployment(t *testing.T) {
|
||||||
zero, ten, twenty := 0, 10, 20
|
zero, ten, twenty := 0, 10, 20
|
||||||
|
|
|
@ -535,19 +535,6 @@ func TestDeploymentStop(t *testing.T) {
|
||||||
Replicas: 0,
|
Replicas: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
&extensions.Scale{ // UPDATE
|
|
||||||
ObjectMeta: api.ObjectMeta{
|
|
||||||
Name: name,
|
|
||||||
Namespace: ns,
|
|
||||||
},
|
|
||||||
Spec: extensions.ScaleSpec{
|
|
||||||
Replicas: 0,
|
|
||||||
},
|
|
||||||
Status: extensions.ScaleStatus{
|
|
||||||
Replicas: 0,
|
|
||||||
Selector: map[string]string{"k1": "v1"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
StopError: nil,
|
StopError: nil,
|
||||||
ExpectedActions: []string{"get:deployments", "update:deployments",
|
ExpectedActions: []string{"get:deployments", "update:deployments",
|
||||||
|
@ -558,19 +545,6 @@ func TestDeploymentStop(t *testing.T) {
|
||||||
Name: "Deployment with single replicaset",
|
Name: "Deployment with single replicaset",
|
||||||
Objs: []runtime.Object{
|
Objs: []runtime.Object{
|
||||||
&deployment, // GET
|
&deployment, // GET
|
||||||
&extensions.Scale{ // UPDATE
|
|
||||||
ObjectMeta: api.ObjectMeta{
|
|
||||||
Name: name,
|
|
||||||
Namespace: ns,
|
|
||||||
},
|
|
||||||
Spec: extensions.ScaleSpec{
|
|
||||||
Replicas: 0,
|
|
||||||
},
|
|
||||||
Status: extensions.ScaleStatus{
|
|
||||||
Replicas: 0,
|
|
||||||
Selector: map[string]string{"k1": "v1"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
&extensions.ReplicaSetList{ // LIST
|
&extensions.ReplicaSetList{ // LIST
|
||||||
Items: []extensions.ReplicaSet{
|
Items: []extensions.ReplicaSet{
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue