storage.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Copyright 2015 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package storage
  14. import (
  15. "k8s.io/apimachinery/pkg/runtime"
  16. "k8s.io/apiserver/pkg/registry/generic"
  17. genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
  18. settingsapi "k8s.io/kubernetes/pkg/apis/settings"
  19. "k8s.io/kubernetes/pkg/registry/settings/podpreset"
  20. )
  21. // rest implements a RESTStorage for replication controllers against etcd
  22. type REST struct {
  23. *genericregistry.Store
  24. }
  25. // NewREST returns a RESTStorage object that will work against replication controllers.
  26. func NewREST(optsGetter generic.RESTOptionsGetter) *REST {
  27. store := &genericregistry.Store{
  28. NewFunc: func() runtime.Object { return &settingsapi.PodPreset{} },
  29. NewListFunc: func() runtime.Object { return &settingsapi.PodPresetList{} },
  30. DefaultQualifiedResource: settingsapi.Resource("podpresets"),
  31. CreateStrategy: podpreset.Strategy,
  32. UpdateStrategy: podpreset.Strategy,
  33. DeleteStrategy: podpreset.Strategy,
  34. }
  35. options := &generic.StoreOptions{RESTOptions: optsGetter}
  36. if err := store.CompleteWithOptions(options); err != nil {
  37. panic(err) // TODO: Propagate error up
  38. }
  39. return &REST{store}
  40. }