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
6d3652ed
Commit
6d3652ed
authored
Apr 25, 2018
by
juanvallejo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove hardcoded list of resources
parent
b8ab2891
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
115 additions
and
135 deletions
+115
-135
annotate.go
pkg/kubectl/cmd/annotate.go
+2
-2
annotate_test.go
pkg/kubectl/cmd/annotate_test.go
+5
-5
cmd.go
pkg/kubectl/cmd/cmd.go
+4
-4
describe.go
pkg/kubectl/cmd/describe.go
+3
-3
describe_test.go
pkg/kubectl/cmd/describe_test.go
+21
-22
explain.go
pkg/kubectl/cmd/explain.go
+45
-23
get.go
pkg/kubectl/cmd/get/get.go
+9
-6
get_test.go
pkg/kubectl/cmd/get/get_test.go
+22
-22
printing.go
pkg/kubectl/cmd/util/printing.go
+4
-48
No files found.
pkg/kubectl/cmd/annotate.go
View file @
6d3652ed
...
@@ -112,7 +112,7 @@ func NewAnnotateOptions(ioStreams genericclioptions.IOStreams) *AnnotateOptions
...
@@ -112,7 +112,7 @@ func NewAnnotateOptions(ioStreams genericclioptions.IOStreams) *AnnotateOptions
}
}
}
}
func
NewCmdAnnotate
(
f
cmdutil
.
Factory
,
ioStreams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
func
NewCmdAnnotate
(
parent
string
,
f
cmdutil
.
Factory
,
ioStreams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
o
:=
NewAnnotateOptions
(
ioStreams
)
o
:=
NewAnnotateOptions
(
ioStreams
)
validArgs
:=
cmdutil
.
ValidArgList
(
f
)
validArgs
:=
cmdutil
.
ValidArgList
(
f
)
...
@@ -120,7 +120,7 @@ func NewCmdAnnotate(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *c
...
@@ -120,7 +120,7 @@ func NewCmdAnnotate(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *c
Use
:
"annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]"
,
Use
:
"annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]"
,
DisableFlagsInUseLine
:
true
,
DisableFlagsInUseLine
:
true
,
Short
:
i18n
.
T
(
"Update the annotations on a resource"
),
Short
:
i18n
.
T
(
"Update the annotations on a resource"
),
Long
:
annotateLong
+
"
\n\n
"
+
cmdutil
.
ValidResourceTypeList
(
f
),
Long
:
annotateLong
+
"
\n\n
"
+
cmdutil
.
SuggestApiResources
(
parent
),
Example
:
annotateExample
,
Example
:
annotateExample
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
err
:=
o
.
Complete
(
f
,
cmd
,
args
);
err
!=
nil
{
if
err
:=
o
.
Complete
(
f
,
cmd
,
args
);
err
!=
nil
{
...
...
pkg/kubectl/cmd/annotate_test.go
View file @
6d3652ed
...
@@ -425,7 +425,7 @@ func TestAnnotateErrors(t *testing.T) {
...
@@ -425,7 +425,7 @@ func TestAnnotateErrors(t *testing.T) {
tf
.
ClientConfigVal
=
defaultClientConfig
()
tf
.
ClientConfigVal
=
defaultClientConfig
()
iostreams
,
_
,
bufOut
,
bufErr
:=
genericclioptions
.
NewTestIOStreams
()
iostreams
,
_
,
bufOut
,
bufErr
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdAnnotate
(
tf
,
iostreams
)
cmd
:=
NewCmdAnnotate
(
"kubectl"
,
tf
,
iostreams
)
cmd
.
SetOutput
(
bufOut
)
cmd
.
SetOutput
(
bufOut
)
for
k
,
v
:=
range
testCase
.
flags
{
for
k
,
v
:=
range
testCase
.
flags
{
...
@@ -489,7 +489,7 @@ func TestAnnotateObject(t *testing.T) {
...
@@ -489,7 +489,7 @@ func TestAnnotateObject(t *testing.T) {
tf
.
ClientConfigVal
=
defaultClientConfig
()
tf
.
ClientConfigVal
=
defaultClientConfig
()
iostreams
,
_
,
bufOut
,
_
:=
genericclioptions
.
NewTestIOStreams
()
iostreams
,
_
,
bufOut
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdAnnotate
(
tf
,
iostreams
)
cmd
:=
NewCmdAnnotate
(
"kubectl"
,
tf
,
iostreams
)
cmd
.
SetOutput
(
bufOut
)
cmd
.
SetOutput
(
bufOut
)
options
:=
NewAnnotateOptions
(
iostreams
)
options
:=
NewAnnotateOptions
(
iostreams
)
args
:=
[]
string
{
"pods/foo"
,
"a=b"
,
"c-"
}
args
:=
[]
string
{
"pods/foo"
,
"a=b"
,
"c-"
}
...
@@ -543,7 +543,7 @@ func TestAnnotateObjectFromFile(t *testing.T) {
...
@@ -543,7 +543,7 @@ func TestAnnotateObjectFromFile(t *testing.T) {
tf
.
ClientConfigVal
=
defaultClientConfig
()
tf
.
ClientConfigVal
=
defaultClientConfig
()
iostreams
,
_
,
bufOut
,
_
:=
genericclioptions
.
NewTestIOStreams
()
iostreams
,
_
,
bufOut
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdAnnotate
(
tf
,
iostreams
)
cmd
:=
NewCmdAnnotate
(
"kubectl"
,
tf
,
iostreams
)
cmd
.
SetOutput
(
bufOut
)
cmd
.
SetOutput
(
bufOut
)
options
:=
NewAnnotateOptions
(
iostreams
)
options
:=
NewAnnotateOptions
(
iostreams
)
options
.
Filenames
=
[]
string
{
"../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"
}
options
.
Filenames
=
[]
string
{
"../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"
}
...
@@ -575,7 +575,7 @@ func TestAnnotateLocal(t *testing.T) {
...
@@ -575,7 +575,7 @@ func TestAnnotateLocal(t *testing.T) {
tf
.
ClientConfigVal
=
defaultClientConfig
()
tf
.
ClientConfigVal
=
defaultClientConfig
()
iostreams
,
_
,
_
,
_
:=
genericclioptions
.
NewTestIOStreams
()
iostreams
,
_
,
_
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdAnnotate
(
tf
,
iostreams
)
cmd
:=
NewCmdAnnotate
(
"kubectl"
,
tf
,
iostreams
)
options
:=
NewAnnotateOptions
(
iostreams
)
options
:=
NewAnnotateOptions
(
iostreams
)
options
.
local
=
true
options
.
local
=
true
options
.
Filenames
=
[]
string
{
"../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"
}
options
.
Filenames
=
[]
string
{
"../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"
}
...
@@ -631,7 +631,7 @@ func TestAnnotateMultipleObjects(t *testing.T) {
...
@@ -631,7 +631,7 @@ func TestAnnotateMultipleObjects(t *testing.T) {
tf
.
ClientConfigVal
=
defaultClientConfig
()
tf
.
ClientConfigVal
=
defaultClientConfig
()
iostreams
,
_
,
_
,
_
:=
genericclioptions
.
NewTestIOStreams
()
iostreams
,
_
,
_
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdAnnotate
(
tf
,
iostreams
)
cmd
:=
NewCmdAnnotate
(
"kubectl"
,
tf
,
iostreams
)
cmd
.
SetOutput
(
iostreams
.
Out
)
cmd
.
SetOutput
(
iostreams
.
Out
)
options
:=
NewAnnotateOptions
(
iostreams
)
options
:=
NewAnnotateOptions
(
iostreams
)
options
.
all
=
true
options
.
all
=
true
...
...
pkg/kubectl/cmd/cmd.go
View file @
6d3652ed
...
@@ -264,8 +264,8 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
...
@@ -264,8 +264,8 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
{
{
Message
:
"Basic Commands (Intermediate):"
,
Message
:
"Basic Commands (Intermediate):"
,
Commands
:
[]
*
cobra
.
Command
{
Commands
:
[]
*
cobra
.
Command
{
NewCmdExplain
(
f
,
ioStreams
),
NewCmdExplain
(
"kubectl"
,
f
,
ioStreams
),
get
.
NewCmdGet
(
f
,
ioStreams
),
get
.
NewCmdGet
(
"kubectl"
,
f
,
ioStreams
),
NewCmdEdit
(
f
,
ioStreams
),
NewCmdEdit
(
f
,
ioStreams
),
NewCmdDelete
(
f
,
out
,
err
),
NewCmdDelete
(
f
,
out
,
err
),
},
},
...
@@ -294,7 +294,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
...
@@ -294,7 +294,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
{
{
Message
:
"Troubleshooting and Debugging Commands:"
,
Message
:
"Troubleshooting and Debugging Commands:"
,
Commands
:
[]
*
cobra
.
Command
{
Commands
:
[]
*
cobra
.
Command
{
NewCmdDescribe
(
f
,
out
,
err
),
NewCmdDescribe
(
"kubectl"
,
f
,
ioStreams
),
NewCmdLogs
(
f
,
out
,
err
),
NewCmdLogs
(
f
,
out
,
err
),
NewCmdAttach
(
f
,
in
,
out
,
err
),
NewCmdAttach
(
f
,
in
,
out
,
err
),
NewCmdExec
(
f
,
in
,
out
,
err
),
NewCmdExec
(
f
,
in
,
out
,
err
),
...
@@ -317,7 +317,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
...
@@ -317,7 +317,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
Message
:
"Settings Commands:"
,
Message
:
"Settings Commands:"
,
Commands
:
[]
*
cobra
.
Command
{
Commands
:
[]
*
cobra
.
Command
{
NewCmdLabel
(
f
,
ioStreams
),
NewCmdLabel
(
f
,
ioStreams
),
NewCmdAnnotate
(
f
,
ioStreams
),
NewCmdAnnotate
(
"kubectl"
,
f
,
ioStreams
),
NewCmdCompletion
(
out
,
""
),
NewCmdCompletion
(
out
,
""
),
},
},
},
},
...
...
pkg/kubectl/cmd/describe.go
View file @
6d3652ed
...
@@ -67,7 +67,7 @@ var (
...
@@ -67,7 +67,7 @@ var (
kubectl describe pods frontend`
))
kubectl describe pods frontend`
))
)
)
func
NewCmdDescribe
(
f
cmdutil
.
Factory
,
out
,
cmdErr
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdDescribe
(
parent
string
,
f
cmdutil
.
Factory
,
out
,
cmdErr
io
.
Writer
)
*
cobra
.
Command
{
options
:=
&
resource
.
FilenameOptions
{}
options
:=
&
resource
.
FilenameOptions
{}
describerSettings
:=
&
printers
.
DescriberSettings
{
describerSettings
:=
&
printers
.
DescriberSettings
{
ShowEvents
:
true
,
ShowEvents
:
true
,
...
@@ -77,7 +77,7 @@ func NewCmdDescribe(f cmdutil.Factory, out, cmdErr io.Writer) *cobra.Command {
...
@@ -77,7 +77,7 @@ func NewCmdDescribe(f cmdutil.Factory, out, cmdErr io.Writer) *cobra.Command {
Use
:
"describe (-f FILENAME | TYPE [NAME_PREFIX | -l label] | TYPE/NAME)"
,
Use
:
"describe (-f FILENAME | TYPE [NAME_PREFIX | -l label] | TYPE/NAME)"
,
DisableFlagsInUseLine
:
true
,
DisableFlagsInUseLine
:
true
,
Short
:
i18n
.
T
(
"Show details of a specific resource or group of resources"
),
Short
:
i18n
.
T
(
"Show details of a specific resource or group of resources"
),
Long
:
describeLong
+
"
\n\n
"
+
cmdutil
.
ValidResourceTypeList
(
f
),
Long
:
describeLong
+
"
\n\n
"
+
cmdutil
.
SuggestApiResources
(
parent
),
Example
:
describeExample
,
Example
:
describeExample
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
err
:=
RunDescribe
(
f
,
out
,
cmdErr
,
cmd
,
args
,
options
,
describerSettings
)
err
:=
RunDescribe
(
f
,
out
,
cmdErr
,
cmd
,
args
,
options
,
describerSettings
)
...
@@ -104,7 +104,7 @@ func RunDescribe(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, a
...
@@ -104,7 +104,7 @@ func RunDescribe(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, a
enforceNamespace
=
false
enforceNamespace
=
false
}
}
if
len
(
args
)
==
0
&&
cmdutil
.
IsFilenameSliceEmpty
(
options
.
Filenames
)
{
if
len
(
args
)
==
0
&&
cmdutil
.
IsFilenameSliceEmpty
(
options
.
Filenames
)
{
fmt
.
Fprintf
(
cmdErr
,
"You must specify the type of resource to describe. %s
\n\n
"
,
cmdutil
.
ValidResourceTypeList
(
f
))
fmt
.
Fprintf
(
cmdErr
,
"You must specify the type of resource to describe. %s
\n\n
"
,
cmdutil
.
SuggestApiResources
(
cmd
.
Parent
()
.
Name
()
))
return
cmdutil
.
UsageErrorf
(
cmd
,
"Required resource not specified."
)
return
cmdutil
.
UsageErrorf
(
cmd
,
"Required resource not specified."
)
}
}
...
...
pkg/kubectl/cmd/describe_test.go
View file @
6d3652ed
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
cmd
package
cmd
import
(
import
(
"bytes"
"fmt"
"fmt"
"net/http"
"net/http"
"strings"
"strings"
...
@@ -26,6 +25,7 @@ import (
...
@@ -26,6 +25,7 @@ import (
"k8s.io/client-go/rest/fake"
"k8s.io/client-go/rest/fake"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/legacyscheme"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/scheme"
"k8s.io/kubernetes/pkg/kubectl/scheme"
)
)
...
@@ -40,10 +40,11 @@ func TestDescribeUnknownSchemaObject(t *testing.T) {
...
@@ -40,10 +40,11 @@ func TestDescribeUnknownSchemaObject(t *testing.T) {
NegotiatedSerializer
:
unstructuredSerializer
,
NegotiatedSerializer
:
unstructuredSerializer
,
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
cmdtesting
.
NewInternalType
(
""
,
""
,
"foo"
))},
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
cmdtesting
.
NewInternalType
(
""
,
""
,
"foo"
))},
}
}
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
tf
.
Namespace
=
"non-default"
tf
.
Namespace
=
"non-default"
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdDescribe
(
"kubectl"
,
tf
,
streams
)
buferr
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdDescribe
(
tf
,
buf
,
buferr
)
cmd
.
Run
(
cmd
,
[]
string
{
"type"
,
"foo"
})
cmd
.
Run
(
cmd
,
[]
string
{
"type"
,
"foo"
})
if
d
.
Name
!=
"foo"
||
d
.
Namespace
!=
""
{
if
d
.
Name
!=
"foo"
||
d
.
Namespace
!=
""
{
...
@@ -68,9 +69,10 @@ func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) {
...
@@ -68,9 +69,10 @@ func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) {
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
cmdtesting
.
NewInternalNamespacedType
(
""
,
""
,
"foo"
,
"non-default"
))},
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
cmdtesting
.
NewInternalNamespacedType
(
""
,
""
,
"foo"
,
"non-default"
))},
}
}
tf
.
Namespace
=
"non-default"
tf
.
Namespace
=
"non-default"
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buferr
:=
bytes
.
NewBuffer
([]
byte
{})
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdDescribe
(
tf
,
buf
,
buferr
)
cmd
:=
NewCmdDescribe
(
"kubectl"
,
tf
,
streams
)
cmd
.
Run
(
cmd
,
[]
string
{
"namespacedtype"
,
"foo"
})
cmd
.
Run
(
cmd
,
[]
string
{
"namespacedtype"
,
"foo"
})
if
d
.
Name
!=
"foo"
||
d
.
Namespace
!=
"non-default"
{
if
d
.
Name
!=
"foo"
||
d
.
Namespace
!=
"non-default"
{
...
@@ -103,9 +105,10 @@ func TestDescribeObject(t *testing.T) {
...
@@ -103,9 +105,10 @@ func TestDescribeObject(t *testing.T) {
}),
}),
}
}
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buferr
:=
bytes
.
NewBuffer
([]
byte
{})
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdDescribe
(
tf
,
buf
,
buferr
)
cmd
:=
NewCmdDescribe
(
"kubectl"
,
tf
,
streams
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../test/e2e/testing-manifests/guestbook/legacy/redis-master-controller.yaml"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../test/e2e/testing-manifests/guestbook/legacy/redis-master-controller.yaml"
)
cmd
.
Run
(
cmd
,
[]
string
{})
cmd
.
Run
(
cmd
,
[]
string
{})
...
@@ -131,10 +134,10 @@ func TestDescribeListObjects(t *testing.T) {
...
@@ -131,10 +134,10 @@ func TestDescribeListObjects(t *testing.T) {
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
pods
)},
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
pods
)},
}
}
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdDescribe
(
"kubectl"
,
tf
,
streams
)
buferr
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdDescribe
(
tf
,
buf
,
buferr
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
if
buf
.
String
()
!=
fmt
.
Sprintf
(
"%s
\n\n
%s"
,
d
.
Output
,
d
.
Output
)
{
if
buf
.
String
()
!=
fmt
.
Sprintf
(
"%s
\n\n
%s"
,
d
.
Output
,
d
.
Output
)
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
...
@@ -155,9 +158,7 @@ func TestDescribeObjectShowEvents(t *testing.T) {
...
@@ -155,9 +158,7 @@ func TestDescribeObjectShowEvents(t *testing.T) {
}
}
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdDescribe
(
"kubectl"
,
tf
,
genericclioptions
.
NewTestIOStreamsDiscard
())
buferr
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdDescribe
(
tf
,
buf
,
buferr
)
cmd
.
Flags
()
.
Set
(
"show-events"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"show-events"
,
"true"
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
if
d
.
Settings
.
ShowEvents
!=
true
{
if
d
.
Settings
.
ShowEvents
!=
true
{
...
@@ -179,9 +180,7 @@ func TestDescribeObjectSkipEvents(t *testing.T) {
...
@@ -179,9 +180,7 @@ func TestDescribeObjectSkipEvents(t *testing.T) {
}
}
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdDescribe
(
"kubectl"
,
tf
,
genericclioptions
.
NewTestIOStreamsDiscard
())
buferr
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdDescribe
(
tf
,
buf
,
buferr
)
cmd
.
Flags
()
.
Set
(
"show-events"
,
"false"
)
cmd
.
Flags
()
.
Set
(
"show-events"
,
"false"
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
if
d
.
Settings
.
ShowEvents
!=
false
{
if
d
.
Settings
.
ShowEvents
!=
false
{
...
@@ -193,9 +192,9 @@ func TestDescribeHelpMessage(t *testing.T) {
...
@@ -193,9 +192,9 @@ func TestDescribeHelpMessage(t *testing.T) {
tf
:=
cmdtesting
.
NewTestFactory
()
tf
:=
cmdtesting
.
NewTestFactory
()
defer
tf
.
Cleanup
()
defer
tf
.
Cleanup
()
buf
:=
bytes
.
NewBuffer
([]
byte
{}
)
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
(
)
buferr
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdDescribe
(
tf
,
buf
,
buferr
)
cmd
:=
NewCmdDescribe
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetArgs
([]
string
{
"-h"
})
cmd
.
SetArgs
([]
string
{
"-h"
})
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
_
,
err
:=
cmd
.
ExecuteC
()
_
,
err
:=
cmd
.
ExecuteC
()
...
...
pkg/kubectl/cmd/explain.go
View file @
6d3652ed
...
@@ -21,9 +21,11 @@ import (
...
@@ -21,9 +21,11 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
"k8s.io/kubernetes/pkg/kubectl/explain"
"k8s.io/kubernetes/pkg/kubectl/explain"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
...
@@ -51,27 +53,36 @@ var (
...
@@ -51,27 +53,36 @@ var (
type
ExplainOptions
struct
{
type
ExplainOptions
struct
{
genericclioptions
.
IOStreams
genericclioptions
.
IOStreams
CmdParent
string
ApiVersion
string
Recursive
bool
Mapper
meta
.
RESTMapper
Schema
openapi
.
Resources
}
}
func
NewExplainOptions
(
streams
genericclioptions
.
IOStreams
)
*
ExplainOptions
{
func
NewExplainOptions
(
parent
string
,
streams
genericclioptions
.
IOStreams
)
*
ExplainOptions
{
return
&
ExplainOptions
{
return
&
ExplainOptions
{
IOStreams
:
streams
,
IOStreams
:
streams
,
CmdParent
:
parent
,
}
}
}
}
// NewCmdExplain returns a cobra command for swagger docs
// NewCmdExplain returns a cobra command for swagger docs
func
NewCmdExplain
(
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
func
NewCmdExplain
(
parent
string
,
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
o
:=
NewExplainOptions
(
streams
)
o
:=
NewExplainOptions
(
parent
,
streams
)
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"explain RESOURCE"
,
Use
:
"explain RESOURCE"
,
DisableFlagsInUseLine
:
true
,
DisableFlagsInUseLine
:
true
,
Short
:
i18n
.
T
(
"Documentation of resources"
),
Short
:
i18n
.
T
(
"Documentation of resources"
),
Long
:
explainLong
+
"
\n\n
"
+
cmdutil
.
ValidResourceTypeList
(
f
),
Long
:
explainLong
+
"
\n\n
"
+
cmdutil
.
SuggestApiResources
(
parent
),
Example
:
explainExamples
,
Example
:
explainExamples
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
err
:=
o
.
RunExplain
(
f
,
cmd
,
args
)
cmdutil
.
CheckErr
(
o
.
Complete
(
f
,
cmd
))
cmdutil
.
CheckErr
(
err
)
cmdutil
.
CheckErr
(
o
.
Validate
(
args
))
cmdutil
.
CheckErr
(
o
.
Run
(
args
))
},
},
}
}
cmd
.
Flags
()
.
Bool
(
"recursive"
,
false
,
"Print the fields of fields (Currently only 1 level deep)"
)
cmd
.
Flags
()
.
Bool
(
"recursive"
,
false
,
"Print the fields of fields (Currently only 1 level deep)"
)
...
@@ -79,24 +90,40 @@ func NewCmdExplain(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobr
...
@@ -79,24 +90,40 @@ func NewCmdExplain(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobr
return
cmd
return
cmd
}
}
// RunExplain executes the appropriate steps to print a model's documentation
func
(
o
*
ExplainOptions
)
Complete
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
)
error
{
func
(
o
*
ExplainOptions
)
RunExplain
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
o
.
Recursive
=
cmdutil
.
GetFlagBool
(
cmd
,
"recursive"
)
o
.
ApiVersion
=
cmdutil
.
GetFlagString
(
cmd
,
"api-version"
)
o
.
Mapper
,
_
=
f
.
Object
()
var
err
error
o
.
Schema
,
err
=
f
.
OpenAPISchema
()
if
err
!=
nil
{
return
err
}
return
nil
}
func
(
o
*
ExplainOptions
)
Validate
(
args
[]
string
)
error
{
if
len
(
args
)
==
0
{
if
len
(
args
)
==
0
{
fmt
.
Fprintf
(
o
.
ErrOut
,
"You must specify the type of resource to explain. %s
\n\n
"
,
cmdutil
.
ValidResourceTypeList
(
f
))
return
fmt
.
Errorf
(
"You must specify the type of resource to explain. %s
\n
"
,
cmdutil
.
SuggestApiResources
(
o
.
CmdParent
))
return
cmdutil
.
UsageErrorf
(
cmd
,
"Required resource not specified."
)
}
}
if
len
(
args
)
>
1
{
if
len
(
args
)
>
1
{
return
cmdutil
.
UsageErrorf
(
cmd
,
"We accept only this format: explain RESOURCE
"
)
return
fmt
.
Errorf
(
"We accept only this format: explain RESOURCE
\n
"
)
}
}
recursive
:=
cmdutil
.
GetFlagBool
(
cmd
,
"recursive"
)
return
nil
apiVersionString
:=
cmdutil
.
GetFlagString
(
cmd
,
"api-version"
)
}
// Run executes the appropriate steps to print a model's documentation
func
(
o
*
ExplainOptions
)
Run
(
args
[]
string
)
error
{
recursive
:=
o
.
Recursive
apiVersionString
:=
o
.
ApiVersion
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
// the users to use it in explain (kubectl explain <group><syntax><resource>).
// the users to use it in explain (kubectl explain <group><syntax><resource>).
// Refer to issue #16039 for why we do this. Refer to PR #15808 that used "/" syntax.
// Refer to issue #16039 for why we do this. Refer to PR #15808 that used "/" syntax.
inModel
,
fieldsPath
,
err
:=
explain
.
SplitAndParseResourceRequest
(
args
[
0
],
m
apper
)
inModel
,
fieldsPath
,
err
:=
explain
.
SplitAndParseResourceRequest
(
args
[
0
],
o
.
M
apper
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -105,10 +132,10 @@ func (o *ExplainOptions) RunExplain(f cmdutil.Factory, cmd *cobra.Command, args
...
@@ -105,10 +132,10 @@ func (o *ExplainOptions) RunExplain(f cmdutil.Factory, cmd *cobra.Command, args
fullySpecifiedGVR
,
groupResource
:=
schema
.
ParseResourceArg
(
inModel
)
fullySpecifiedGVR
,
groupResource
:=
schema
.
ParseResourceArg
(
inModel
)
gvk
:=
schema
.
GroupVersionKind
{}
gvk
:=
schema
.
GroupVersionKind
{}
if
fullySpecifiedGVR
!=
nil
{
if
fullySpecifiedGVR
!=
nil
{
gvk
,
_
=
m
apper
.
KindFor
(
*
fullySpecifiedGVR
)
gvk
,
_
=
o
.
M
apper
.
KindFor
(
*
fullySpecifiedGVR
)
}
}
if
gvk
.
Empty
()
{
if
gvk
.
Empty
()
{
gvk
,
err
=
m
apper
.
KindFor
(
groupResource
.
WithVersion
(
""
))
gvk
,
err
=
o
.
M
apper
.
KindFor
(
groupResource
.
WithVersion
(
""
))
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -122,12 +149,7 @@ func (o *ExplainOptions) RunExplain(f cmdutil.Factory, cmd *cobra.Command, args
...
@@ -122,12 +149,7 @@ func (o *ExplainOptions) RunExplain(f cmdutil.Factory, cmd *cobra.Command, args
gvk
=
apiVersion
.
WithKind
(
gvk
.
Kind
)
gvk
=
apiVersion
.
WithKind
(
gvk
.
Kind
)
}
}
resources
,
err
:=
f
.
OpenAPISchema
()
schema
:=
o
.
Schema
.
LookupResource
(
gvk
)
if
err
!=
nil
{
return
err
}
schema
:=
resources
.
LookupResource
(
gvk
)
if
schema
==
nil
{
if
schema
==
nil
{
return
fmt
.
Errorf
(
"Couldn't find resource for %q"
,
gvk
)
return
fmt
.
Errorf
(
"Couldn't find resource for %q"
,
gvk
)
}
}
...
...
pkg/kubectl/cmd/get/get.go
View file @
6d3652ed
...
@@ -57,6 +57,8 @@ type GetOptions struct {
...
@@ -57,6 +57,8 @@ type GetOptions struct {
IsGeneric
bool
IsGeneric
bool
PrintWithOpenAPICols
bool
PrintWithOpenAPICols
bool
CmdParent
string
resource
.
FilenameOptions
resource
.
FilenameOptions
Raw
string
Raw
string
...
@@ -131,26 +133,27 @@ const (
...
@@ -131,26 +133,27 @@ const (
)
)
// NewGetOptions returns a GetOptions with default chunk size 500.
// NewGetOptions returns a GetOptions with default chunk size 500.
func
NewGetOptions
(
streams
genericclioptions
.
IOStreams
)
*
GetOptions
{
func
NewGetOptions
(
parent
string
,
streams
genericclioptions
.
IOStreams
)
*
GetOptions
{
return
&
GetOptions
{
return
&
GetOptions
{
PrintFlags
:
NewGetPrintFlags
(),
PrintFlags
:
NewGetPrintFlags
(),
C
hunkSize
:
500
,
C
mdParent
:
parent
,
IOStreams
:
streams
,
IOStreams
:
streams
,
ChunkSize
:
500
,
}
}
}
}
// NewCmdGet creates a command object for the generic "get" action, which
// NewCmdGet creates a command object for the generic "get" action, which
// retrieves one or more resources from a server.
// retrieves one or more resources from a server.
func
NewCmdGet
(
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
func
NewCmdGet
(
parent
string
,
f
cmdutil
.
Factory
,
streams
genericclioptions
.
IOStreams
)
*
cobra
.
Command
{
o
:=
NewGetOptions
(
streams
)
o
:=
NewGetOptions
(
parent
,
streams
)
validArgs
:=
cmdutil
.
ValidArgList
(
f
)
validArgs
:=
cmdutil
.
ValidArgList
(
f
)
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"get [(-o|--output=)json|yaml|wide|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=...] (TYPE [NAME | -l label] | TYPE/NAME ...) [flags]"
,
Use
:
"get [(-o|--output=)json|yaml|wide|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=...] (TYPE [NAME | -l label] | TYPE/NAME ...) [flags]"
,
DisableFlagsInUseLine
:
true
,
DisableFlagsInUseLine
:
true
,
Short
:
i18n
.
T
(
"Display one or many resources"
),
Short
:
i18n
.
T
(
"Display one or many resources"
),
Long
:
getLong
+
"
\n\n
"
+
cmdutil
.
ValidResourceTypeList
(
f
),
Long
:
getLong
+
"
\n\n
"
+
cmdutil
.
SuggestApiResources
(
parent
),
Example
:
getExample
,
Example
:
getExample
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
cmdutil
.
CheckErr
(
o
.
Complete
(
f
,
cmd
,
args
))
cmdutil
.
CheckErr
(
o
.
Complete
(
f
,
cmd
,
args
))
...
@@ -258,7 +261,7 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
...
@@ -258,7 +261,7 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
o
.
IncludeUninitialized
=
cmdutil
.
ShouldIncludeUninitialized
(
cmd
,
len
(
args
)
==
2
)
o
.
IncludeUninitialized
=
cmdutil
.
ShouldIncludeUninitialized
(
cmd
,
len
(
args
)
==
2
)
default
:
default
:
if
len
(
args
)
==
0
&&
cmdutil
.
IsFilenameSliceEmpty
(
o
.
Filenames
)
{
if
len
(
args
)
==
0
&&
cmdutil
.
IsFilenameSliceEmpty
(
o
.
Filenames
)
{
fmt
.
Fprintf
(
o
.
ErrOut
,
"You must specify the type of resource to get. %s
\n\n
"
,
cmdutil
.
ValidResourceTypeList
(
f
))
fmt
.
Fprintf
(
o
.
ErrOut
,
"You must specify the type of resource to get. %s
\n\n
"
,
cmdutil
.
SuggestApiResources
(
o
.
CmdParent
))
fullCmdName
:=
cmd
.
Parent
()
.
CommandPath
()
fullCmdName
:=
cmd
.
Parent
()
.
CommandPath
()
usageString
:=
"Required resource not specified."
usageString
:=
"Required resource not specified."
if
len
(
fullCmdName
)
>
0
&&
cmdutil
.
IsSiblingCommandExists
(
cmd
,
"explain"
)
{
if
len
(
fullCmdName
)
>
0
&&
cmdutil
.
IsSiblingCommandExists
(
cmd
,
"explain"
)
{
...
...
pkg/kubectl/cmd/get/get_test.go
View file @
6d3652ed
...
@@ -213,7 +213,7 @@ func TestGetUnknownSchemaObject(t *testing.T) {
...
@@ -213,7 +213,7 @@ func TestGetUnknownSchemaObject(t *testing.T) {
}
}
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Run
(
cmd
,
[]
string
{
"type"
,
"foo"
})
cmd
.
Run
(
cmd
,
[]
string
{
"type"
,
"foo"
})
...
@@ -255,7 +255,7 @@ func TestGetSchemaObject(t *testing.T) {
...
@@ -255,7 +255,7 @@ func TestGetSchemaObject(t *testing.T) {
tf
.
ClientConfigVal
=
defaultClientConfig
()
tf
.
ClientConfigVal
=
defaultClientConfig
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
Run
(
cmd
,
[]
string
{
"replicationcontrollers"
,
"foo"
})
cmd
.
Run
(
cmd
,
[]
string
{
"replicationcontrollers"
,
"foo"
})
if
!
strings
.
Contains
(
buf
.
String
(),
"foo"
)
{
if
!
strings
.
Contains
(
buf
.
String
(),
"foo"
)
{
...
@@ -280,7 +280,7 @@ func TestGetObjectsWithOpenAPIOutputFormatPresent(t *testing.T) {
...
@@ -280,7 +280,7 @@ func TestGetObjectsWithOpenAPIOutputFormatPresent(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
useOpenAPIPrintColumnFlagLabel
,
"true"
)
cmd
.
Flags
()
.
Set
(
useOpenAPIPrintColumnFlagLabel
,
"true"
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
,
"foo"
})
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
,
"foo"
})
...
@@ -334,7 +334,7 @@ func TestGetObjects(t *testing.T) {
...
@@ -334,7 +334,7 @@ func TestGetObjects(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
,
"foo"
})
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
,
"foo"
})
...
@@ -382,7 +382,7 @@ func TestGetObjectIgnoreNotFound(t *testing.T) {
...
@@ -382,7 +382,7 @@ func TestGetObjectIgnoreNotFound(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"ignore-not-found"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"ignore-not-found"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"output"
,
"yaml"
)
cmd
.
Flags
()
.
Set
(
"output"
,
"yaml"
)
...
@@ -426,7 +426,7 @@ func TestGetSortedObjects(t *testing.T) {
...
@@ -426,7 +426,7 @@ func TestGetSortedObjects(t *testing.T) {
tf
.
ClientConfigVal
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
schema
.
GroupVersion
{
Version
:
"v1"
}}}
tf
.
ClientConfigVal
=
&
restclient
.
Config
{
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
schema
.
GroupVersion
{
Version
:
"v1"
}}}
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
// sorting with metedata.name
// sorting with metedata.name
...
@@ -457,7 +457,7 @@ func TestGetObjectsIdentifiedByFile(t *testing.T) {
...
@@ -457,7 +457,7 @@ func TestGetObjectsIdentifiedByFile(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"
)
cmd
.
Run
(
cmd
,
[]
string
{})
cmd
.
Run
(
cmd
,
[]
string
{})
...
@@ -484,7 +484,7 @@ func TestGetListObjects(t *testing.T) {
...
@@ -484,7 +484,7 @@ func TestGetListObjects(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
...
@@ -511,7 +511,7 @@ func TestGetAllListObjects(t *testing.T) {
...
@@ -511,7 +511,7 @@ func TestGetAllListObjects(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
...
@@ -538,7 +538,7 @@ func TestGetListComponentStatus(t *testing.T) {
...
@@ -538,7 +538,7 @@ func TestGetListComponentStatus(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Run
(
cmd
,
[]
string
{
"componentstatuses"
})
cmd
.
Run
(
cmd
,
[]
string
{
"componentstatuses"
})
...
@@ -588,7 +588,7 @@ func TestGetMixedGenericObjects(t *testing.T) {
...
@@ -588,7 +588,7 @@ func TestGetMixedGenericObjects(t *testing.T) {
tf
.
ClientConfigVal
=
defaultClientConfig
()
tf
.
ClientConfigVal
=
defaultClientConfig
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"output"
,
"json"
)
cmd
.
Flags
()
.
Set
(
"output"
,
"json"
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
cmd
.
Run
(
cmd
,
[]
string
{
"pods"
})
...
@@ -639,7 +639,7 @@ func TestGetMultipleTypeObjects(t *testing.T) {
...
@@ -639,7 +639,7 @@ func TestGetMultipleTypeObjects(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Run
(
cmd
,
[]
string
{
"pods,services"
})
cmd
.
Run
(
cmd
,
[]
string
{
"pods,services"
})
...
@@ -679,7 +679,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
...
@@ -679,7 +679,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
tf
.
ClientConfigVal
=
defaultClientConfig
()
tf
.
ClientConfigVal
=
defaultClientConfig
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"output"
,
"json"
)
cmd
.
Flags
()
.
Set
(
"output"
,
"json"
)
...
@@ -783,7 +783,7 @@ func TestGetMultipleTypeObjectsWithLabelSelector(t *testing.T) {
...
@@ -783,7 +783,7 @@ func TestGetMultipleTypeObjectsWithLabelSelector(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"selector"
,
"a=b"
)
cmd
.
Flags
()
.
Set
(
"selector"
,
"a=b"
)
...
@@ -827,7 +827,7 @@ func TestGetMultipleTypeObjectsWithFieldSelector(t *testing.T) {
...
@@ -827,7 +827,7 @@ func TestGetMultipleTypeObjectsWithFieldSelector(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"field-selector"
,
"a=b"
)
cmd
.
Flags
()
.
Set
(
"field-selector"
,
"a=b"
)
...
@@ -873,7 +873,7 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) {
...
@@ -873,7 +873,7 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Run
(
cmd
,
[]
string
{
"services/bar"
,
"node/foo"
})
cmd
.
Run
(
cmd
,
[]
string
{
"services/bar"
,
"node/foo"
})
...
@@ -992,7 +992,7 @@ func TestWatchLabelSelector(t *testing.T) {
...
@@ -992,7 +992,7 @@ func TestWatchLabelSelector(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"watch"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"watch"
,
"true"
)
...
@@ -1044,7 +1044,7 @@ func TestWatchFieldSelector(t *testing.T) {
...
@@ -1044,7 +1044,7 @@ func TestWatchFieldSelector(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"watch"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"watch"
,
"true"
)
...
@@ -1090,7 +1090,7 @@ func TestWatchResource(t *testing.T) {
...
@@ -1090,7 +1090,7 @@ func TestWatchResource(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"watch"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"watch"
,
"true"
)
...
@@ -1134,7 +1134,7 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) {
...
@@ -1134,7 +1134,7 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"watch"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"watch"
,
"true"
)
...
@@ -1179,7 +1179,7 @@ func TestWatchOnlyResource(t *testing.T) {
...
@@ -1179,7 +1179,7 @@ func TestWatchOnlyResource(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"watch-only"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"watch-only"
,
"true"
)
...
@@ -1225,7 +1225,7 @@ func TestWatchOnlyList(t *testing.T) {
...
@@ -1225,7 +1225,7 @@ func TestWatchOnlyList(t *testing.T) {
tf
.
Namespace
=
"test"
tf
.
Namespace
=
"test"
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
streams
,
_
,
buf
,
_
:=
genericclioptions
.
NewTestIOStreams
()
cmd
:=
NewCmdGet
(
tf
,
streams
)
cmd
:=
NewCmdGet
(
"kubectl"
,
tf
,
streams
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"watch-only"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"watch-only"
,
"true"
)
...
...
pkg/kubectl/cmd/util/printing.go
View file @
6d3652ed
...
@@ -234,54 +234,10 @@ func maybeWrapSortingPrinter(printer printers.ResourcePrinter, printOpts printer
...
@@ -234,54 +234,10 @@ func maybeWrapSortingPrinter(printer printers.ResourcePrinter, printOpts printer
return
printer
return
printer
}
}
// ValidResourceTypeList returns a multi-line string containing the valid resources. May
// SuggestApiResources returns a suggestion to use the "api-resources" command
// be called before the factory is initialized.
// to retrieve a supported list of resources
// TODO: This function implementation should be replaced with a real implementation from the
func
SuggestApiResources
(
parent
string
)
string
{
// discovery service.
return
templates
.
LongDesc
(
fmt
.
Sprintf
(
"Use
\"
%s api-resources
\"
for a complete list of supported resources."
,
parent
))
func
ValidResourceTypeList
(
f
ClientAccessFactory
)
string
{
// TODO: Should attempt to use the cached discovery list or fallback to a static list
// that is calculated from code compiled into the factory.
return
templates
.
LongDesc
(
`Valid resource types include:
* all
* certificatesigningrequests (aka 'csr')
* clusterrolebindings
* clusterroles
* componentstatuses (aka 'cs')
* configmaps (aka 'cm')
* controllerrevisions
* cronjobs
* customresourcedefinition (aka 'crd')
* daemonsets (aka 'ds')
* deployments (aka 'deploy')
* endpoints (aka 'ep')
* events (aka 'ev')
* horizontalpodautoscalers (aka 'hpa')
* ingresses (aka 'ing')
* jobs
* limitranges (aka 'limits')
* namespaces (aka 'ns')
* networkpolicies (aka 'netpol')
* nodes (aka 'no')
* persistentvolumeclaims (aka 'pvc')
* persistentvolumes (aka 'pv')
* poddisruptionbudgets (aka 'pdb')
* podpreset
* pods (aka 'po')
* podsecuritypolicies (aka 'psp')
* podtemplates
* replicasets (aka 'rs')
* replicationcontrollers (aka 'rc')
* resourcequotas (aka 'quota')
* rolebindings
* roles
* secrets
* serviceaccounts (aka 'sa')
* services (aka 'svc')
* statefulsets (aka 'sts')
* storageclasses (aka 'sc')
`
)
}
}
// Retrieve a list of handled resources from printer as valid args
// Retrieve a list of handled resources from printer as valid args
...
...
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