Use storage directly for scale subresources

This commit is contained in:
Jordan Liggitt
2018-07-10 17:23:29 -04:00
parent 16c5ba4114
commit 3cb771a866
9 changed files with 97 additions and 62 deletions

View File

@@ -50,12 +50,11 @@ type ControllerStorage struct {
func NewStorage(optsGetter generic.RESTOptionsGetter) ControllerStorage {
controllerREST, statusREST := NewREST(optsGetter)
controllerRegistry := replicationcontroller.NewRegistry(controllerREST)
return ControllerStorage{
Controller: controllerREST,
Status: statusREST,
Scale: &ScaleREST{registry: controllerRegistry},
Scale: &ScaleREST{store: controllerREST.Store},
}
}
@@ -126,7 +125,7 @@ func (r *StatusREST) Update(ctx context.Context, name string, objInfo rest.Updat
}
type ScaleREST struct {
registry replicationcontroller.Registry
store *genericregistry.Store
}
// ScaleREST implements Patcher
@@ -148,22 +147,24 @@ func (r *ScaleREST) New() runtime.Object {
}
func (r *ScaleREST) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
rc, err := r.registry.GetController(ctx, name, options)
obj, err := r.store.Get(ctx, name, options)
if err != nil {
return nil, errors.NewNotFound(autoscaling.Resource("replicationcontrollers/scale"), name)
}
rc := obj.(*api.ReplicationController)
return scaleFromRC(rc), nil
}
func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
rc, err := r.registry.GetController(ctx, name, &metav1.GetOptions{})
obj, err := r.store.Get(ctx, name, &metav1.GetOptions{})
if err != nil {
return nil, false, errors.NewNotFound(autoscaling.Resource("replicationcontrollers/scale"), name)
}
rc := obj.(*api.ReplicationController)
oldScale := scaleFromRC(rc)
// TODO: should this pass validation?
obj, err := objInfo.UpdatedObject(ctx, oldScale)
obj, err = objInfo.UpdatedObject(ctx, oldScale)
if err != nil {
return nil, false, err
}
@@ -182,10 +183,11 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
rc.Spec.Replicas = scale.Spec.Replicas
rc.ResourceVersion = scale.ResourceVersion
rc, err = r.registry.UpdateController(ctx, rc, createValidation, updateValidation, options)
obj, _, err = r.store.Update(ctx, rc.Name, rest.DefaultUpdatedObjectInfo(rc), createValidation, updateValidation, false, options)
if err != nil {
return nil, false, err
}
rc = obj.(*api.ReplicationController)
return scaleFromRC(rc), false, nil
}