2 Copyright 2014 The Kubernetes Authors.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
22 "k8s.io/apimachinery/pkg/runtime/schema"
23 "k8s.io/apimachinery/pkg/util/sets"
26 // AmbiguousResourceError is returned if the RESTMapper finds multiple matches for a resource
27 type AmbiguousResourceError struct {
28 PartialResource schema.GroupVersionResource
30 MatchingResources []schema.GroupVersionResource
31 MatchingKinds []schema.GroupVersionKind
34 func (e *AmbiguousResourceError) Error() string {
36 case len(e.MatchingKinds) > 0 && len(e.MatchingResources) > 0:
37 return fmt.Sprintf("%v matches multiple resources %v and kinds %v", e.PartialResource, e.MatchingResources, e.MatchingKinds)
38 case len(e.MatchingKinds) > 0:
39 return fmt.Sprintf("%v matches multiple kinds %v", e.PartialResource, e.MatchingKinds)
40 case len(e.MatchingResources) > 0:
41 return fmt.Sprintf("%v matches multiple resources %v", e.PartialResource, e.MatchingResources)
43 return fmt.Sprintf("%v matches multiple resources or kinds", e.PartialResource)
46 // AmbiguousKindError is returned if the RESTMapper finds multiple matches for a kind
47 type AmbiguousKindError struct {
48 PartialKind schema.GroupVersionKind
50 MatchingResources []schema.GroupVersionResource
51 MatchingKinds []schema.GroupVersionKind
54 func (e *AmbiguousKindError) Error() string {
56 case len(e.MatchingKinds) > 0 && len(e.MatchingResources) > 0:
57 return fmt.Sprintf("%v matches multiple resources %v and kinds %v", e.PartialKind, e.MatchingResources, e.MatchingKinds)
58 case len(e.MatchingKinds) > 0:
59 return fmt.Sprintf("%v matches multiple kinds %v", e.PartialKind, e.MatchingKinds)
60 case len(e.MatchingResources) > 0:
61 return fmt.Sprintf("%v matches multiple resources %v", e.PartialKind, e.MatchingResources)
63 return fmt.Sprintf("%v matches multiple resources or kinds", e.PartialKind)
66 func IsAmbiguousError(err error) bool {
71 case *AmbiguousResourceError, *AmbiguousKindError:
78 // NoResourceMatchError is returned if the RESTMapper can't find any match for a resource
79 type NoResourceMatchError struct {
80 PartialResource schema.GroupVersionResource
83 func (e *NoResourceMatchError) Error() string {
84 return fmt.Sprintf("no matches for %v", e.PartialResource)
87 // NoKindMatchError is returned if the RESTMapper can't find any match for a kind
88 type NoKindMatchError struct {
89 // GroupKind is the API group and kind that was searched
90 GroupKind schema.GroupKind
91 // SearchedVersions is the optional list of versions the search was restricted to
92 SearchedVersions []string
95 func (e *NoKindMatchError) Error() string {
96 searchedVersions := sets.NewString()
97 for _, v := range e.SearchedVersions {
98 searchedVersions.Insert(schema.GroupVersion{Group: e.GroupKind.Group, Version: v}.String())
101 switch len(searchedVersions) {
103 return fmt.Sprintf("no matches for kind %q in group %q", e.GroupKind.Kind, e.GroupKind.Group)
105 return fmt.Sprintf("no matches for kind %q in version %q", e.GroupKind.Kind, searchedVersions.List()[0])
107 return fmt.Sprintf("no matches for kind %q in versions %q", e.GroupKind.Kind, searchedVersions.List())
111 func IsNoMatchError(err error) bool {
116 case *NoResourceMatchError, *NoKindMatchError: