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
b12f6b34
Commit
b12f6b34
authored
Dec 19, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #18599 from smarterclayton/abstract_explain
Auto commit by PR queue bot
parents
3c3a24e1
151b4e59
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
21 deletions
+31
-21
test-cmd.sh
hack/test-cmd.sh
+11
-0
explain.go
pkg/kubectl/cmd/explain.go
+2
-7
factory.go
pkg/kubectl/cmd/util/factory.go
+10
-0
explain.go
pkg/kubectl/explain.go
+3
-14
kubectl.go
pkg/kubectl/kubectl.go
+5
-0
No files found.
hack/test-cmd.sh
View file @
b12f6b34
...
@@ -1292,6 +1292,17 @@ __EOF__
...
@@ -1292,6 +1292,17 @@ __EOF__
###########
###########
# Explain #
###########
kube::log::status
"Testing kubectl(
${
version
}
:explain)"
kubectl explain pods
# shortcuts work
kubectl explain po
kubectl explain po.status.message
###########
# Swagger #
# Swagger #
###########
###########
...
...
pkg/kubectl/cmd/explain.go
View file @
b12f6b34
...
@@ -65,11 +65,6 @@ func RunExplain(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
...
@@ -65,11 +65,6 @@ func RunExplain(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
return
cmdutil
.
UsageError
(
cmd
,
"We accept only this format: explain RESOURCE"
)
return
cmdutil
.
UsageError
(
cmd
,
"We accept only this format: explain RESOURCE"
)
}
}
client
,
err
:=
f
.
Client
()
if
err
!=
nil
{
return
err
}
recursive
:=
cmdutil
.
GetFlagBool
(
cmd
,
"recursive"
)
recursive
:=
cmdutil
.
GetFlagBool
(
cmd
,
"recursive"
)
apiVersionString
:=
cmdutil
.
GetFlagString
(
cmd
,
"api-version"
)
apiVersionString
:=
cmdutil
.
GetFlagString
(
cmd
,
"api-version"
)
apiVersion
:=
unversioned
.
GroupVersion
{}
apiVersion
:=
unversioned
.
GroupVersion
{}
...
@@ -103,10 +98,10 @@ func RunExplain(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
...
@@ -103,10 +98,10 @@ func RunExplain(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
}
}
}
}
s
wagSchema
,
err
:=
kubectl
.
GetSwaggerSchema
(
apiVersion
,
client
)
s
chema
,
err
:=
f
.
SwaggerSchema
(
apiVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
return
kubectl
.
PrintModelDescription
(
inModel
,
fieldsPath
,
out
,
s
wagS
chema
,
recursive
)
return
kubectl
.
PrintModelDescription
(
inModel
,
fieldsPath
,
out
,
schema
,
recursive
)
}
}
pkg/kubectl/cmd/util/factory.go
View file @
b12f6b34
...
@@ -29,6 +29,7 @@ import (
...
@@ -29,6 +29,7 @@ import (
"strconv"
"strconv"
"time"
"time"
"github.com/emicklei/go-restful/swagger"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/pflag"
...
@@ -88,6 +89,8 @@ type Factory struct {
...
@@ -88,6 +89,8 @@ type Factory struct {
LogsForObject
func
(
object
,
options
runtime
.
Object
)
(
*
client
.
Request
,
error
)
LogsForObject
func
(
object
,
options
runtime
.
Object
)
(
*
client
.
Request
,
error
)
// Returns a schema that can validate objects stored on disk.
// Returns a schema that can validate objects stored on disk.
Validator
func
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
Validator
func
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
// SwaggerSchema returns the schema declaration for the provided group version.
SwaggerSchema
func
(
unversioned
.
GroupVersion
)
(
*
swagger
.
ApiDeclaration
,
error
)
// Returns the default namespace to use in cases where no
// Returns the default namespace to use in cases where no
// other namespace is specified and whether the namespace was
// other namespace is specified and whether the namespace was
// overriden.
// overriden.
...
@@ -304,6 +307,13 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -304,6 +307,13 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
}
}
return
validation
.
NullSchema
{},
nil
return
validation
.
NullSchema
{},
nil
},
},
SwaggerSchema
:
func
(
version
unversioned
.
GroupVersion
)
(
*
swagger
.
ApiDeclaration
,
error
)
{
client
,
err
:=
clients
.
ClientForVersion
(
&
version
)
if
err
!=
nil
{
return
nil
,
err
}
return
client
.
SwaggerSchema
(
version
)
},
DefaultNamespace
:
func
()
(
string
,
bool
,
error
)
{
DefaultNamespace
:
func
()
(
string
,
bool
,
error
)
{
return
clientConfig
.
Namespace
()
return
clientConfig
.
Namespace
()
},
},
...
...
pkg/kubectl/explain.go
View file @
b12f6b34
...
@@ -24,27 +24,16 @@ import (
...
@@ -24,27 +24,16 @@ 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"
)
)
var
allModels
=
make
(
map
[
string
]
*
swagger
.
NamedModel
)
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
func
GetSwaggerSchema
(
version
unversioned
.
GroupVersion
,
kubeClient
client
.
Interface
)
(
*
swagger
.
ApiDeclaration
,
error
)
{
swaggerSchema
,
err
:=
kubeClient
.
SwaggerSchema
(
version
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"couldn't read swagger schema from server: %v"
,
err
)
}
return
swaggerSchema
,
nil
}
// SplitAndParseResourceRequest separates the users input into a model and fields
// SplitAndParseResourceRequest separates the users input into a model and fields
func
SplitAndParseResourceRequest
(
inResource
string
,
mapper
meta
.
RESTMapper
)
(
string
,
[]
string
,
error
)
{
func
SplitAndParseResourceRequest
(
inResource
string
,
mapper
meta
.
RESTMapper
)
(
string
,
[]
string
,
error
)
{
inResource
,
fieldsPath
:=
splitDotNotation
(
inResource
)
inResource
,
fieldsPath
:=
splitDotNotation
(
inResource
)
inResource
,
_
=
mapper
.
ResourceSingularizer
(
expandResourceShortcut
(
inResource
)
)
inResource
,
_
=
mapper
.
ResourceSingularizer
(
inResource
)
return
inResource
,
fieldsPath
,
nil
return
inResource
,
fieldsPath
,
nil
}
}
...
@@ -63,7 +52,7 @@ func PrintModelDescription(inModel string, fieldsPath []string, w io.Writer, swa
...
@@ -63,7 +52,7 @@ func PrintModelDescription(inModel string, fieldsPath []string, w io.Writer, swa
}
}
}
}
if
pointedModel
==
nil
{
if
pointedModel
==
nil
{
return
fmt
.
Errorf
(
"
Requested resource: %s doesn't exist
"
,
inModel
)
return
fmt
.
Errorf
(
"
requested resource %q is not defined
"
,
inModel
)
}
}
if
len
(
fieldsPath
)
==
0
{
if
len
(
fieldsPath
)
==
0
{
...
@@ -80,7 +69,7 @@ func PrintModelDescription(inModel string, fieldsPath []string, w io.Writer, swa
...
@@ -80,7 +69,7 @@ func PrintModelDescription(inModel string, fieldsPath []string, w io.Writer, swa
return
printPrimitive
(
w
,
prop
)
return
printPrimitive
(
w
,
prop
)
}
}
}
else
{
}
else
{
return
fmt
.
Errorf
(
"field
: %s doesn'
t exist"
,
field
)
return
fmt
.
Errorf
(
"field
%q does no
t exist"
,
field
)
}
}
}
}
return
printModelInfo
(
w
,
pointedModel
,
pointedModelAsProp
)
return
printModelInfo
(
w
,
pointedModel
,
pointedModelAsProp
)
...
...
pkg/kubectl/kubectl.go
View file @
b12f6b34
...
@@ -91,6 +91,11 @@ func (e ShortcutExpander) ResourceIsValid(resource string) bool {
...
@@ -91,6 +91,11 @@ func (e ShortcutExpander) ResourceIsValid(resource string) bool {
return
e
.
RESTMapper
.
ResourceIsValid
(
expandResourceShortcut
(
resource
))
return
e
.
RESTMapper
.
ResourceIsValid
(
expandResourceShortcut
(
resource
))
}
}
// ResourceSingularizer expands the named resource and then singularizes it.
func
(
e
ShortcutExpander
)
ResourceSingularizer
(
resource
string
)
(
string
,
error
)
{
return
e
.
RESTMapper
.
ResourceSingularizer
(
expandResourceShortcut
(
resource
))
}
// expandResourceShortcut will return the expanded version of resource
// expandResourceShortcut will return the expanded version of resource
// (something that a pkg/api/meta.RESTMapper can understand), if it is
// (something that a pkg/api/meta.RESTMapper can understand), if it is
// indeed a shortcut. Otherwise, will return resource unmodified.
// indeed a shortcut. Otherwise, will return resource unmodified.
...
...
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