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
abf2c43a
Commit
abf2c43a
authored
Oct 14, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
attempt to use discovery RESTMapper and fallback if we can't
parent
928b8cbd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
34 deletions
+16
-34
factory.go
pkg/kubectl/cmd/util/factory.go
+16
-34
No files found.
pkg/kubectl/cmd/util/factory.go
View file @
abf2c43a
...
...
@@ -32,7 +32,6 @@ import (
"strings"
"time"
"github.com/blang/semver"
"github.com/emicklei/go-restful/swagger"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
...
...
@@ -334,26 +333,23 @@ func (f *factory) Object() (meta.RESTMapper, runtime.ObjectTyper) {
mapper
:=
registered
.
RESTMapper
()
discoveryClient
,
err
:=
discovery
.
NewDiscoveryClientForConfig
(
cfg
)
// if we can find the server version and it's current enough to have discovery information, use it. Otherwise,
// fallback to our hardcoded list
if
err
==
nil
{
if
serverVersion
,
err
:=
discoveryClient
.
ServerVersion
();
err
==
nil
&&
useDiscoveryRESTMapper
(
serverVersion
.
GitVersion
)
{
// register third party resources with the api machinery groups. This probably should be done, but
// its consistent with old code, so we'll start with it.
if
err
:=
registerThirdPartyResources
(
discoveryClient
);
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Unable to register third party resources: %v
\n
"
,
err
)
}
// ThirdPartyResourceData is special. It's not discoverable, but needed for thirdparty resource listing
// TODO eliminate this once we're truly generic.
thirdPartyResourceDataMapper
:=
meta
.
NewDefaultRESTMapper
([]
unversioned
.
GroupVersion
{
extensionsv1beta1
.
SchemeGroupVersion
},
registered
.
InterfacesFor
)
thirdPartyResourceDataMapper
.
Add
(
extensionsv1beta1
.
SchemeGroupVersion
.
WithKind
(
"ThirdPartyResourceData"
),
meta
.
RESTScopeNamespace
)
mapper
=
meta
.
FirstHitRESTMapper
{
MultiRESTMapper
:
meta
.
MultiRESTMapper
{
discovery
.
NewDeferredDiscoveryRESTMapper
(
discoveryClient
,
registered
.
InterfacesFor
),
thirdPartyResourceDataMapper
,
},
}
// register third party resources with the api machinery groups. This probably should be done, but
// its consistent with old code, so we'll start with it.
if
err
:=
registerThirdPartyResources
(
discoveryClient
);
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Unable to register third party resources: %v
\n
"
,
err
)
}
// ThirdPartyResourceData is special. It's not discoverable, but needed for thirdparty resource listing
// TODO eliminate this once we're truly generic.
thirdPartyResourceDataMapper
:=
meta
.
NewDefaultRESTMapper
([]
unversioned
.
GroupVersion
{
extensionsv1beta1
.
SchemeGroupVersion
},
registered
.
InterfacesFor
)
thirdPartyResourceDataMapper
.
Add
(
extensionsv1beta1
.
SchemeGroupVersion
.
WithKind
(
"ThirdPartyResourceData"
),
meta
.
RESTScopeNamespace
)
mapper
=
meta
.
FirstHitRESTMapper
{
MultiRESTMapper
:
meta
.
MultiRESTMapper
{
discovery
.
NewDeferredDiscoveryRESTMapper
(
discoveryClient
,
registered
.
InterfacesFor
),
thirdPartyResourceDataMapper
,
// needed for TPR printing
registered
.
RESTMapper
(),
// hardcoded fall back
},
}
}
...
...
@@ -1332,20 +1328,6 @@ func (f *factory) NewBuilder() *resource.Builder {
return
resource
.
NewBuilder
(
mapper
,
typer
,
resource
.
ClientMapperFunc
(
f
.
ClientForMapping
),
f
.
Decoder
(
true
))
}
// useDiscoveryRESTMapper checks the server version to see if its recent enough to have
// enough discovery information available to reliably build a RESTMapper. If not, use the
// hardcoded mapper in this client (legacy behavior)
func
useDiscoveryRESTMapper
(
serverVersion
string
)
bool
{
if
len
(
serverVersion
)
==
0
{
return
false
}
serverSemVer
,
err
:=
semver
.
Parse
(
serverVersion
[
1
:
])
if
err
!=
nil
{
return
false
}
return
serverSemVer
.
GE
(
semver
.
MustParse
(
"1.3.0"
))
}
// registerThirdPartyResources inspects the discovery endpoint to find thirdpartyresources in the discovery doc
// and then registers them with the apimachinery code. I think this is done so that scheme/codec stuff works,
// but I really don't know. Feels like this code should go away once kubectl is completely generic for generic
...
...
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