mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
Add Validators for Scale Objects
This commit introduces a validator for use with Scale updates. The validator checks that we have > 0 replica count, as well as the normal ObjectMeta checks (some of which have to be faked since they don't exist on the Scale object).
This commit is contained in:
@@ -30,6 +30,8 @@ import (
|
||||
etcdgeneric "k8s.io/kubernetes/pkg/registry/generic/etcd"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/storage"
|
||||
|
||||
extvalidation "k8s.io/kubernetes/pkg/apis/extensions/validation"
|
||||
)
|
||||
|
||||
// DeploymentStorage includes dummy storage for Deployments and for Scale subresource.
|
||||
@@ -149,6 +151,11 @@ func (r *ScaleREST) Update(ctx api.Context, obj runtime.Object) (runtime.Object,
|
||||
if !ok {
|
||||
return nil, false, errors.NewBadRequest(fmt.Sprintf("wrong object passed to Scale update: %v", obj))
|
||||
}
|
||||
|
||||
if errs := extvalidation.ValidateScale(scale); len(errs) > 0 {
|
||||
return nil, false, errors.NewInvalid("scale", scale.Name, errs)
|
||||
}
|
||||
|
||||
deployment, err := (*r.registry).GetDeployment(ctx, scale.Name)
|
||||
if err != nil {
|
||||
return nil, false, errors.NewNotFound("scale", scale.Name)
|
||||
|
||||
Reference in New Issue
Block a user