blob: 42eac3af001465537432cf7d3ec723f5a258eca0 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001/*
2Copyright 2014 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package meta
18
19import (
20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21 "k8s.io/apimachinery/pkg/runtime"
22 "k8s.io/apimachinery/pkg/runtime/schema"
23 "k8s.io/apimachinery/pkg/types"
24)
25
26type ListMetaAccessor interface {
27 GetListMeta() List
28}
29
30// List lets you work with list metadata from any of the versioned or
31// internal API objects. Attempting to set or retrieve a field on an object that does
32// not support that field will be a no-op and return a default value.
33type List metav1.ListInterface
34
35// Type exposes the type and APIVersion of versioned or internal API objects.
36type Type metav1.Type
37
38// MetadataAccessor lets you work with object and list metadata from any of the versioned or
39// internal API objects. Attempting to set or retrieve a field on an object that does
40// not support that field (Name, UID, Namespace on lists) will be a no-op and return
41// a default value.
42//
43// MetadataAccessor exposes Interface in a way that can be used with multiple objects.
44type MetadataAccessor interface {
45 APIVersion(obj runtime.Object) (string, error)
46 SetAPIVersion(obj runtime.Object, version string) error
47
48 Kind(obj runtime.Object) (string, error)
49 SetKind(obj runtime.Object, kind string) error
50
51 Namespace(obj runtime.Object) (string, error)
52 SetNamespace(obj runtime.Object, namespace string) error
53
54 Name(obj runtime.Object) (string, error)
55 SetName(obj runtime.Object, name string) error
56
57 GenerateName(obj runtime.Object) (string, error)
58 SetGenerateName(obj runtime.Object, name string) error
59
60 UID(obj runtime.Object) (types.UID, error)
61 SetUID(obj runtime.Object, uid types.UID) error
62
63 SelfLink(obj runtime.Object) (string, error)
64 SetSelfLink(obj runtime.Object, selfLink string) error
65
66 Labels(obj runtime.Object) (map[string]string, error)
67 SetLabels(obj runtime.Object, labels map[string]string) error
68
69 Annotations(obj runtime.Object) (map[string]string, error)
70 SetAnnotations(obj runtime.Object, annotations map[string]string) error
71
72 Continue(obj runtime.Object) (string, error)
73 SetContinue(obj runtime.Object, c string) error
74
75 runtime.ResourceVersioner
76}
77
78type RESTScopeName string
79
80const (
81 RESTScopeNameNamespace RESTScopeName = "namespace"
82 RESTScopeNameRoot RESTScopeName = "root"
83)
84
85// RESTScope contains the information needed to deal with REST resources that are in a resource hierarchy
86type RESTScope interface {
87 // Name of the scope
88 Name() RESTScopeName
89}
90
91// RESTMapping contains the information needed to deal with objects of a specific
92// resource and kind in a RESTful manner.
93type RESTMapping struct {
94 // Resource is the GroupVersionResource (location) for this endpoint
95 Resource schema.GroupVersionResource
96
97 // GroupVersionKind is the GroupVersionKind (data format) to submit to this endpoint
98 GroupVersionKind schema.GroupVersionKind
99
100 // Scope contains the information needed to deal with REST Resources that are in a resource hierarchy
101 Scope RESTScope
102}
103
104// RESTMapper allows clients to map resources to kind, and map kind and version
105// to interfaces for manipulating those objects. It is primarily intended for
106// consumers of Kubernetes compatible REST APIs as defined in docs/devel/api-conventions.md.
107//
108// The Kubernetes API provides versioned resources and object kinds which are scoped
109// to API groups. In other words, kinds and resources should not be assumed to be
110// unique across groups.
111//
112// TODO: split into sub-interfaces
113type RESTMapper interface {
114 // KindFor takes a partial resource and returns the single match. Returns an error if there are multiple matches
115 KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error)
116
117 // KindsFor takes a partial resource and returns the list of potential kinds in priority order
118 KindsFor(resource schema.GroupVersionResource) ([]schema.GroupVersionKind, error)
119
120 // ResourceFor takes a partial resource and returns the single match. Returns an error if there are multiple matches
121 ResourceFor(input schema.GroupVersionResource) (schema.GroupVersionResource, error)
122
123 // ResourcesFor takes a partial resource and returns the list of potential resource in priority order
124 ResourcesFor(input schema.GroupVersionResource) ([]schema.GroupVersionResource, error)
125
126 // RESTMapping identifies a preferred resource mapping for the provided group kind.
127 RESTMapping(gk schema.GroupKind, versions ...string) (*RESTMapping, error)
128 // RESTMappings returns all resource mappings for the provided group kind if no
129 // version search is provided. Otherwise identifies a preferred resource mapping for
130 // the provided version(s).
131 RESTMappings(gk schema.GroupKind, versions ...string) ([]*RESTMapping, error)
132
133 ResourceSingularizer(resource string) (singular string, err error)
134}