Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
4359c79f
Commit
4359c79f
authored
Sep 13, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add FirstHitRESTMapper for adding thirdparty resources
parent
500cddc5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
3 deletions
+112
-3
firsthit_restmapper.go
pkg/api/meta/firsthit_restmapper.go
+97
-0
restmapper.go
pkg/client/typed/discovery/restmapper.go
+9
-0
factory.go
pkg/kubectl/cmd/util/factory.go
+6
-3
No files found.
pkg/api/meta/firsthit_restmapper.go
0 → 100644
View file @
4359c79f
/*
Copyright 2014 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
(
"fmt"
"k8s.io/kubernetes/pkg/api/unversioned"
utilerrors
"k8s.io/kubernetes/pkg/util/errors"
)
// FirstHitRESTMapper is a wrapper for multiple RESTMappers which returns the
// first successful result for the singular requests
type
FirstHitRESTMapper
struct
{
MultiRESTMapper
}
func
(
m
FirstHitRESTMapper
)
String
()
string
{
return
fmt
.
Sprintf
(
"FirstHitRESTMapper{
\n\t
%v
\n
}"
,
m
.
MultiRESTMapper
)
}
func
(
m
FirstHitRESTMapper
)
ResourceFor
(
resource
unversioned
.
GroupVersionResource
)
(
unversioned
.
GroupVersionResource
,
error
)
{
errors
:=
[]
error
{}
for
_
,
t
:=
range
m
.
MultiRESTMapper
{
ret
,
err
:=
t
.
ResourceFor
(
resource
)
if
err
==
nil
{
return
ret
,
nil
}
errors
=
append
(
errors
,
err
)
}
return
unversioned
.
GroupVersionResource
{},
collapseAggregateErrors
(
errors
)
}
func
(
m
FirstHitRESTMapper
)
KindFor
(
resource
unversioned
.
GroupVersionResource
)
(
unversioned
.
GroupVersionKind
,
error
)
{
errors
:=
[]
error
{}
for
_
,
t
:=
range
m
.
MultiRESTMapper
{
ret
,
err
:=
t
.
KindFor
(
resource
)
if
err
==
nil
{
return
ret
,
nil
}
errors
=
append
(
errors
,
err
)
}
return
unversioned
.
GroupVersionKind
{},
collapseAggregateErrors
(
errors
)
}
// RESTMapping provides the REST mapping for the resource based on the
// kind and version. This implementation supports multiple REST schemas and
// return the first match.
func
(
m
FirstHitRESTMapper
)
RESTMapping
(
gk
unversioned
.
GroupKind
,
versions
...
string
)
(
*
RESTMapping
,
error
)
{
errors
:=
[]
error
{}
for
_
,
t
:=
range
m
.
MultiRESTMapper
{
ret
,
err
:=
t
.
RESTMapping
(
gk
,
versions
...
)
if
err
==
nil
{
return
ret
,
nil
}
errors
=
append
(
errors
,
err
)
}
return
nil
,
collapseAggregateErrors
(
errors
)
}
// collapseAggregateErrors returns the minimal errors. it handles empty as nil, handles one item in a list
// by returning the item, and collapses all NoMatchErrors to a single one (since they should all be the same)
func
collapseAggregateErrors
(
errors
[]
error
)
error
{
if
len
(
errors
)
==
0
{
return
nil
}
if
len
(
errors
)
==
1
{
return
errors
[
0
]
}
allNoMatchErrors
:=
true
for
_
,
err
:=
range
errors
{
allNoMatchErrors
=
allNoMatchErrors
&&
IsNoMatchError
(
err
)
}
if
allNoMatchErrors
{
return
errors
[
0
]
}
return
utilerrors
.
NewAggregate
(
errors
)
}
pkg/client/typed/discovery/restmapper.go
View file @
4359c79f
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
discovery
package
discovery
import
(
import
(
"fmt"
"sync"
"sync"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/errors"
...
@@ -259,5 +260,13 @@ func (d *DeferredDiscoveryRESTMapper) ResourceSingularizer(resource string) (sin
...
@@ -259,5 +260,13 @@ func (d *DeferredDiscoveryRESTMapper) ResourceSingularizer(resource string) (sin
return
del
.
ResourceSingularizer
(
resource
)
return
del
.
ResourceSingularizer
(
resource
)
}
}
func
(
d
*
DeferredDiscoveryRESTMapper
)
String
()
string
{
del
,
err
:=
d
.
getDelegate
()
if
err
!=
nil
{
return
fmt
.
Sprintf
(
"DeferredDiscoveryRESTMapper{%v}"
,
err
)
}
return
fmt
.
Sprintf
(
"DeferredDiscoveryRESTMapper{
\n\t
%v
\n
}"
,
del
)
}
// Make sure it satisfies the interface
// Make sure it satisfies the interface
var
_
meta
.
RESTMapper
=
&
DeferredDiscoveryRESTMapper
{}
var
_
meta
.
RESTMapper
=
&
DeferredDiscoveryRESTMapper
{}
pkg/kubectl/cmd/util/factory.go
View file @
4359c79f
...
@@ -315,9 +315,12 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -315,9 +315,12 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
// TODO eliminate this once we're truly generic.
// TODO eliminate this once we're truly generic.
thirdPartyResourceDataMapper
:=
meta
.
NewDefaultRESTMapper
([]
unversioned
.
GroupVersion
{
extensionsv1beta1
.
SchemeGroupVersion
},
registered
.
InterfacesFor
)
thirdPartyResourceDataMapper
:=
meta
.
NewDefaultRESTMapper
([]
unversioned
.
GroupVersion
{
extensionsv1beta1
.
SchemeGroupVersion
},
registered
.
InterfacesFor
)
thirdPartyResourceDataMapper
.
Add
(
extensionsv1beta1
.
SchemeGroupVersion
.
WithKind
(
"ThirdPartyResourceData"
),
meta
.
RESTScopeNamespace
)
thirdPartyResourceDataMapper
.
Add
(
extensionsv1beta1
.
SchemeGroupVersion
.
WithKind
(
"ThirdPartyResourceData"
),
meta
.
RESTScopeNamespace
)
mapper
=
meta
.
MultiRESTMapper
{
discovery
.
NewDeferredDiscoveryRESTMapper
(
discoveryClient
,
registered
.
InterfacesFor
),
mapper
=
meta
.
FirstHitRESTMapper
{
thirdPartyResourceDataMapper
,
MultiRESTMapper
:
meta
.
MultiRESTMapper
{
discovery
.
NewDeferredDiscoveryRESTMapper
(
discoveryClient
,
registered
.
InterfacesFor
),
thirdPartyResourceDataMapper
,
},
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment