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
66eecb96
Commit
66eecb96
authored
Dec 01, 2015
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update more kubectl bits for groupversion
parent
33eda2ff
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
129 additions
and
94 deletions
+129
-94
latest.go
pkg/api/latest/latest.go
+6
-0
client.go
pkg/client/unversioned/client.go
+9
-8
client_test.go
pkg/client/unversioned/client_test.go
+4
-3
latest.go
pkg/client/unversioned/clientcmd/api/latest/latest.go
+3
-0
testclient.go
pkg/client/unversioned/testclient/testclient.go
+7
-2
autoscale.go
pkg/kubectl/cmd/autoscale.go
+1
-1
view.go
pkg/kubectl/cmd/config/view.go
+4
-9
convert.go
pkg/kubectl/cmd/convert.go
+5
-6
edit.go
pkg/kubectl/cmd/edit.go
+7
-3
explain.go
pkg/kubectl/cmd/explain.go
+13
-4
expose.go
pkg/kubectl/cmd/expose.go
+1
-1
get.go
pkg/kubectl/cmd/get.go
+5
-2
get_test.go
pkg/kubectl/cmd/get_test.go
+1
-1
factory.go
pkg/kubectl/cmd/util/factory.go
+23
-21
factory_test.go
pkg/kubectl/cmd/util/factory_test.go
+3
-3
printing.go
pkg/kubectl/cmd/util/printing.go
+10
-14
explain.go
pkg/kubectl/explain.go
+3
-2
kubectl.go
pkg/kubectl/kubectl.go
+14
-4
resource_printer.go
pkg/kubectl/resource_printer.go
+8
-8
resource_printer_test.go
pkg/kubectl/resource_printer_test.go
+2
-2
No files found.
pkg/api/latest/latest.go
View file @
66eecb96
...
@@ -42,6 +42,12 @@ var (
...
@@ -42,6 +42,12 @@ var (
IsRegistered
=
allGroups
.
IsRegistered
IsRegistered
=
allGroups
.
IsRegistered
)
)
// ExternalVersions is a list of all external versions for this API group in order of
// most preferred to least preferred
var
ExternalVersions
=
[]
unversioned
.
GroupVersion
{
{
Group
:
""
,
Version
:
"v1"
},
}
// GroupMetaMap is a map between group names and their metadata.
// GroupMetaMap is a map between group names and their metadata.
type
GroupMetaMap
map
[
string
]
*
GroupMeta
type
GroupMetaMap
map
[
string
]
*
GroupMeta
...
...
pkg/client/unversioned/client.go
View file @
66eecb96
...
@@ -27,6 +27,7 @@ import (
...
@@ -27,6 +27,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/version"
"k8s.io/kubernetes/pkg/version"
)
)
...
@@ -183,12 +184,12 @@ func (c *Client) ValidateComponents() (*api.ComponentStatusList, error) {
...
@@ -183,12 +184,12 @@ func (c *Client) ValidateComponents() (*api.ComponentStatusList, error) {
// SwaggerSchemaInterface has a method to retrieve the swagger schema. Used in
// SwaggerSchemaInterface has a method to retrieve the swagger schema. Used in
// client.Interface
// client.Interface
type
SwaggerSchemaInterface
interface
{
type
SwaggerSchemaInterface
interface
{
SwaggerSchema
(
groupVersion
string
)
(
*
swagger
.
ApiDeclaration
,
error
)
SwaggerSchema
(
version
unversioned
.
GroupVersion
)
(
*
swagger
.
ApiDeclaration
,
error
)
}
}
// SwaggerSchema retrieves and parses the swagger API schema the server supports.
// SwaggerSchema retrieves and parses the swagger API schema the server supports.
func
(
c
*
Client
)
SwaggerSchema
(
groupVersion
string
)
(
*
swagger
.
ApiDeclaration
,
error
)
{
func
(
c
*
Client
)
SwaggerSchema
(
version
unversioned
.
GroupVersion
)
(
*
swagger
.
ApiDeclaration
,
error
)
{
if
groupVersion
==
""
{
if
version
.
IsEmpty
()
{
return
nil
,
fmt
.
Errorf
(
"groupVersion cannot be empty"
)
return
nil
,
fmt
.
Errorf
(
"groupVersion cannot be empty"
)
}
}
...
@@ -198,14 +199,14 @@ func (c *Client) SwaggerSchema(groupVersion string) (*swagger.ApiDeclaration, er
...
@@ -198,14 +199,14 @@ func (c *Client) SwaggerSchema(groupVersion string) (*swagger.ApiDeclaration, er
}
}
groupVersions
:=
ExtractGroupVersions
(
groupList
)
groupVersions
:=
ExtractGroupVersions
(
groupList
)
// This check also takes care the case that kubectl is newer than the running endpoint
// This check also takes care the case that kubectl is newer than the running endpoint
if
stringDoesntExistIn
(
groupVersion
,
groupVersions
)
{
if
stringDoesntExistIn
(
version
.
String
()
,
groupVersions
)
{
return
nil
,
fmt
.
Errorf
(
"API version: %
s is not supported by the server. Use one of: %v"
,
groupV
ersion
,
groupVersions
)
return
nil
,
fmt
.
Errorf
(
"API version: %
v is not supported by the server. Use one of: %v"
,
v
ersion
,
groupVersions
)
}
}
var
path
string
var
path
string
if
groupVersion
==
"v1"
{
if
version
==
v1
.
SchemeGroupVersion
{
path
=
"/swaggerapi/api/"
+
group
Version
path
=
"/swaggerapi/api/"
+
version
.
Version
}
else
{
}
else
{
path
=
"/swaggerapi/apis/"
+
group
Version
path
=
"/swaggerapi/apis/"
+
version
.
Group
+
"/"
+
version
.
Version
}
}
body
,
err
:=
c
.
Get
()
.
AbsPath
(
path
)
.
Do
()
.
Raw
()
body
,
err
:=
c
.
Get
()
.
AbsPath
(
path
)
.
Do
()
.
Raw
()
...
...
pkg/client/unversioned/client_test.go
View file @
66eecb96
...
@@ -31,6 +31,7 @@ import (
...
@@ -31,6 +31,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
...
@@ -496,7 +497,7 @@ func TestGetSwaggerSchema(t *testing.T) {
...
@@ -496,7 +497,7 @@ func TestGetSwaggerSchema(t *testing.T) {
}
}
client
:=
NewOrDie
(
&
Config
{
Host
:
server
.
URL
})
client
:=
NewOrDie
(
&
Config
{
Host
:
server
.
URL
})
got
,
err
:=
client
.
SwaggerSchema
(
"v1"
)
got
,
err
:=
client
.
SwaggerSchema
(
v1
.
SchemeGroupVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected encoding error: %v"
,
err
)
t
.
Fatalf
(
"unexpected encoding error: %v"
,
err
)
}
}
...
@@ -506,7 +507,7 @@ func TestGetSwaggerSchema(t *testing.T) {
...
@@ -506,7 +507,7 @@ func TestGetSwaggerSchema(t *testing.T) {
}
}
func
TestGetSwaggerSchemaFail
(
t
*
testing
.
T
)
{
func
TestGetSwaggerSchemaFail
(
t
*
testing
.
T
)
{
expErr
:=
"API version: v4 is not supported by the server. Use one of: [v1 v2 v3]"
expErr
:=
"API version:
api.group/
v4 is not supported by the server. Use one of: [v1 v2 v3]"
server
,
err
:=
swaggerSchemaFakeServer
()
server
,
err
:=
swaggerSchemaFakeServer
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -514,7 +515,7 @@ func TestGetSwaggerSchemaFail(t *testing.T) {
...
@@ -514,7 +515,7 @@ func TestGetSwaggerSchemaFail(t *testing.T) {
}
}
client
:=
NewOrDie
(
&
Config
{
Host
:
server
.
URL
})
client
:=
NewOrDie
(
&
Config
{
Host
:
server
.
URL
})
got
,
err
:=
client
.
SwaggerSchema
(
"v4"
)
got
,
err
:=
client
.
SwaggerSchema
(
unversioned
.
GroupVersion
{
Group
:
"api.group"
,
Version
:
"v4"
}
)
if
got
!=
nil
{
if
got
!=
nil
{
t
.
Fatalf
(
"unexpected response: %v"
,
got
)
t
.
Fatalf
(
"unexpected response: %v"
,
got
)
}
}
...
...
pkg/client/unversioned/clientcmd/api/latest/latest.go
View file @
66eecb96
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
latest
package
latest
import
(
import
(
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api/v1"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api/v1"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
)
)
...
@@ -24,6 +25,8 @@ import (
...
@@ -24,6 +25,8 @@ import (
// Version is the string that represents the current external default version.
// Version is the string that represents the current external default version.
const
Version
=
"v1"
const
Version
=
"v1"
var
ExternalVersion
=
unversioned
.
GroupVersion
{
Group
:
""
,
Version
:
"v1"
}
// OldestVersion is the string that represents the oldest server version supported,
// OldestVersion is the string that represents the oldest server version supported,
// for client code that wants to hardcode the lowest common denominator.
// for client code that wants to hardcode the lowest common denominator.
const
OldestVersion
=
"v1"
const
OldestVersion
=
"v1"
...
...
pkg/client/unversioned/testclient/testclient.go
View file @
66eecb96
...
@@ -25,6 +25,7 @@ import (
...
@@ -25,6 +25,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/registered"
"k8s.io/kubernetes/pkg/api/registered"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/version"
"k8s.io/kubernetes/pkg/version"
...
@@ -306,10 +307,14 @@ func (c *Fake) ComponentStatuses() client.ComponentStatusInterface {
...
@@ -306,10 +307,14 @@ func (c *Fake) ComponentStatuses() client.ComponentStatusInterface {
}
}
// SwaggerSchema returns an empty swagger.ApiDeclaration for testing
// SwaggerSchema returns an empty swagger.ApiDeclaration for testing
func
(
c
*
Fake
)
SwaggerSchema
(
version
string
)
(
*
swagger
.
ApiDeclaration
,
error
)
{
func
(
c
*
Fake
)
SwaggerSchema
(
version
unversioned
.
GroupVersion
)
(
*
swagger
.
ApiDeclaration
,
error
)
{
action
:=
ActionImpl
{}
action
:=
ActionImpl
{}
action
.
Verb
=
"get"
action
.
Verb
=
"get"
action
.
Resource
=
"/swaggerapi/api/"
+
version
if
version
==
v1
.
SchemeGroupVersion
{
action
.
Resource
=
"/swaggerapi/api/"
+
version
.
Version
}
else
{
action
.
Resource
=
"/swaggerapi/apis/"
+
version
.
Group
+
"/"
+
version
.
Version
}
c
.
Invokes
(
action
,
nil
)
c
.
Invokes
(
action
,
nil
)
return
&
swagger
.
ApiDeclaration
{},
nil
return
&
swagger
.
ApiDeclaration
{},
nil
...
...
pkg/kubectl/cmd/autoscale.go
View file @
66eecb96
...
@@ -95,7 +95,7 @@ func RunAutoscale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
...
@@ -95,7 +95,7 @@ func RunAutoscale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
}
}
info
:=
infos
[
0
]
info
:=
infos
[
0
]
mapping
:=
info
.
ResourceMapping
()
mapping
:=
info
.
ResourceMapping
()
if
err
:=
f
.
CanBeAutoscaled
(
mapping
.
GroupVersionKind
.
Kind
);
err
!=
nil
{
if
err
:=
f
.
CanBeAutoscaled
(
mapping
.
GroupVersionKind
.
GroupKind
()
);
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/kubectl/cmd/config/view.go
View file @
66eecb96
...
@@ -21,7 +21,6 @@ import (
...
@@ -21,7 +21,6 @@ import (
"fmt"
"fmt"
"io"
"io"
"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
...
@@ -70,16 +69,12 @@ func NewCmdConfigView(out io.Writer, ConfigAccess ConfigAccess) *cobra.Command {
...
@@ -70,16 +69,12 @@ func NewCmdConfigView(out io.Writer, ConfigAccess ConfigAccess) *cobra.Command {
}
}
printer
,
_
,
err
:=
cmdutil
.
PrinterForCommand
(
cmd
)
printer
,
_
,
err
:=
cmdutil
.
PrinterForCommand
(
cmd
)
if
err
!=
nil
{
cmdutil
.
CheckErr
(
err
)
glog
.
FatalDepth
(
1
,
err
)
version
,
err
:=
cmdutil
.
OutputVersion
(
cmd
,
&
latest
.
ExternalVersion
)
}
cmdutil
.
CheckErr
(
err
)
version
:=
cmdutil
.
OutputVersion
(
cmd
,
latest
.
Version
)
printer
=
kubectl
.
NewVersionedPrinter
(
printer
,
clientcmdapi
.
Scheme
,
version
)
printer
=
kubectl
.
NewVersionedPrinter
(
printer
,
clientcmdapi
.
Scheme
,
version
)
if
err
:=
options
.
Run
(
out
,
printer
);
err
!=
nil
{
cmdutil
.
CheckErr
(
options
.
Run
(
out
,
printer
))
glog
.
FatalDepth
(
1
,
err
)
}
},
},
}
}
...
...
pkg/kubectl/cmd/convert.go
View file @
66eecb96
...
@@ -90,17 +90,16 @@ type ConvertOptions struct {
...
@@ -90,17 +90,16 @@ type ConvertOptions struct {
out
io
.
Writer
out
io
.
Writer
printer
kubectl
.
ResourcePrinter
printer
kubectl
.
ResourcePrinter
outputVersion
string
outputVersion
unversioned
.
GroupVersion
}
}
// Complete collects information required to run Convert command from command line.
// Complete collects information required to run Convert command from command line.
func
(
o
*
ConvertOptions
)
Complete
(
f
*
cmdutil
.
Factory
,
out
io
.
Writer
,
cmd
*
cobra
.
Command
,
args
[]
string
)
(
err
error
)
{
func
(
o
*
ConvertOptions
)
Complete
(
f
*
cmdutil
.
Factory
,
out
io
.
Writer
,
cmd
*
cobra
.
Command
,
args
[]
string
)
(
err
error
)
{
o
.
outputVersion
=
cmdutil
.
OutputVersion
(
cmd
,
latest
.
GroupOrDie
(
""
)
.
GroupVersion
.
Version
)
o
.
outputVersion
,
err
=
cmdutil
.
OutputVersion
(
cmd
,
&
latest
.
ExternalVersions
[
0
])
outputGV
,
err
:=
unversioned
.
ParseGroupVersion
(
o
.
outputVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to parse group/version from %q: %v"
,
o
.
outputVersion
,
err
)
return
err
}
}
if
!
registered
.
IsRegisteredAPIGroupVersion
(
o
utputGV
)
{
if
!
registered
.
IsRegisteredAPIGroupVersion
(
o
.
outputVersion
)
{
cmdutil
.
UsageError
(
cmd
,
"'%s' is not a registered version."
,
o
.
outputVersion
)
cmdutil
.
UsageError
(
cmd
,
"'%s' is not a registered version."
,
o
.
outputVersion
)
}
}
...
@@ -152,7 +151,7 @@ func (o *ConvertOptions) RunConvert() error {
...
@@ -152,7 +151,7 @@ func (o *ConvertOptions) RunConvert() error {
return
err
return
err
}
}
objects
,
err
:=
resource
.
AsVersionedObject
(
infos
,
false
,
o
.
outputVersion
)
objects
,
err
:=
resource
.
AsVersionedObject
(
infos
,
false
,
o
.
outputVersion
.
String
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/kubectl/cmd/edit.go
View file @
66eecb96
...
@@ -28,6 +28,7 @@ import (
...
@@ -28,6 +28,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
...
@@ -149,10 +150,13 @@ func RunEdit(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
...
@@ -149,10 +150,13 @@ func RunEdit(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
windowsLineEndings
:=
cmdutil
.
GetFlagBool
(
cmd
,
"windows-line-endings"
)
windowsLineEndings
:=
cmdutil
.
GetFlagBool
(
cmd
,
"windows-line-endings"
)
edit
:=
editor
.
NewDefaultEditor
(
f
.
EditorEnvs
())
edit
:=
editor
.
NewDefaultEditor
(
f
.
EditorEnvs
())
defaultVersion
:=
cmdutil
.
OutputVersionFromGroupVersion
(
cmd
,
clientConfig
.
GroupVersion
)
defaultVersion
,
err
:=
cmdutil
.
OutputVersion
(
cmd
,
clientConfig
.
GroupVersion
)
if
err
!=
nil
{
return
err
}
results
:=
editResults
{}
results
:=
editResults
{}
for
{
for
{
objs
,
err
:=
resource
.
AsVersionedObjects
(
infos
,
defaultVersion
)
objs
,
err
:=
resource
.
AsVersionedObjects
(
infos
,
defaultVersion
.
String
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
preservedFile
(
err
,
results
.
file
,
out
)
return
preservedFile
(
err
,
results
.
file
,
out
)
}
}
...
@@ -356,7 +360,7 @@ type editResults struct {
...
@@ -356,7 +360,7 @@ type editResults struct {
edit
[]
*
resource
.
Info
edit
[]
*
resource
.
Info
file
string
file
string
version
string
version
unversioned
.
GroupVersion
}
}
func
(
r
*
editResults
)
addError
(
err
error
,
info
*
resource
.
Info
)
string
{
func
(
r
*
editResults
)
addError
(
err
error
,
info
*
resource
.
Info
)
string
{
...
...
pkg/kubectl/cmd/explain.go
View file @
66eecb96
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
)
)
...
@@ -70,7 +71,8 @@ func RunExplain(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
...
@@ -70,7 +71,8 @@ func RunExplain(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
}
}
recursive
:=
cmdutil
.
GetFlagBool
(
cmd
,
"recursive"
)
recursive
:=
cmdutil
.
GetFlagBool
(
cmd
,
"recursive"
)
apiV
:=
cmdutil
.
GetFlagString
(
cmd
,
"api-version"
)
apiVersionString
:=
cmdutil
.
GetFlagString
(
cmd
,
"api-version"
)
apiVersion
:=
unversioned
.
GroupVersion
{}
mapper
,
_
:=
f
.
Object
()
mapper
,
_
:=
f
.
Object
()
// TODO: After we figured out the new syntax to separate group and resource, allow
// TODO: After we figured out the new syntax to separate group and resource, allow
...
@@ -87,14 +89,21 @@ func RunExplain(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
...
@@ -87,14 +89,21 @@ func RunExplain(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
return
err
return
err
}
}
if
len
(
apiV
)
==
0
{
if
len
(
apiV
ersionString
)
==
0
{
groupMeta
,
err
:=
latest
.
Group
(
gvk
.
Group
)
groupMeta
,
err
:=
latest
.
Group
(
gvk
.
Group
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
apiV
=
groupMeta
.
GroupVersion
.
String
()
apiVersion
=
groupMeta
.
GroupVersion
}
else
{
apiVersion
,
err
=
unversioned
.
ParseGroupVersion
(
apiVersionString
)
if
err
!=
nil
{
return
nil
}
}
}
swagSchema
,
err
:=
kubectl
.
GetSwaggerSchema
(
apiV
,
client
)
swagSchema
,
err
:=
kubectl
.
GetSwaggerSchema
(
apiVersion
,
client
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/kubectl/cmd/expose.go
View file @
66eecb96
...
@@ -120,7 +120,7 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
...
@@ -120,7 +120,7 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
}
}
info
:=
infos
[
0
]
info
:=
infos
[
0
]
mapping
:=
info
.
ResourceMapping
()
mapping
:=
info
.
ResourceMapping
()
if
err
:=
f
.
CanBeExposed
(
mapping
.
GroupVersionKind
.
Kind
);
err
!=
nil
{
if
err
:=
f
.
CanBeExposed
(
mapping
.
GroupVersionKind
.
GroupKind
()
);
err
!=
nil
{
return
err
return
err
}
}
// Get the input object
// Get the input object
...
...
pkg/kubectl/cmd/get.go
View file @
66eecb96
...
@@ -209,8 +209,11 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
...
@@ -209,8 +209,11 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
// the outermost object will be converted to the output-version, but inner
// the outermost object will be converted to the output-version, but inner
// objects can use their mappings
// objects can use their mappings
version
:=
cmdutil
.
OutputVersionFromGroupVersion
(
cmd
,
clientConfig
.
GroupVersion
)
version
,
err
:=
cmdutil
.
OutputVersion
(
cmd
,
clientConfig
.
GroupVersion
)
obj
,
err
:=
resource
.
AsVersionedObject
(
infos
,
!
singular
,
version
)
if
err
!=
nil
{
return
err
}
obj
,
err
:=
resource
.
AsVersionedObject
(
infos
,
!
singular
,
version
.
String
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/kubectl/cmd/get_test.go
View file @
66eecb96
...
@@ -164,7 +164,7 @@ func TestGetUnknownSchemaObjectListGeneric(t *testing.T) {
...
@@ -164,7 +164,7 @@ func TestGetUnknownSchemaObjectListGeneric(t *testing.T) {
rcVersion
:
testapi
.
Default
.
Version
(),
rcVersion
:
testapi
.
Default
.
Version
(),
},
},
"handles second specific version"
:
{
"handles second specific version"
:
{
outputVersion
:
"unlikelyversion"
,
outputVersion
:
"unlikely
.group/unlikely
version"
,
listVersion
:
testapi
.
Default
.
Version
(),
listVersion
:
testapi
.
Default
.
Version
(),
testtypeVersion
:
unlikelyGV
.
String
(),
testtypeVersion
:
unlikelyGV
.
String
(),
rcVersion
:
testapi
.
Default
.
Version
(),
// see expected behavior 3b
rcVersion
:
testapi
.
Default
.
Version
(),
// see expected behavior 3b
...
...
pkg/kubectl/cmd/util/factory.go
View file @
66eecb96
...
@@ -95,9 +95,9 @@ type Factory struct {
...
@@ -95,9 +95,9 @@ type Factory struct {
// Returns the generator for the provided generator name
// Returns the generator for the provided generator name
Generator
func
(
name
string
)
(
kubectl
.
Generator
,
bool
)
Generator
func
(
name
string
)
(
kubectl
.
Generator
,
bool
)
// Check whether the kind of resources could be exposed
// Check whether the kind of resources could be exposed
CanBeExposed
func
(
kind
string
)
error
CanBeExposed
func
(
kind
unversioned
.
GroupKind
)
error
// Check whether the kind of resources could be autoscaled
// Check whether the kind of resources could be autoscaled
CanBeAutoscaled
func
(
kind
string
)
error
CanBeAutoscaled
func
(
kind
unversioned
.
GroupKind
)
error
// AttachablePodForObject returns the pod to which to attach given an object.
// AttachablePodForObject returns the pod to which to attach given an object.
AttachablePodForObject
func
(
object
runtime
.
Object
)
(
*
api
.
Pod
,
error
)
AttachablePodForObject
func
(
object
runtime
.
Object
)
(
*
api
.
Pod
,
error
)
// EditorEnvs returns a group of environment variables that the edit command
// EditorEnvs returns a group of environment variables that the edit command
...
@@ -140,12 +140,12 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -140,12 +140,12 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
Object
:
func
()
(
meta
.
RESTMapper
,
runtime
.
ObjectTyper
)
{
Object
:
func
()
(
meta
.
RESTMapper
,
runtime
.
ObjectTyper
)
{
cfg
,
err
:=
clientConfig
.
ClientConfig
()
cfg
,
err
:=
clientConfig
.
ClientConfig
()
CheckErr
(
err
)
CheckErr
(
err
)
cmdApiVersion
:=
""
cmdApiVersion
:=
unversioned
.
GroupVersion
{}
if
cfg
.
GroupVersion
!=
nil
{
if
cfg
.
GroupVersion
!=
nil
{
cmdApiVersion
=
cfg
.
GroupVersion
.
String
()
cmdApiVersion
=
*
cfg
.
GroupVersion
}
}
return
kubectl
.
OutputVersionMapper
{
RESTMapper
:
mapper
,
OutputVersion
:
cmdApiVersion
},
api
.
Scheme
return
kubectl
.
OutputVersionMapper
{
RESTMapper
:
mapper
,
OutputVersion
s
:
[]
unversioned
.
GroupVersion
{
cmdApiVersion
}
},
api
.
Scheme
},
},
Client
:
func
()
(
*
client
.
Client
,
error
)
{
Client
:
func
()
(
*
client
.
Client
,
error
)
{
return
clients
.
ClientForVersion
(
""
)
return
clients
.
ClientForVersion
(
""
)
...
@@ -163,9 +163,9 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -163,9 +163,9 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
nil
,
err
return
nil
,
err
}
}
switch
gvk
.
Group
{
switch
gvk
.
Group
{
case
""
:
case
api
.
SchemeGroupVersion
.
Group
:
return
client
.
RESTClient
,
nil
return
client
.
RESTClient
,
nil
case
"extensions"
:
case
extensions
.
SchemeGroupVersion
.
Group
:
return
client
.
ExtensionsClient
.
RESTClient
,
nil
return
client
.
ExtensionsClient
.
RESTClient
,
nil
}
}
return
nil
,
fmt
.
Errorf
(
"unable to get RESTClient for resource '%s'"
,
mapping
.
Resource
)
return
nil
,
fmt
.
Errorf
(
"unable to get RESTClient for resource '%s'"
,
mapping
.
Resource
)
...
@@ -290,21 +290,21 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -290,21 +290,21 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
generator
,
ok
:=
generators
[
name
]
generator
,
ok
:=
generators
[
name
]
return
generator
,
ok
return
generator
,
ok
},
},
CanBeExposed
:
func
(
kind
string
)
error
{
CanBeExposed
:
func
(
kind
unversioned
.
GroupKind
)
error
{
switch
kind
{
switch
kind
{
case
"ReplicationController"
,
"Service"
,
"Pod"
:
case
api
.
Kind
(
"ReplicationController"
),
api
.
Kind
(
"Service"
),
api
.
Kind
(
"Pod"
)
:
// nothing to do here
// nothing to do here
default
:
default
:
return
fmt
.
Errorf
(
"cannot expose a %s"
,
kind
)
return
fmt
.
Errorf
(
"cannot expose a %s"
,
kind
)
}
}
return
nil
return
nil
},
},
CanBeAutoscaled
:
func
(
kind
string
)
error
{
CanBeAutoscaled
:
func
(
kind
unversioned
.
GroupKind
)
error
{
switch
kind
{
switch
kind
{
case
"ReplicationController"
,
"Deployment"
:
case
api
.
Kind
(
"ReplicationController"
),
extensions
.
Kind
(
"Deployment"
)
:
// nothing to do here
// nothing to do here
default
:
default
:
return
fmt
.
Errorf
(
"cannot autoscale a %
s
"
,
kind
)
return
fmt
.
Errorf
(
"cannot autoscale a %
v
"
,
kind
)
}
}
return
nil
return
nil
},
},
...
@@ -604,19 +604,20 @@ func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMappin
...
@@ -604,19 +604,20 @@ func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMappin
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
defaultVersion
:=
""
if
clientConfig
.
GroupVersion
!=
nil
{
defaultVersion
=
clientConfig
.
GroupVersion
.
String
()
}
version
:=
OutputVersion
(
cmd
,
defaultVersion
)
version
,
err
:=
OutputVersion
(
cmd
,
clientConfig
.
GroupVersion
)
if
len
(
version
)
==
0
{
if
err
!=
nil
{
version
=
mapping
.
GroupVersionKind
.
GroupVersion
()
.
String
()
return
nil
,
err
}
if
version
.
IsEmpty
()
{
version
=
mapping
.
GroupVersionKind
.
GroupVersion
()
}
}
if
len
(
version
)
==
0
{
if
version
.
IsEmpty
()
{
return
nil
,
fmt
.
Errorf
(
"you must specify an output-version when using this output format"
)
return
nil
,
fmt
.
Errorf
(
"you must specify an output-version when using this output format"
)
}
}
printer
=
kubectl
.
NewVersionedPrinter
(
printer
,
mapping
.
ObjectConvertor
,
version
,
mapping
.
GroupVersionKind
.
GroupVersion
()
.
String
())
printer
=
kubectl
.
NewVersionedPrinter
(
printer
,
mapping
.
ObjectConvertor
,
version
,
mapping
.
GroupVersionKind
.
GroupVersion
())
}
else
{
}
else
{
// Some callers do not have "label-columns" so we can't use the GetFlagStringSlice() helper
// Some callers do not have "label-columns" so we can't use the GetFlagStringSlice() helper
columnLabel
,
err
:=
cmd
.
Flags
()
.
GetStringSlice
(
"label-columns"
)
columnLabel
,
err
:=
cmd
.
Flags
()
.
GetStringSlice
(
"label-columns"
)
...
@@ -629,6 +630,7 @@ func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMappin
...
@@ -629,6 +630,7 @@ func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMappin
}
}
printer
=
maybeWrapSortingPrinter
(
cmd
,
printer
)
printer
=
maybeWrapSortingPrinter
(
cmd
,
printer
)
}
}
return
printer
,
nil
return
printer
,
nil
}
}
...
...
pkg/kubectl/cmd/util/factory_test.go
View file @
66eecb96
...
@@ -170,15 +170,15 @@ func TestLabelsForObject(t *testing.T) {
...
@@ -170,15 +170,15 @@ func TestLabelsForObject(t *testing.T) {
func
TestCanBeExposed
(
t
*
testing
.
T
)
{
func
TestCanBeExposed
(
t
*
testing
.
T
)
{
factory
:=
NewFactory
(
nil
)
factory
:=
NewFactory
(
nil
)
tests
:=
[]
struct
{
tests
:=
[]
struct
{
kind
string
kind
unversioned
.
GroupKind
expectErr
bool
expectErr
bool
}{
}{
{
{
kind
:
"ReplicationController"
,
kind
:
api
.
Kind
(
"ReplicationController"
)
,
expectErr
:
false
,
expectErr
:
false
,
},
},
{
{
kind
:
"Node"
,
kind
:
api
.
Kind
(
"Node"
)
,
expectErr
:
true
,
expectErr
:
true
,
},
},
}
}
...
...
pkg/kubectl/cmd/util/printing.go
View file @
66eecb96
...
@@ -76,22 +76,18 @@ func ValidateOutputArgs(cmd *cobra.Command) error {
...
@@ -76,22 +76,18 @@ func ValidateOutputArgs(cmd *cobra.Command) error {
}
}
// OutputVersion returns the preferred output version for generic content (JSON, YAML, or templates)
// OutputVersion returns the preferred output version for generic content (JSON, YAML, or templates)
// TODO, when this has no callers, replace it with OutputVersionFromGroupVersion. Also this shoudl return a GroupVersion
// defaultVersion is never mutated. Nil simply allows clean passing in common usage from client.Config
func
OutputVersion
(
cmd
*
cobra
.
Command
,
defaultVersion
string
)
string
{
func
OutputVersion
(
cmd
*
cobra
.
Command
,
defaultVersion
*
unversioned
.
GroupVersion
)
(
unversioned
.
GroupVersion
,
error
)
{
outputVersion
:=
GetFlagString
(
cmd
,
"output-version"
)
outputVersionString
:=
GetFlagString
(
cmd
,
"output-version"
)
if
len
(
outputVersion
)
==
0
{
if
len
(
outputVersionString
)
==
0
{
outputVersion
=
defaultVersion
if
defaultVersion
==
nil
{
}
return
unversioned
.
GroupVersion
{},
nil
return
outputVersion
}
}
// OutputVersionFromGroupVersion returns the preferred output version for generic content (JSON, YAML, or templates)
return
*
defaultVersion
,
nil
func
OutputVersionFromGroupVersion
(
cmd
*
cobra
.
Command
,
defaultGV
*
unversioned
.
GroupVersion
)
string
{
outputVersion
:=
GetFlagString
(
cmd
,
"output-version"
)
if
len
(
outputVersion
)
==
0
&&
defaultGV
!=
nil
{
outputVersion
=
defaultGV
.
String
()
}
}
return
outputVersion
return
unversioned
.
ParseGroupVersion
(
outputVersionString
)
}
}
// PrinterForCommand returns the default printer for this command.
// PrinterForCommand returns the default printer for this command.
...
...
pkg/kubectl/explain.go
View file @
66eecb96
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"github.com/emicklei/go-restful/swagger"
"github.com/emicklei/go-restful/swagger"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/unversioned"
apiutil
"k8s.io/kubernetes/pkg/api/util"
apiutil
"k8s.io/kubernetes/pkg/api/util"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
)
)
...
@@ -32,8 +33,8 @@ var allModels = make(map[string]*swagger.NamedModel)
...
@@ -32,8 +33,8 @@ var allModels = make(map[string]*swagger.NamedModel)
var
recursive
=
false
// this is global for convenience, can become int for multiple levels
var
recursive
=
false
// this is global for convenience, can become int for multiple levels
// GetSwaggerSchema returns the swagger spec from master
// GetSwaggerSchema returns the swagger spec from master
func
GetSwaggerSchema
(
apiVer
string
,
kubeClient
client
.
Interface
)
(
*
swagger
.
ApiDeclaration
,
error
)
{
func
GetSwaggerSchema
(
version
unversioned
.
GroupVersion
,
kubeClient
client
.
Interface
)
(
*
swagger
.
ApiDeclaration
,
error
)
{
swaggerSchema
,
err
:=
kubeClient
.
SwaggerSchema
(
apiVer
)
swaggerSchema
,
err
:=
kubeClient
.
SwaggerSchema
(
version
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"couldn't read swagger schema from server: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"couldn't read swagger schema from server: %v"
,
err
)
}
}
...
...
pkg/kubectl/kubectl.go
View file @
66eecb96
...
@@ -47,14 +47,24 @@ func makeImageList(spec *api.PodSpec) string {
...
@@ -47,14 +47,24 @@ func makeImageList(spec *api.PodSpec) string {
// correspond to a preferred output version (if feasible)
// correspond to a preferred output version (if feasible)
type
OutputVersionMapper
struct
{
type
OutputVersionMapper
struct
{
meta
.
RESTMapper
meta
.
RESTMapper
OutputVersion
string
// output versions takes a list of preferred GroupVersions. Only the first
// hit for a given group will have effect. This allows different output versions
// depending upon the group of the kind being requested
OutputVersions
[]
unversioned
.
GroupVersion
}
}
// RESTMapping implements meta.RESTMapper by prepending the output version to the preferred version list.
// RESTMapping implements meta.RESTMapper by prepending the output version to the preferred version list.
func
(
m
OutputVersionMapper
)
RESTMapping
(
gk
unversioned
.
GroupKind
,
versions
...
string
)
(
*
meta
.
RESTMapping
,
error
)
{
func
(
m
OutputVersionMapper
)
RESTMapping
(
gk
unversioned
.
GroupKind
,
versions
...
string
)
(
*
meta
.
RESTMapping
,
error
)
{
mapping
,
err
:=
m
.
RESTMapper
.
RESTMapping
(
gk
,
m
.
OutputVersion
)
for
_
,
preferredVersion
:=
range
m
.
OutputVersions
{
if
err
==
nil
{
if
gk
.
Group
==
preferredVersion
.
Group
{
return
mapping
,
nil
mapping
,
err
:=
m
.
RESTMapper
.
RESTMapping
(
gk
,
preferredVersion
.
Version
)
if
err
==
nil
{
return
mapping
,
nil
}
break
}
}
}
return
m
.
RESTMapper
.
RESTMapping
(
gk
,
versions
...
)
return
m
.
RESTMapper
.
RESTMapping
(
gk
,
versions
...
)
...
...
pkg/kubectl/resource_printer.go
View file @
66eecb96
...
@@ -157,28 +157,28 @@ func (fn ResourcePrinterFunc) HandledResources() []string {
...
@@ -157,28 +157,28 @@ func (fn ResourcePrinterFunc) HandledResources() []string {
type
VersionedPrinter
struct
{
type
VersionedPrinter
struct
{
printer
ResourcePrinter
printer
ResourcePrinter
convertor
runtime
.
ObjectConvertor
convertor
runtime
.
ObjectConvertor
version
[]
string
version
s
[]
unversioned
.
GroupVersion
}
}
// NewVersionedPrinter wraps a printer to convert objects to a known API version prior to printing.
// NewVersionedPrinter wraps a printer to convert objects to a known API version prior to printing.
func
NewVersionedPrinter
(
printer
ResourcePrinter
,
convertor
runtime
.
ObjectConvertor
,
version
...
string
)
ResourcePrinter
{
func
NewVersionedPrinter
(
printer
ResourcePrinter
,
convertor
runtime
.
ObjectConvertor
,
version
s
...
unversioned
.
GroupVersion
)
ResourcePrinter
{
return
&
VersionedPrinter
{
return
&
VersionedPrinter
{
printer
:
printer
,
printer
:
printer
,
convertor
:
convertor
,
convertor
:
convertor
,
version
:
version
,
version
s
:
versions
,
}
}
}
}
// PrintObj implements ResourcePrinter
// PrintObj implements ResourcePrinter
func
(
p
*
VersionedPrinter
)
PrintObj
(
obj
runtime
.
Object
,
w
io
.
Writer
)
error
{
func
(
p
*
VersionedPrinter
)
PrintObj
(
obj
runtime
.
Object
,
w
io
.
Writer
)
error
{
if
len
(
p
.
version
)
==
0
{
if
len
(
p
.
version
s
)
==
0
{
return
fmt
.
Errorf
(
"no version specified, object cannot be converted"
)
return
fmt
.
Errorf
(
"no version specified, object cannot be converted"
)
}
}
for
_
,
version
:=
range
p
.
version
{
for
_
,
version
:=
range
p
.
version
s
{
if
len
(
version
)
==
0
{
if
version
.
IsEmpty
()
{
continue
continue
}
}
converted
,
err
:=
p
.
convertor
.
ConvertToVersion
(
obj
,
version
)
converted
,
err
:=
p
.
convertor
.
ConvertToVersion
(
obj
,
version
.
String
()
)
if
conversion
.
IsNotRegisteredError
(
err
)
{
if
conversion
.
IsNotRegisteredError
(
err
)
{
continue
continue
}
}
...
@@ -187,7 +187,7 @@ func (p *VersionedPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
...
@@ -187,7 +187,7 @@ func (p *VersionedPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
}
}
return
p
.
printer
.
PrintObj
(
converted
,
w
)
return
p
.
printer
.
PrintObj
(
converted
,
w
)
}
}
return
fmt
.
Errorf
(
"the object cannot be converted to any of the versions: %v"
,
p
.
version
)
return
fmt
.
Errorf
(
"the object cannot be converted to any of the versions: %v"
,
p
.
version
s
)
}
}
// TODO: implement HandledResources()
// TODO: implement HandledResources()
...
...
pkg/kubectl/resource_printer_test.go
View file @
66eecb96
...
@@ -64,7 +64,7 @@ func TestVersionedPrinter(t *testing.T) {
...
@@ -64,7 +64,7 @@ func TestVersionedPrinter(t *testing.T) {
return
nil
return
nil
}),
}),
api
.
Scheme
,
api
.
Scheme
,
testapi
.
Default
.
Version
(),
*
testapi
.
Default
.
Group
Version
(),
)
)
if
err
:=
p
.
PrintObj
(
original
,
nil
);
err
!=
nil
{
if
err
:=
p
.
PrintObj
(
original
,
nil
);
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
...
@@ -422,7 +422,7 @@ func TestTemplateStrings(t *testing.T) {
...
@@ -422,7 +422,7 @@ func TestTemplateStrings(t *testing.T) {
t
.
Fatalf
(
"tmpl fail: %v"
,
err
)
t
.
Fatalf
(
"tmpl fail: %v"
,
err
)
}
}
printer
:=
NewVersionedPrinter
(
p
,
api
.
Scheme
,
testapi
.
Default
.
Version
())
printer
:=
NewVersionedPrinter
(
p
,
api
.
Scheme
,
*
testapi
.
Default
.
Group
Version
())
for
name
,
item
:=
range
table
{
for
name
,
item
:=
range
table
{
buffer
:=
&
bytes
.
Buffer
{}
buffer
:=
&
bytes
.
Buffer
{}
...
...
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