interface.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. Copyright 2016 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 dynamic
  14. import (
  15. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  16. "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
  17. "k8s.io/apimachinery/pkg/runtime/schema"
  18. "k8s.io/apimachinery/pkg/types"
  19. "k8s.io/apimachinery/pkg/watch"
  20. )
  21. type Interface interface {
  22. Resource(resource schema.GroupVersionResource) NamespaceableResourceInterface
  23. }
  24. type ResourceInterface interface {
  25. Create(obj *unstructured.Unstructured, subresources ...string) (*unstructured.Unstructured, error)
  26. Update(obj *unstructured.Unstructured, subresources ...string) (*unstructured.Unstructured, error)
  27. UpdateStatus(obj *unstructured.Unstructured) (*unstructured.Unstructured, error)
  28. Delete(name string, options *metav1.DeleteOptions, subresources ...string) error
  29. DeleteCollection(options *metav1.DeleteOptions, listOptions metav1.ListOptions) error
  30. Get(name string, options metav1.GetOptions, subresources ...string) (*unstructured.Unstructured, error)
  31. List(opts metav1.ListOptions) (*unstructured.UnstructuredList, error)
  32. Watch(opts metav1.ListOptions) (watch.Interface, error)
  33. Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*unstructured.Unstructured, error)
  34. }
  35. type NamespaceableResourceInterface interface {
  36. Namespace(string) ResourceInterface
  37. ResourceInterface
  38. }
  39. // APIPathResolverFunc knows how to convert a groupVersion to its API path. The Kind field is optional.
  40. // TODO find a better place to move this for existing callers
  41. type APIPathResolverFunc func(kind schema.GroupVersionKind) string
  42. // LegacyAPIPathResolverFunc can resolve paths properly with the legacy API.
  43. // TODO find a better place to move this for existing callers
  44. func LegacyAPIPathResolverFunc(kind schema.GroupVersionKind) string {
  45. if len(kind.Group) == 0 {
  46. return "/api"
  47. }
  48. return "/apis"
  49. }