summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/apimachinery/pkg/api/meta
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/k8s.io/apimachinery/pkg/api/meta')
-rw-r--r--vendor/k8s.io/apimachinery/pkg/api/meta/default.go51
-rw-r--r--vendor/k8s.io/apimachinery/pkg/api/meta/errors.go20
-rw-r--r--vendor/k8s.io/apimachinery/pkg/api/meta/help.go3
-rw-r--r--vendor/k8s.io/apimachinery/pkg/api/meta/interfaces.go5
-rw-r--r--vendor/k8s.io/apimachinery/pkg/api/meta/lazy.go121
-rw-r--r--vendor/k8s.io/apimachinery/pkg/api/meta/meta.go73
-rw-r--r--vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go4
-rw-r--r--vendor/k8s.io/apimachinery/pkg/api/meta/priority.go2
-rw-r--r--vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go7
-rw-r--r--vendor/k8s.io/apimachinery/pkg/api/meta/unstructured.go18
10 files changed, 229 insertions, 75 deletions
diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/default.go b/vendor/k8s.io/apimachinery/pkg/api/meta/default.go
deleted file mode 100644
index 5ea906a2a..000000000
--- a/vendor/k8s.io/apimachinery/pkg/api/meta/default.go
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-Copyright 2015 The Kubernetes Authors.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package meta
-
-import (
- "strings"
-
- "k8s.io/apimachinery/pkg/runtime"
- "k8s.io/apimachinery/pkg/runtime/schema"
- "k8s.io/apimachinery/pkg/util/sets"
-)
-
-// NewDefaultRESTMapperFromScheme instantiates a DefaultRESTMapper based on types registered in the given scheme.
-func NewDefaultRESTMapperFromScheme(defaultGroupVersions []schema.GroupVersion, interfacesFunc VersionInterfacesFunc,
- importPathPrefix string, ignoredKinds, rootScoped sets.String, scheme *runtime.Scheme) *DefaultRESTMapper {
-
- mapper := NewDefaultRESTMapper(defaultGroupVersions, interfacesFunc)
- // enumerate all supported versions, get the kinds, and register with the mapper how to address
- // our resources.
- for _, gv := range defaultGroupVersions {
- for kind, oType := range scheme.KnownTypes(gv) {
- gvk := gv.WithKind(kind)
- // TODO: Remove import path check.
- // We check the import path because we currently stuff both "api" and "extensions" objects
- // into the same group within Scheme since Scheme has no notion of groups yet.
- if !strings.Contains(oType.PkgPath(), importPathPrefix) || ignoredKinds.Has(kind) {
- continue
- }
- scope := RESTScopeNamespace
- if rootScoped.Has(kind) {
- scope = RESTScopeRoot
- }
- mapper.Add(gvk, scope)
- }
- }
- return mapper
-}
diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/errors.go b/vendor/k8s.io/apimachinery/pkg/api/meta/errors.go
index 1503bd6d8..cbf5d0263 100644
--- a/vendor/k8s.io/apimachinery/pkg/api/meta/errors.go
+++ b/vendor/k8s.io/apimachinery/pkg/api/meta/errors.go
@@ -20,6 +20,7 @@ import (
"fmt"
"k8s.io/apimachinery/pkg/runtime/schema"
+ "k8s.io/apimachinery/pkg/util/sets"
)
// AmbiguousResourceError is returned if the RESTMapper finds multiple matches for a resource
@@ -85,11 +86,26 @@ func (e *NoResourceMatchError) Error() string {
// NoKindMatchError is returned if the RESTMapper can't find any match for a kind
type NoKindMatchError struct {
- PartialKind schema.GroupVersionKind
+ // GroupKind is the API group and kind that was searched
+ GroupKind schema.GroupKind
+ // SearchedVersions is the optional list of versions the search was restricted to
+ SearchedVersions []string
}
func (e *NoKindMatchError) Error() string {
- return fmt.Sprintf("no matches for %v", e.PartialKind)
+ searchedVersions := sets.NewString()
+ for _, v := range e.SearchedVersions {
+ searchedVersions.Insert(schema.GroupVersion{Group: e.GroupKind.Group, Version: v}.String())
+ }
+
+ switch len(searchedVersions) {
+ case 0:
+ return fmt.Sprintf("no matches for kind %q in group %q", e.GroupKind.Kind, e.GroupKind.Group)
+ case 1:
+ return fmt.Sprintf("no matches for kind %q in version %q", e.GroupKind.Kind, searchedVersions.List()[0])
+ default:
+ return fmt.Sprintf("no matches for kind %q in versions %q", e.GroupKind.Kind, searchedVersions.List())
+ }
}
func IsNoMatchError(err error) bool {
diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/help.go b/vendor/k8s.io/apimachinery/pkg/api/meta/help.go
index 9e0fb152a..c70b3d2b6 100644
--- a/vendor/k8s.io/apimachinery/pkg/api/meta/help.go
+++ b/vendor/k8s.io/apimachinery/pkg/api/meta/help.go
@@ -67,6 +67,9 @@ func GetItemsPtr(list runtime.Object) (interface{}, error) {
// EachListItem invokes fn on each runtime.Object in the list. Any error immediately terminates
// the loop.
func EachListItem(obj runtime.Object, fn func(runtime.Object) error) error {
+ if unstructured, ok := obj.(runtime.Unstructured); ok {
+ return unstructured.EachListItem(fn)
+ }
// TODO: Change to an interface call?
itemsPtr, err := GetItemsPtr(obj)
if err != nil {
diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/interfaces.go b/vendor/k8s.io/apimachinery/pkg/api/meta/interfaces.go
index b2c8c97b1..5dc9d89e6 100644
--- a/vendor/k8s.io/apimachinery/pkg/api/meta/interfaces.go
+++ b/vendor/k8s.io/apimachinery/pkg/api/meta/interfaces.go
@@ -36,7 +36,7 @@ type ListMetaAccessor interface {
// List lets you work with list metadata from any of the versioned or
// internal API objects. Attempting to set or retrieve a field on an object that does
// not support that field will be a no-op and return a default value.
-type List metav1.List
+type List metav1.ListInterface
// Type exposes the type and APIVersion of versioned or internal API objects.
type Type metav1.Type
@@ -75,6 +75,9 @@ type MetadataAccessor interface {
Annotations(obj runtime.Object) (map[string]string, error)
SetAnnotations(obj runtime.Object, annotations map[string]string) error
+ Continue(obj runtime.Object) (string, error)
+ SetContinue(obj runtime.Object, c string) error
+
runtime.ResourceVersioner
}
diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/lazy.go b/vendor/k8s.io/apimachinery/pkg/api/meta/lazy.go
new file mode 100644
index 000000000..7f92f39a4
--- /dev/null
+++ b/vendor/k8s.io/apimachinery/pkg/api/meta/lazy.go
@@ -0,0 +1,121 @@
+/*
+Copyright 2017 The Kubernetes Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package meta
+
+import (
+ "sync"
+
+ "k8s.io/apimachinery/pkg/runtime"
+ "k8s.io/apimachinery/pkg/runtime/schema"
+)
+
+// lazyObject defers loading the mapper and typer until necessary.
+type lazyObject struct {
+ loader func() (RESTMapper, runtime.ObjectTyper, error)
+
+ lock sync.Mutex
+ loaded bool
+ err error
+ mapper RESTMapper
+ typer runtime.ObjectTyper
+}
+
+// NewLazyObjectLoader handles unrecoverable errors when creating a RESTMapper / ObjectTyper by
+// returning those initialization errors when the interface methods are invoked. This defers the
+// initialization and any server calls until a client actually needs to perform the action.
+func NewLazyObjectLoader(fn func() (RESTMapper, runtime.ObjectTyper, error)) (RESTMapper, runtime.ObjectTyper) {
+ obj := &lazyObject{loader: fn}
+ return obj, obj
+}
+
+// init lazily loads the mapper and typer, returning an error if initialization has failed.
+func (o *lazyObject) init() error {
+ o.lock.Lock()
+ defer o.lock.Unlock()
+ if o.loaded {
+ return o.err
+ }
+ o.mapper, o.typer, o.err = o.loader()
+ o.loaded = true
+ return o.err
+}
+
+var _ RESTMapper = &lazyObject{}
+var _ runtime.ObjectTyper = &lazyObject{}
+
+func (o *lazyObject) KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error) {
+ if err := o.init(); err != nil {
+ return schema.GroupVersionKind{}, err
+ }
+ return o.mapper.KindFor(resource)
+}
+
+func (o *lazyObject) KindsFor(resource schema.GroupVersionResource) ([]schema.GroupVersionKind, error) {
+ if err := o.init(); err != nil {
+ return []schema.GroupVersionKind{}, err
+ }
+ return o.mapper.KindsFor(resource)
+}
+
+func (o *lazyObject) ResourceFor(input schema.GroupVersionResource) (schema.GroupVersionResource, error) {
+ if err := o.init(); err != nil {
+ return schema.GroupVersionResource{}, err
+ }
+ return o.mapper.ResourceFor(input)
+}
+
+func (o *lazyObject) ResourcesFor(input schema.GroupVersionResource) ([]schema.GroupVersionResource, error) {
+ if err := o.init(); err != nil {
+ return []schema.GroupVersionResource{}, err
+ }
+ return o.mapper.ResourcesFor(input)
+}
+
+func (o *lazyObject) RESTMapping(gk schema.GroupKind, versions ...string) (*RESTMapping, error) {
+ if err := o.init(); err != nil {
+ return nil, err
+ }
+ return o.mapper.RESTMapping(gk, versions...)
+}
+
+func (o *lazyObject) RESTMappings(gk schema.GroupKind, versions ...string) ([]*RESTMapping, error) {
+ if err := o.init(); err != nil {
+ return nil, err
+ }
+ return o.mapper.RESTMappings(gk, versions...)
+}
+
+func (o *lazyObject) ResourceSingularizer(resource string) (singular string, err error) {
+ if err := o.init(); err != nil {
+ return "", err
+ }
+ return o.mapper.ResourceSingularizer(resource)
+}
+
+func (o *lazyObject) ObjectKinds(obj runtime.Object) ([]schema.GroupVersionKind, bool, error) {
+ if err := o.init(); err != nil {
+ return nil, false, err
+ }
+ return o.typer.ObjectKinds(obj)
+}
+
+func (o *lazyObject) Recognizes(gvk schema.GroupVersionKind) bool {
+ if err := o.init(); err != nil {
+ return false
+ }
+ return o.typer.Recognizes(gvk)
+}
diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go b/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go
index 45d850ea8..b9670071c 100644
--- a/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go
+++ b/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go
@@ -23,7 +23,7 @@ import (
"github.com/golang/glog"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
- metav1alpha1 "k8s.io/apimachinery/pkg/apis/meta/v1alpha1"
+ metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -34,33 +34,59 @@ import (
// interfaces.
var errNotList = fmt.Errorf("object does not implement the List interfaces")
-// ListAccessor returns a List interface for the provided object or an error if the object does
+var errNotCommon = fmt.Errorf("object does not implement the common interface for accessing the SelfLink")
+
+// CommonAccessor returns a Common interface for the provided object or an error if the object does
// not provide List.
-// IMPORTANT: Objects are a superset of lists, so all Objects return List metadata. Do not use this
-// check to determine whether an object *is* a List.
// TODO: return bool instead of error
-func ListAccessor(obj interface{}) (List, error) {
+func CommonAccessor(obj interface{}) (metav1.Common, error) {
switch t := obj.(type) {
case List:
return t, nil
- case metav1.List:
+ case metav1.ListInterface:
return t, nil
case ListMetaAccessor:
if m := t.GetListMeta(); m != nil {
return m, nil
}
- return nil, errNotList
+ return nil, errNotCommon
case metav1.ListMetaAccessor:
if m := t.GetListMeta(); m != nil {
return m, nil
}
- return nil, errNotList
+ return nil, errNotCommon
case metav1.Object:
return t, nil
case metav1.ObjectMetaAccessor:
if m := t.GetObjectMeta(); m != nil {
return m, nil
}
+ return nil, errNotCommon
+ default:
+ return nil, errNotCommon
+ }
+}
+
+// ListAccessor returns a List interface for the provided object or an error if the object does
+// not provide List.
+// IMPORTANT: Objects are NOT a superset of lists. Do not use this check to determine whether an
+// object *is* a List.
+// TODO: return bool instead of error
+func ListAccessor(obj interface{}) (List, error) {
+ switch t := obj.(type) {
+ case List:
+ return t, nil
+ case metav1.ListInterface:
+ return t, nil
+ case ListMetaAccessor:
+ if m := t.GetListMeta(); m != nil {
+ return m, nil
+ }
+ return nil, errNotList
+ case metav1.ListMetaAccessor:
+ if m := t.GetListMeta(); m != nil {
+ return m, nil
+ }
return nil, errNotList
default:
return nil, errNotList
@@ -92,12 +118,12 @@ func Accessor(obj interface{}) (metav1.Object, error) {
// AsPartialObjectMetadata takes the metav1 interface and returns a partial object.
// TODO: consider making this solely a conversion action.
-func AsPartialObjectMetadata(m metav1.Object) *metav1alpha1.PartialObjectMetadata {
+func AsPartialObjectMetadata(m metav1.Object) *metav1beta1.PartialObjectMetadata {
switch t := m.(type) {
case *metav1.ObjectMeta:
- return &metav1alpha1.PartialObjectMetadata{ObjectMeta: *t}
+ return &metav1beta1.PartialObjectMetadata{ObjectMeta: *t}
default:
- return &metav1alpha1.PartialObjectMetadata{
+ return &metav1beta1.PartialObjectMetadata{
ObjectMeta: metav1.ObjectMeta{
Name: m.GetName(),
GenerateName: m.GetGenerateName(),
@@ -274,7 +300,7 @@ func (resourceAccessor) SetUID(obj runtime.Object, uid types.UID) error {
}
func (resourceAccessor) SelfLink(obj runtime.Object) (string, error) {
- accessor, err := ListAccessor(obj)
+ accessor, err := CommonAccessor(obj)
if err != nil {
return "", err
}
@@ -282,7 +308,7 @@ func (resourceAccessor) SelfLink(obj runtime.Object) (string, error) {
}
func (resourceAccessor) SetSelfLink(obj runtime.Object, selfLink string) error {
- accessor, err := ListAccessor(obj)
+ accessor, err := CommonAccessor(obj)
if err != nil {
return err
}
@@ -325,7 +351,7 @@ func (resourceAccessor) SetAnnotations(obj runtime.Object, annotations map[strin
}
func (resourceAccessor) ResourceVersion(obj runtime.Object) (string, error) {
- accessor, err := ListAccessor(obj)
+ accessor, err := CommonAccessor(obj)
if err != nil {
return "", err
}
@@ -333,7 +359,7 @@ func (resourceAccessor) ResourceVersion(obj runtime.Object) (string, error) {
}
func (resourceAccessor) SetResourceVersion(obj runtime.Object, version string) error {
- accessor, err := ListAccessor(obj)
+ accessor, err := CommonAccessor(obj)
if err != nil {
return err
}
@@ -341,6 +367,23 @@ func (resourceAccessor) SetResourceVersion(obj runtime.Object, version string) e
return nil
}
+func (resourceAccessor) Continue(obj runtime.Object) (string, error) {
+ accessor, err := ListAccessor(obj)
+ if err != nil {
+ return "", err
+ }
+ return accessor.GetContinue(), nil
+}
+
+func (resourceAccessor) SetContinue(obj runtime.Object, version string) error {
+ accessor, err := ListAccessor(obj)
+ if err != nil {
+ return err
+ }
+ accessor.SetContinue(version)
+ return nil
+}
+
// extractFromOwnerReference extracts v to o. v is the OwnerReferences field of an object.
func extractFromOwnerReference(v reflect.Value, o *metav1.OwnerReference) error {
if err := runtime.Field(v, "APIVersion", &o.APIVersion); err != nil {
diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go b/vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go
index 679098fe5..6b01bf197 100644
--- a/vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go
+++ b/vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go
@@ -179,7 +179,7 @@ func (m MultiRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*
if len(errors) > 0 {
return nil, utilerrors.NewAggregate(errors)
}
- return nil, &NoKindMatchError{PartialKind: gk.WithVersion("")}
+ return nil, &NoKindMatchError{GroupKind: gk, SearchedVersions: versions}
}
// RESTMappings returns all possible RESTMappings for the provided group kind, or an error
@@ -204,7 +204,7 @@ func (m MultiRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) (
return nil, utilerrors.NewAggregate(errors)
}
if len(allMappings) == 0 {
- return nil, &NoKindMatchError{PartialKind: gk.WithVersion("")}
+ return nil, &NoKindMatchError{GroupKind: gk, SearchedVersions: versions}
}
return allMappings, nil
}
diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/priority.go b/vendor/k8s.io/apimachinery/pkg/api/meta/priority.go
index 2a14aa7ab..df28e64ff 100644
--- a/vendor/k8s.io/apimachinery/pkg/api/meta/priority.go
+++ b/vendor/k8s.io/apimachinery/pkg/api/meta/priority.go
@@ -153,7 +153,7 @@ func kindMatches(pattern schema.GroupVersionKind, kind schema.GroupVersionKind)
}
func (m PriorityRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (mapping *RESTMapping, err error) {
- mappings, err := m.Delegate.RESTMappings(gk)
+ mappings, err := m.Delegate.RESTMappings(gk, versions...)
if err != nil {
return nil, err
}
diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go b/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go
index c6b2597dd..ff945acd1 100644
--- a/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go
+++ b/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go
@@ -117,7 +117,10 @@ func NewDefaultRESTMapper(defaultGroupVersions []schema.GroupVersion, f VersionI
func (m *DefaultRESTMapper) Add(kind schema.GroupVersionKind, scope RESTScope) {
plural, singular := UnsafeGuessKindToResource(kind)
+ m.AddSpecific(kind, plural, singular, scope)
+}
+func (m *DefaultRESTMapper) AddSpecific(kind schema.GroupVersionKind, plural, singular schema.GroupVersionResource, scope RESTScope) {
m.singularToPlural[singular] = plural
m.pluralToSingular[plural] = singular
@@ -469,7 +472,7 @@ func (m *DefaultRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string)
return nil, err
}
if len(mappings) == 0 {
- return nil, &NoKindMatchError{PartialKind: gk.WithVersion("")}
+ return nil, &NoKindMatchError{GroupKind: gk, SearchedVersions: versions}
}
// since we rely on RESTMappings method
// take the first match and return to the caller
@@ -507,7 +510,7 @@ func (m *DefaultRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string
}
if len(potentialGVK) == 0 {
- return nil, &NoKindMatchError{PartialKind: gk.WithVersion("")}
+ return nil, &NoKindMatchError{GroupKind: gk, SearchedVersions: versions}
}
for _, gvk := range potentialGVK {
diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/unstructured.go b/vendor/k8s.io/apimachinery/pkg/api/meta/unstructured.go
index 3ebf24815..4e13efea3 100644
--- a/vendor/k8s.io/apimachinery/pkg/api/meta/unstructured.go
+++ b/vendor/k8s.io/apimachinery/pkg/api/meta/unstructured.go
@@ -21,8 +21,24 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
)
+// InterfacesForUnstructuredConversion returns VersionInterfaces suitable for
+// dealing with unstructured.Unstructured objects and supports conversion
+// from typed objects (provided by parent) to untyped objects.
+func InterfacesForUnstructuredConversion(parent VersionInterfacesFunc) VersionInterfacesFunc {
+ return func(version schema.GroupVersion) (*VersionInterfaces, error) {
+ if i, err := parent(version); err == nil {
+ return &VersionInterfaces{
+ ObjectConvertor: i.ObjectConvertor,
+ MetadataAccessor: NewAccessor(),
+ }, nil
+ }
+ return InterfacesForUnstructured(version)
+ }
+}
+
// InterfacesForUnstructured returns VersionInterfaces suitable for
-// dealing with unstructured.Unstructured objects.
+// dealing with unstructured.Unstructured objects. It will return errors for
+// other conversions.
func InterfacesForUnstructured(schema.GroupVersion) (*VersionInterfaces, error) {
return &VersionInterfaces{
ObjectConvertor: &unstructured.UnstructuredObjectConverter{},