registry.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Copyright 2014 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 endpoint
  14. import (
  15. "k8s.io/kubernetes/pkg/api"
  16. "k8s.io/kubernetes/pkg/api/rest"
  17. "k8s.io/kubernetes/pkg/watch"
  18. )
  19. // Registry is an interface for things that know how to store endpoints.
  20. type Registry interface {
  21. ListEndpoints(ctx api.Context, options *api.ListOptions) (*api.EndpointsList, error)
  22. GetEndpoints(ctx api.Context, name string) (*api.Endpoints, error)
  23. WatchEndpoints(ctx api.Context, options *api.ListOptions) (watch.Interface, error)
  24. UpdateEndpoints(ctx api.Context, e *api.Endpoints) error
  25. DeleteEndpoints(ctx api.Context, name string) error
  26. }
  27. // storage puts strong typing around storage calls
  28. type storage struct {
  29. rest.StandardStorage
  30. }
  31. // NewRegistry returns a new Registry interface for the given Storage. Any mismatched
  32. // types will panic.
  33. func NewRegistry(s rest.StandardStorage) Registry {
  34. return &storage{s}
  35. }
  36. func (s *storage) ListEndpoints(ctx api.Context, options *api.ListOptions) (*api.EndpointsList, error) {
  37. obj, err := s.List(ctx, options)
  38. if err != nil {
  39. return nil, err
  40. }
  41. return obj.(*api.EndpointsList), nil
  42. }
  43. func (s *storage) WatchEndpoints(ctx api.Context, options *api.ListOptions) (watch.Interface, error) {
  44. return s.Watch(ctx, options)
  45. }
  46. func (s *storage) GetEndpoints(ctx api.Context, name string) (*api.Endpoints, error) {
  47. obj, err := s.Get(ctx, name)
  48. if err != nil {
  49. return nil, err
  50. }
  51. return obj.(*api.Endpoints), nil
  52. }
  53. func (s *storage) UpdateEndpoints(ctx api.Context, endpoints *api.Endpoints) error {
  54. _, _, err := s.Update(ctx, endpoints.Name, rest.DefaultUpdatedObjectInfo(endpoints, api.Scheme))
  55. return err
  56. }
  57. func (s *storage) DeleteEndpoints(ctx api.Context, name string) error {
  58. _, err := s.Delete(ctx, name, nil)
  59. return err
  60. }