storage.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. Copyright 2018 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. coordinationapi "k8s.io/kubernetes/pkg/apis/coordination"
  19. "k8s.io/kubernetes/pkg/printers"
  20. printersinternal "k8s.io/kubernetes/pkg/printers/internalversion"
  21. printerstorage "k8s.io/kubernetes/pkg/printers/storage"
  22. "k8s.io/kubernetes/pkg/registry/coordination/lease"
  23. )
  24. // REST implements a RESTStorage for leases against etcd
  25. type REST struct {
  26. *genericregistry.Store
  27. }
  28. // NewREST returns a RESTStorage object that will work against leases.
  29. func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, error) {
  30. store := &genericregistry.Store{
  31. NewFunc: func() runtime.Object { return &coordinationapi.Lease{} },
  32. NewListFunc: func() runtime.Object { return &coordinationapi.LeaseList{} },
  33. DefaultQualifiedResource: coordinationapi.Resource("leases"),
  34. CreateStrategy: lease.Strategy,
  35. UpdateStrategy: lease.Strategy,
  36. DeleteStrategy: lease.Strategy,
  37. TableConvertor: printerstorage.TableConvertor{TableGenerator: printers.NewTableGenerator().With(printersinternal.AddHandlers)},
  38. }
  39. options := &generic.StoreOptions{RESTOptions: optsGetter}
  40. if err := store.CompleteWithOptions(options); err != nil {
  41. return nil, err
  42. }
  43. return &REST{store}, nil
  44. }