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
810dbc5e
Commit
810dbc5e
authored
Mar 17, 2017
by
Daniel Martí
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubectl/cmd: remove a bunch of unused parameters
Found with github.com/mvdan/unparam.
parent
e9a91b8c
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
56 additions
and
71 deletions
+56
-71
kubefed.go
federation/pkg/kubefed/kubefed.go
+1
-1
annotate.go
pkg/kubectl/cmd/annotate.go
+2
-2
annotate_test.go
pkg/kubectl/cmd/annotate_test.go
+5
-5
clusterinfo_dump.go
pkg/kubectl/cmd/clusterinfo_dump.go
+2
-2
cmd.go
pkg/kubectl/cmd/cmd.go
+3
-3
completion.go
pkg/kubectl/cmd/completion.go
+1
-1
current_context.go
pkg/kubectl/cmd/config/current_context.go
+2
-2
current_context_test.go
pkg/kubectl/cmd/config/current_context_test.go
+1
-1
convert.go
pkg/kubectl/cmd/convert.go
+2
-2
cp.go
pkg/kubectl/cmd/cp.go
+3
-3
delete.go
pkg/kubectl/cmd/delete.go
+2
-2
describe.go
pkg/kubectl/cmd/describe.go
+2
-4
edit.go
pkg/kubectl/cmd/edit.go
+3
-4
expose.go
pkg/kubectl/cmd/expose.go
+1
-1
get.go
pkg/kubectl/cmd/get.go
+1
-1
help.go
pkg/kubectl/cmd/help.go
+1
-3
label.go
pkg/kubectl/cmd/label.go
+2
-2
label_test.go
pkg/kubectl/cmd/label_test.go
+4
-4
options.go
pkg/kubectl/cmd/options.go
+1
-3
portforward.go
pkg/kubectl/cmd/portforward.go
+2
-2
portforward_test.go
pkg/kubectl/cmd/portforward_test.go
+1
-1
run.go
pkg/kubectl/cmd/run.go
+7
-7
set_selector.go
pkg/kubectl/cmd/set/set_selector.go
+2
-2
taint.go
pkg/kubectl/cmd/taint.go
+2
-2
helpers.go
pkg/kubectl/cmd/util/helpers.go
+2
-2
helpers_test.go
pkg/kubectl/cmd/util/helpers_test.go
+1
-9
No files found.
federation/pkg/kubefed/kubefed.go
View file @
810dbc5e
...
...
@@ -67,7 +67,7 @@ func NewKubeFedCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
templates
.
ActsAsRootCommand
(
cmds
,
filters
,
groups
...
)
cmds
.
AddCommand
(
kubectl
.
NewCmdVersion
(
f
,
out
))
cmds
.
AddCommand
(
kubectl
.
NewCmdOptions
(
out
))
cmds
.
AddCommand
(
kubectl
.
NewCmdOptions
())
return
cmds
}
...
...
pkg/kubectl/cmd/annotate.go
View file @
810dbc5e
...
...
@@ -117,7 +117,7 @@ func NewCmdAnnotate(f cmdutil.Factory, out io.Writer) *cobra.Command {
Long
:
annotate_long
,
Example
:
annotate_example
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
err
:=
options
.
Complete
(
f
,
out
,
cmd
,
args
);
err
!=
nil
{
if
err
:=
options
.
Complete
(
out
,
cmd
,
args
);
err
!=
nil
{
cmdutil
.
CheckErr
(
cmdutil
.
UsageError
(
cmd
,
err
.
Error
()))
}
if
err
:=
options
.
Validate
();
err
!=
nil
{
...
...
@@ -144,7 +144,7 @@ func NewCmdAnnotate(f cmdutil.Factory, out io.Writer) *cobra.Command {
}
// Complete adapts from the command line args and factory to the data required.
func
(
o
*
AnnotateOptions
)
Complete
(
f
cmdutil
.
Factory
,
out
io
.
Writer
,
cmd
*
cobra
.
Command
,
args
[]
string
)
(
err
error
)
{
func
(
o
*
AnnotateOptions
)
Complete
(
out
io
.
Writer
,
cmd
*
cobra
.
Command
,
args
[]
string
)
(
err
error
)
{
o
.
out
=
out
o
.
local
=
cmdutil
.
GetFlagBool
(
cmd
,
"local"
)
o
.
overwrite
=
cmdutil
.
GetFlagBool
(
cmd
,
"overwrite"
)
...
...
pkg/kubectl/cmd/annotate_test.go
View file @
810dbc5e
...
...
@@ -404,7 +404,7 @@ func TestAnnotateErrors(t *testing.T) {
cmd
.
Flags
()
.
Set
(
k
,
v
)
}
options
:=
&
AnnotateOptions
{}
err
:=
options
.
Complete
(
f
,
buf
,
cmd
,
testCase
.
args
)
err
:=
options
.
Complete
(
buf
,
cmd
,
testCase
.
args
)
if
err
==
nil
{
err
=
options
.
Validate
()
}
...
...
@@ -461,7 +461,7 @@ func TestAnnotateObject(t *testing.T) {
cmd
.
SetOutput
(
buf
)
options
:=
&
AnnotateOptions
{}
args
:=
[]
string
{
"pods/foo"
,
"a=b"
,
"c-"
}
if
err
:=
options
.
Complete
(
f
,
buf
,
cmd
,
args
);
err
!=
nil
{
if
err
:=
options
.
Complete
(
buf
,
cmd
,
args
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
err
:=
options
.
Validate
();
err
!=
nil
{
...
...
@@ -513,7 +513,7 @@ func TestAnnotateObjectFromFile(t *testing.T) {
options
:=
&
AnnotateOptions
{}
options
.
Filenames
=
[]
string
{
"../../../examples/storage/cassandra/cassandra-controller.yaml"
}
args
:=
[]
string
{
"a=b"
,
"c-"
}
if
err
:=
options
.
Complete
(
f
,
buf
,
cmd
,
args
);
err
!=
nil
{
if
err
:=
options
.
Complete
(
buf
,
cmd
,
args
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
err
:=
options
.
Validate
();
err
!=
nil
{
...
...
@@ -543,7 +543,7 @@ func TestAnnotateLocal(t *testing.T) {
options
:=
&
AnnotateOptions
{}
options
.
Filenames
=
[]
string
{
"../../../examples/storage/cassandra/cassandra-controller.yaml"
}
args
:=
[]
string
{
"a=b"
}
if
err
:=
options
.
Complete
(
f
,
buf
,
cmd
,
args
);
err
!=
nil
{
if
err
:=
options
.
Complete
(
buf
,
cmd
,
args
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
err
:=
options
.
Validate
();
err
!=
nil
{
...
...
@@ -597,7 +597,7 @@ func TestAnnotateMultipleObjects(t *testing.T) {
cmd
.
Flags
()
.
Set
(
"all"
,
"true"
)
options
:=
&
AnnotateOptions
{}
args
:=
[]
string
{
"pods"
,
"a=b"
,
"c-"
}
if
err
:=
options
.
Complete
(
f
,
buf
,
cmd
,
args
);
err
!=
nil
{
if
err
:=
options
.
Complete
(
buf
,
cmd
,
args
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
err
:=
options
.
Validate
();
err
!=
nil
{
...
...
pkg/kubectl/cmd/clusterinfo_dump.go
View file @
810dbc5e
...
...
@@ -40,7 +40,7 @@ func NewCmdClusterInfoDump(f cmdutil.Factory, cmdOut io.Writer) *cobra.Command {
Long
:
dumpLong
,
Example
:
dumpExample
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
cmdutil
.
CheckErr
(
dumpClusterInfo
(
f
,
cmd
,
args
,
cmdOut
))
cmdutil
.
CheckErr
(
dumpClusterInfo
(
f
,
cmd
,
cmdOut
))
},
}
cmd
.
Flags
()
.
String
(
"output-directory"
,
""
,
i18n
.
T
(
"Where to output the files. If empty or '-' uses stdout, otherwise creates a directory hierarchy in that directory"
))
...
...
@@ -88,7 +88,7 @@ func setupOutputWriter(cmd *cobra.Command, defaultWriter io.Writer, filename str
return
file
}
func
dumpClusterInfo
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
args
[]
string
,
out
io
.
Writer
)
error
{
func
dumpClusterInfo
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
out
io
.
Writer
)
error
{
timeout
,
err
:=
cmdutil
.
GetPodRunningTimeoutFlag
(
cmd
)
if
err
!=
nil
{
return
cmdutil
.
UsageError
(
cmd
,
err
.
Error
())
...
...
pkg/kubectl/cmd/cmd.go
View file @
810dbc5e
...
...
@@ -296,7 +296,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
NewCmdExec
(
f
,
in
,
out
,
err
),
NewCmdPortForward
(
f
,
out
,
err
),
NewCmdProxy
(
f
,
out
),
NewCmdCp
(
f
,
in
,
out
,
err
),
NewCmdCp
(
f
,
out
,
err
),
auth
.
NewCmdAuth
(
f
,
out
,
err
),
},
},
...
...
@@ -314,7 +314,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
Commands
:
[]
*
cobra
.
Command
{
NewCmdLabel
(
f
,
out
),
NewCmdAnnotate
(
f
,
out
),
NewCmdCompletion
(
f
,
out
,
""
),
NewCmdCompletion
(
out
,
""
),
},
},
}
...
...
@@ -349,7 +349,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
cmds
.
AddCommand
(
cmdconfig
.
NewCmdConfig
(
clientcmd
.
NewDefaultPathOptions
(),
out
,
err
))
cmds
.
AddCommand
(
NewCmdVersion
(
f
,
out
))
cmds
.
AddCommand
(
NewCmdApiVersions
(
f
,
out
))
cmds
.
AddCommand
(
NewCmdOptions
(
out
))
cmds
.
AddCommand
(
NewCmdOptions
())
return
cmds
}
...
...
pkg/kubectl/cmd/completion.go
View file @
810dbc5e
...
...
@@ -87,7 +87,7 @@ var (
}
)
func
NewCmdCompletion
(
f
cmdutil
.
Factory
,
out
io
.
Writer
,
boilerPlate
string
)
*
cobra
.
Command
{
func
NewCmdCompletion
(
out
io
.
Writer
,
boilerPlate
string
)
*
cobra
.
Command
{
shells
:=
[]
string
{}
for
s
:=
range
completion_shells
{
shells
=
append
(
shells
,
s
)
...
...
pkg/kubectl/cmd/config/current_context.go
View file @
810dbc5e
...
...
@@ -50,7 +50,7 @@ func NewCmdConfigCurrentContext(out io.Writer, configAccess clientcmd.ConfigAcce
Long
:
current_context_long
,
Example
:
current_context_example
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
err
:=
RunCurrentContext
(
out
,
args
,
options
)
err
:=
RunCurrentContext
(
out
,
options
)
cmdutil
.
CheckErr
(
err
)
},
}
...
...
@@ -58,7 +58,7 @@ func NewCmdConfigCurrentContext(out io.Writer, configAccess clientcmd.ConfigAcce
return
cmd
}
func
RunCurrentContext
(
out
io
.
Writer
,
args
[]
string
,
options
*
CurrentContextOptions
)
error
{
func
RunCurrentContext
(
out
io
.
Writer
,
options
*
CurrentContextOptions
)
error
{
config
,
err
:=
options
.
ConfigAccess
.
GetStartingConfig
()
if
err
!=
nil
{
return
err
...
...
pkg/kubectl/cmd/config/current_context_test.go
View file @
810dbc5e
...
...
@@ -72,7 +72,7 @@ func (test currentContextTest) run(t *testing.T) {
}
buf
:=
bytes
.
NewBuffer
([]
byte
{})
err
=
RunCurrentContext
(
buf
,
[]
string
{},
&
options
)
err
=
RunCurrentContext
(
buf
,
&
options
)
if
len
(
test
.
expectedError
)
!=
0
{
if
err
==
nil
{
t
.
Errorf
(
"Did not get %v"
,
test
.
expectedError
)
...
...
pkg/kubectl/cmd/convert.go
View file @
810dbc5e
...
...
@@ -69,7 +69,7 @@ func NewCmdConvert(f cmdutil.Factory, out io.Writer) *cobra.Command {
Long
:
convert_long
,
Example
:
convert_example
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
err
:=
options
.
Complete
(
f
,
out
,
cmd
,
args
)
err
:=
options
.
Complete
(
f
,
out
,
cmd
)
cmdutil
.
CheckErr
(
err
)
err
=
options
.
RunConvert
()
cmdutil
.
CheckErr
(
err
)
...
...
@@ -117,7 +117,7 @@ func outputVersion(cmd *cobra.Command, defaultVersion *schema.GroupVersion) (sch
}
// 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
)
(
err
error
)
{
o
.
outputVersion
,
err
=
outputVersion
(
cmd
,
&
api
.
Registry
.
EnabledVersionsForGroup
(
api
.
GroupName
)[
0
])
if
err
!=
nil
{
return
err
...
...
pkg/kubectl/cmd/cp.go
View file @
810dbc5e
...
...
@@ -59,7 +59,7 @@ var (
)
// NewCmdCp creates a new Copy command.
func
NewCmdCp
(
f
cmdutil
.
Factory
,
cmd
In
io
.
Reader
,
cmd
Out
,
cmdErr
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdCp
(
f
cmdutil
.
Factory
,
cmdOut
,
cmdErr
io
.
Writer
)
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"cp <file-spec-src> <file-spec-dest>"
,
Short
:
i18n
.
T
(
"Copy files and directories to and from containers."
),
...
...
@@ -121,7 +121,7 @@ func runCopy(f cmdutil.Factory, cmd *cobra.Command, out, cmderr io.Writer, args
return
err
}
if
len
(
srcSpec
.
PodName
)
!=
0
{
return
copyFromPod
(
f
,
cmd
,
out
,
cmderr
,
srcSpec
,
destSpec
)
return
copyFromPod
(
f
,
cmd
,
cmderr
,
srcSpec
,
destSpec
)
}
if
len
(
destSpec
.
PodName
)
!=
0
{
return
copyToPod
(
f
,
cmd
,
out
,
cmderr
,
srcSpec
,
destSpec
)
...
...
@@ -161,7 +161,7 @@ func copyToPod(f cmdutil.Factory, cmd *cobra.Command, stdout, stderr io.Writer,
return
execute
(
f
,
cmd
,
options
)
}
func
copyFromPod
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
out
,
cmderr
io
.
Writer
,
src
,
dest
fileSpec
)
error
{
func
copyFromPod
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
cmderr
io
.
Writer
,
src
,
dest
fileSpec
)
error
{
reader
,
outStream
:=
io
.
Pipe
()
options
:=
&
ExecOptions
{
StreamOptions
:
StreamOptions
{
...
...
pkg/kubectl/cmd/delete.go
View file @
810dbc5e
...
...
@@ -137,7 +137,7 @@ func NewCmdDelete(f cmdutil.Factory, out, errOut io.Writer) *cobra.Command {
if
err
:=
options
.
Complete
(
f
,
out
,
errOut
,
args
);
err
!=
nil
{
cmdutil
.
CheckErr
(
err
)
}
if
err
:=
options
.
Validate
(
f
,
cmd
);
err
!=
nil
{
if
err
:=
options
.
Validate
(
cmd
);
err
!=
nil
{
cmdutil
.
CheckErr
(
cmdutil
.
UsageError
(
cmd
,
err
.
Error
()))
}
if
err
:=
options
.
RunDelete
();
err
!=
nil
{
...
...
@@ -198,7 +198,7 @@ func (o *DeleteOptions) Complete(f cmdutil.Factory, out, errOut io.Writer, args
return
nil
}
func
(
o
*
DeleteOptions
)
Validate
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
)
error
{
func
(
o
*
DeleteOptions
)
Validate
(
cmd
*
cobra
.
Command
)
error
{
if
o
.
DeleteAll
{
f
:=
cmd
.
Flags
()
.
Lookup
(
"ignore-not-found"
)
// The flag should never be missing
...
...
pkg/kubectl/cmd/describe.go
View file @
810dbc5e
...
...
@@ -24,9 +24,7 @@ import (
"github.com/spf13/cobra"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/pkg/kubectl"
...
...
@@ -138,7 +136,7 @@ func RunDescribe(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, a
infos
,
err
:=
r
.
Infos
()
if
err
!=
nil
{
if
apierrors
.
IsNotFound
(
err
)
&&
len
(
args
)
==
2
{
return
DescribeMatchingResources
(
mapper
,
typer
,
f
,
cmdNamespace
,
args
[
0
],
args
[
1
],
describerSettings
,
out
,
err
)
return
DescribeMatchingResources
(
f
,
cmdNamespace
,
args
[
0
],
args
[
1
],
describerSettings
,
out
,
err
)
}
allErrs
=
append
(
allErrs
,
err
)
}
...
...
@@ -176,7 +174,7 @@ func RunDescribe(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, a
return
utilerrors
.
NewAggregate
(
allErrs
)
}
func
DescribeMatchingResources
(
mapper
meta
.
RESTMapper
,
typer
runtime
.
ObjectTyper
,
f
cmdutil
.
Factory
,
namespace
,
rsrc
,
prefix
string
,
describerSettings
*
printers
.
DescriberSettings
,
out
io
.
Writer
,
originalError
error
)
error
{
func
DescribeMatchingResources
(
f
cmdutil
.
Factory
,
namespace
,
rsrc
,
prefix
string
,
describerSettings
*
printers
.
DescriberSettings
,
out
io
.
Writer
,
originalError
error
)
error
{
mapper
,
typer
,
err
:=
f
.
UnstructuredObject
()
if
err
!=
nil
{
return
err
...
...
pkg/kubectl/cmd/edit.go
View file @
810dbc5e
...
...
@@ -286,9 +286,9 @@ func runEdit(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args
switch
editMode
{
case
NormalEditMode
:
err
=
visitToPatch
(
infos
,
updatedVisitor
,
mapper
,
encoder
,
out
,
errOut
,
&
results
,
file
)
err
=
visitToPatch
(
infos
,
updatedVisitor
,
mapper
,
encoder
,
out
,
errOut
,
&
results
)
case
EditBeforeCreateMode
:
err
=
visitToCreate
(
updatedVisitor
,
mapper
,
out
,
errOut
,
&
results
,
file
)
err
=
visitToCreate
(
updatedVisitor
,
mapper
,
out
)
default
:
err
=
fmt
.
Errorf
(
"Unsupported edit mode %q"
,
editMode
)
}
...
...
@@ -420,7 +420,6 @@ func visitToPatch(
encoder
runtime
.
Encoder
,
out
,
errOut
io
.
Writer
,
results
*
editResults
,
file
string
,
)
error
{
err
:=
patchVisitor
.
Visit
(
func
(
info
*
resource
.
Info
,
incomingErr
error
)
error
{
editObjUID
,
err
:=
meta
.
NewAccessor
()
.
UID
(
info
.
Object
)
...
...
@@ -521,7 +520,7 @@ func visitToPatch(
return
err
}
func
visitToCreate
(
createVisitor
resource
.
Visitor
,
mapper
meta
.
RESTMapper
,
out
,
errOut
io
.
Writer
,
results
*
editResults
,
file
string
)
error
{
func
visitToCreate
(
createVisitor
resource
.
Visitor
,
mapper
meta
.
RESTMapper
,
out
io
.
Writer
)
error
{
err
:=
createVisitor
.
Visit
(
func
(
info
*
resource
.
Info
,
incomingErr
error
)
error
{
if
err
:=
createAndRefresh
(
info
);
err
!=
nil
{
return
err
...
...
pkg/kubectl/cmd/expose.go
View file @
810dbc5e
...
...
@@ -231,7 +231,7 @@ func RunExpose(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
if
inline
:=
cmdutil
.
GetFlagString
(
cmd
,
"overrides"
);
len
(
inline
)
>
0
{
codec
:=
runtime
.
NewCodec
(
f
.
JSONEncoder
(),
f
.
Decoder
(
true
))
object
,
err
=
cmdutil
.
Merge
(
codec
,
object
,
inline
,
mapping
.
GroupVersionKind
.
Kind
)
object
,
err
=
cmdutil
.
Merge
(
codec
,
object
,
inline
)
if
err
!=
nil
{
return
err
}
...
...
pkg/kubectl/cmd/get.go
View file @
810dbc5e
...
...
@@ -504,6 +504,6 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
}
}
w
.
Flush
()
cmdutil
.
PrintFilterCount
(
errOut
,
len
(
objs
),
filteredResourceCount
,
len
(
allErrs
),
""
,
filterOpts
,
options
.
IgnoreNotFound
)
cmdutil
.
PrintFilterCount
(
errOut
,
len
(
objs
),
filteredResourceCount
,
len
(
allErrs
),
filterOpts
,
options
.
IgnoreNotFound
)
return
utilerrors
.
NewAggregate
(
allErrs
)
}
pkg/kubectl/cmd/help.go
View file @
810dbc5e
...
...
@@ -17,13 +17,11 @@ limitations under the License.
package
cmd
import
(
"io"
"strings"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/util/i18n"
)
...
...
@@ -31,7 +29,7 @@ var help_long = templates.LongDesc(`
Help provides help for any command in the application.
Simply type kubectl help [path to command] for full details.`
)
func
NewCmdHelp
(
f
cmdutil
.
Factory
,
out
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdHelp
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"help [command] | STRING_TO_SEARCH"
,
Short
:
i18n
.
T
(
"Help about any command"
),
...
...
pkg/kubectl/cmd/label.go
View file @
810dbc5e
...
...
@@ -115,7 +115,7 @@ func NewCmdLabel(f cmdutil.Factory, out io.Writer) *cobra.Command {
Long
:
fmt
.
Sprintf
(
label_long
,
validation
.
LabelValueMaxLength
),
Example
:
label_example
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
err
:=
options
.
Complete
(
f
,
out
,
cmd
,
args
);
err
!=
nil
{
if
err
:=
options
.
Complete
(
out
,
cmd
,
args
);
err
!=
nil
{
cmdutil
.
CheckErr
(
cmdutil
.
UsageError
(
cmd
,
err
.
Error
()))
}
if
err
:=
options
.
Validate
();
err
!=
nil
{
...
...
@@ -142,7 +142,7 @@ func NewCmdLabel(f cmdutil.Factory, out io.Writer) *cobra.Command {
}
// Complete adapts from the command line args and factory to the data required.
func
(
o
*
LabelOptions
)
Complete
(
f
cmdutil
.
Factory
,
out
io
.
Writer
,
cmd
*
cobra
.
Command
,
args
[]
string
)
(
err
error
)
{
func
(
o
*
LabelOptions
)
Complete
(
out
io
.
Writer
,
cmd
*
cobra
.
Command
,
args
[]
string
)
(
err
error
)
{
o
.
out
=
out
o
.
local
=
cmdutil
.
GetFlagBool
(
cmd
,
"local"
)
o
.
overwrite
=
cmdutil
.
GetFlagBool
(
cmd
,
"overwrite"
)
...
...
pkg/kubectl/cmd/label_test.go
View file @
810dbc5e
...
...
@@ -325,7 +325,7 @@ func TestLabelErrors(t *testing.T) {
cmd
.
Flags
()
.
Set
(
k
,
v
)
}
opts
:=
LabelOptions
{}
err
:=
opts
.
Complete
(
f
,
buf
,
cmd
,
testCase
.
args
)
err
:=
opts
.
Complete
(
buf
,
cmd
,
testCase
.
args
)
if
err
==
nil
{
err
=
opts
.
Validate
()
}
...
...
@@ -382,7 +382,7 @@ func TestLabelForResourceFromFile(t *testing.T) {
cmd
:=
NewCmdLabel
(
f
,
buf
)
opts
:=
LabelOptions
{
FilenameOptions
:
resource
.
FilenameOptions
{
Filenames
:
[]
string
{
"../../../examples/storage/cassandra/cassandra-controller.yaml"
}}}
err
:=
opts
.
Complete
(
f
,
buf
,
cmd
,
[]
string
{
"a=b"
})
err
:=
opts
.
Complete
(
buf
,
cmd
,
[]
string
{
"a=b"
})
if
err
==
nil
{
err
=
opts
.
Validate
()
}
...
...
@@ -415,7 +415,7 @@ func TestLabelLocal(t *testing.T) {
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
opts
:=
LabelOptions
{
FilenameOptions
:
resource
.
FilenameOptions
{
Filenames
:
[]
string
{
"../../../examples/storage/cassandra/cassandra-controller.yaml"
}}}
err
:=
opts
.
Complete
(
f
,
buf
,
cmd
,
[]
string
{
"a=b"
})
err
:=
opts
.
Complete
(
buf
,
cmd
,
[]
string
{
"a=b"
})
if
err
==
nil
{
err
=
opts
.
Validate
()
}
...
...
@@ -470,7 +470,7 @@ func TestLabelMultipleObjects(t *testing.T) {
cmd
.
Flags
()
.
Set
(
"all"
,
"true"
)
opts
:=
LabelOptions
{}
err
:=
opts
.
Complete
(
f
,
buf
,
cmd
,
[]
string
{
"pods"
,
"a=b"
})
err
:=
opts
.
Complete
(
buf
,
cmd
,
[]
string
{
"pods"
,
"a=b"
})
if
err
==
nil
{
err
=
opts
.
Validate
()
}
...
...
pkg/kubectl/cmd/options.go
View file @
810dbc5e
...
...
@@ -17,8 +17,6 @@ limitations under the License.
package
cmd
import
(
"io"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
"k8s.io/kubernetes/pkg/util/i18n"
...
...
@@ -32,7 +30,7 @@ var (
)
// NewCmdOptions implements the options command
func
NewCmdOptions
(
out
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdOptions
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"options"
,
Short
:
i18n
.
T
(
"Print the list of flags inherited by all commands"
),
...
...
pkg/kubectl/cmd/portforward.go
View file @
810dbc5e
...
...
@@ -77,7 +77,7 @@ func NewCmdPortForward(f cmdutil.Factory, cmdOut, cmdErr io.Writer) *cobra.Comma
Long
:
"Forward one or more local ports to a pod."
,
Example
:
portforward_example
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
err
:=
opts
.
Complete
(
f
,
cmd
,
args
,
cmdOut
,
cmdErr
);
err
!=
nil
{
if
err
:=
opts
.
Complete
(
f
,
cmd
,
args
);
err
!=
nil
{
cmdutil
.
CheckErr
(
err
)
}
if
err
:=
opts
.
Validate
();
err
!=
nil
{
...
...
@@ -114,7 +114,7 @@ func (f *defaultPortForwarder) ForwardPorts(method string, url *url.URL, opts Po
}
// Complete completes all the required options for port-forward cmd.
func
(
o
*
PortForwardOptions
)
Complete
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
args
[]
string
,
cmdOut
io
.
Writer
,
cmdErr
io
.
Writer
)
error
{
func
(
o
*
PortForwardOptions
)
Complete
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
var
err
error
o
.
PodName
=
cmdutil
.
GetFlagString
(
cmd
,
"pod"
)
if
len
(
o
.
PodName
)
==
0
&&
len
(
args
)
==
0
{
...
...
pkg/kubectl/cmd/portforward_test.go
View file @
810dbc5e
...
...
@@ -93,7 +93,7 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) {
opts
:=
&
PortForwardOptions
{}
cmd
:=
NewCmdPortForward
(
f
,
os
.
Stdout
,
os
.
Stderr
)
cmd
.
Run
=
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
err
=
opts
.
Complete
(
f
,
cmd
,
args
,
os
.
Stdout
,
os
.
Stderr
);
err
!=
nil
{
if
err
=
opts
.
Complete
(
f
,
cmd
,
args
);
err
!=
nil
{
return
}
opts
.
PortForwarder
=
ff
...
...
pkg/kubectl/cmd/run.go
View file @
810dbc5e
...
...
@@ -313,7 +313,7 @@ func Run(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cobr
if
err
!=
nil
{
return
err
}
err
=
handleAttachPod
(
f
,
clientset
.
Core
(),
attachablePod
.
Namespace
,
attachablePod
.
Name
,
opts
,
quiet
)
err
=
handleAttachPod
(
f
,
clientset
.
Core
(),
attachablePod
.
Namespace
,
attachablePod
.
Name
,
opts
)
if
err
!=
nil
{
return
err
}
...
...
@@ -322,7 +322,7 @@ func Run(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cobr
leaveStdinOpen
:=
cmdutil
.
GetFlagBool
(
cmd
,
"leave-stdin-open"
)
waitForExitCode
:=
!
leaveStdinOpen
&&
restartPolicy
==
api
.
RestartPolicyNever
if
waitForExitCode
{
pod
,
err
=
waitForPodTerminated
(
clientset
.
Core
(),
attachablePod
.
Namespace
,
attachablePod
.
Name
,
opts
.
Out
,
quiet
)
pod
,
err
=
waitForPodTerminated
(
clientset
.
Core
(),
attachablePod
.
Namespace
,
attachablePod
.
Name
)
if
err
!=
nil
{
return
err
}
...
...
@@ -419,7 +419,7 @@ func waitForPod(podClient coreclient.PodsGetter, ns, name string, exitCondition
return
result
,
err
}
func
waitForPodRunning
(
podClient
coreclient
.
PodsGetter
,
ns
,
name
string
,
out
io
.
Writer
,
quiet
bool
)
(
*
api
.
Pod
,
error
)
{
func
waitForPodRunning
(
podClient
coreclient
.
PodsGetter
,
ns
,
name
string
)
(
*
api
.
Pod
,
error
)
{
pod
,
err
:=
waitForPod
(
podClient
,
ns
,
name
,
conditions
.
PodRunningAndReady
)
// fix generic not found error with empty name in PodRunningAndReady
...
...
@@ -430,7 +430,7 @@ func waitForPodRunning(podClient coreclient.PodsGetter, ns, name string, out io.
return
pod
,
err
}
func
waitForPodTerminated
(
podClient
coreclient
.
PodsGetter
,
ns
,
name
string
,
out
io
.
Writer
,
quiet
bool
)
(
*
api
.
Pod
,
error
)
{
func
waitForPodTerminated
(
podClient
coreclient
.
PodsGetter
,
ns
,
name
string
)
(
*
api
.
Pod
,
error
)
{
pod
,
err
:=
waitForPod
(
podClient
,
ns
,
name
,
conditions
.
PodCompleted
)
// fix generic not found error with empty name in PodCompleted
...
...
@@ -441,8 +441,8 @@ func waitForPodTerminated(podClient coreclient.PodsGetter, ns, name string, out
return
pod
,
err
}
func
handleAttachPod
(
f
cmdutil
.
Factory
,
podClient
coreclient
.
PodsGetter
,
ns
,
name
string
,
opts
*
AttachOptions
,
quiet
bool
)
error
{
pod
,
err
:=
waitForPodRunning
(
podClient
,
ns
,
name
,
opts
.
Out
,
quiet
)
func
handleAttachPod
(
f
cmdutil
.
Factory
,
podClient
coreclient
.
PodsGetter
,
ns
,
name
string
,
opts
*
AttachOptions
)
error
{
pod
,
err
:=
waitForPodRunning
(
podClient
,
ns
,
name
)
if
err
!=
nil
&&
err
!=
conditions
.
ErrPodCompleted
{
return
err
}
...
...
@@ -589,7 +589,7 @@ func createGeneratedObject(f cmdutil.Factory, cmd *cobra.Command, generator kube
if
len
(
overrides
)
>
0
{
codec
:=
runtime
.
NewCodec
(
f
.
JSONEncoder
(),
f
.
Decoder
(
true
))
obj
,
err
=
cmdutil
.
Merge
(
codec
,
obj
,
overrides
,
groupVersionKind
.
Kind
)
obj
,
err
=
cmdutil
.
Merge
(
codec
,
obj
,
overrides
)
if
err
!=
nil
{
return
nil
,
""
,
nil
,
nil
,
err
}
...
...
pkg/kubectl/cmd/set/set_selector.go
View file @
810dbc5e
...
...
@@ -83,7 +83,7 @@ func NewCmdSelector(f cmdutil.Factory, out io.Writer) *cobra.Command {
Long
:
fmt
.
Sprintf
(
selectorLong
,
validation
.
LabelValueMaxLength
),
Example
:
selectorExample
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
cmdutil
.
CheckErr
(
options
.
Complete
(
f
,
cmd
,
args
,
out
))
cmdutil
.
CheckErr
(
options
.
Complete
(
f
,
cmd
,
args
))
cmdutil
.
CheckErr
(
options
.
Validate
())
cmdutil
.
CheckErr
(
options
.
RunSelector
())
},
...
...
@@ -101,7 +101,7 @@ func NewCmdSelector(f cmdutil.Factory, out io.Writer) *cobra.Command {
}
// Complete assigns the SelectorOptions from args.
func
(
o
*
SelectorOptions
)
Complete
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
args
[]
string
,
out
io
.
Writer
)
error
{
func
(
o
*
SelectorOptions
)
Complete
(
f
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
o
.
local
=
cmdutil
.
GetFlagBool
(
cmd
,
"local"
)
o
.
all
=
cmdutil
.
GetFlagBool
(
cmd
,
"all"
)
o
.
record
=
cmdutil
.
GetRecordFlag
(
cmd
)
...
...
pkg/kubectl/cmd/taint.go
View file @
810dbc5e
...
...
@@ -91,7 +91,7 @@ func NewCmdTaint(f cmdutil.Factory, out io.Writer) *cobra.Command {
if
err
:=
options
.
Complete
(
f
,
out
,
cmd
,
args
);
err
!=
nil
{
cmdutil
.
CheckErr
(
err
)
}
if
err
:=
options
.
Validate
(
args
);
err
!=
nil
{
if
err
:=
options
.
Validate
();
err
!=
nil
{
cmdutil
.
CheckErr
(
cmdutil
.
UsageError
(
cmd
,
err
.
Error
()))
}
if
err
:=
options
.
RunTaint
();
err
!=
nil
{
...
...
@@ -249,7 +249,7 @@ func (o *TaintOptions) Complete(f cmdutil.Factory, out io.Writer, cmd *cobra.Com
}
// Validate checks to the TaintOptions to see if there is sufficient information run the command.
func
(
o
TaintOptions
)
Validate
(
args
[]
string
)
error
{
func
(
o
TaintOptions
)
Validate
()
error
{
resourceType
:=
strings
.
ToLower
(
o
.
resources
[
0
])
validResources
,
isValidResource
:=
append
(
kubectl
.
ResourceAliases
([]
string
{
"node"
}),
"node"
),
false
for
_
,
validResource
:=
range
validResources
{
...
...
pkg/kubectl/cmd/util/helpers.go
View file @
810dbc5e
...
...
@@ -441,7 +441,7 @@ func ReadConfigDataFromReader(reader io.Reader, source string) ([]byte, error) {
// Merge requires JSON serialization
// TODO: merge assumes JSON serialization, and does not properly abstract API retrieval
func
Merge
(
codec
runtime
.
Codec
,
dst
runtime
.
Object
,
fragment
,
kind
string
)
(
runtime
.
Object
,
error
)
{
func
Merge
(
codec
runtime
.
Codec
,
dst
runtime
.
Object
,
fragment
string
)
(
runtime
.
Object
,
error
)
{
// encode dst into versioned json and apply fragment directly too it
target
,
err
:=
runtime
.
Encode
(
codec
,
dst
)
if
err
!=
nil
{
...
...
@@ -712,7 +712,7 @@ func FilterResourceList(obj runtime.Object, filterFuncs kubectl.Filters, filterO
// PrintFilterCount displays informational messages based on the number of resources found, hidden, or
// config flags shown.
func
PrintFilterCount
(
out
io
.
Writer
,
found
,
hidden
,
errors
int
,
resource
string
,
options
*
printers
.
PrintOptions
,
ignoreNotFound
bool
)
{
func
PrintFilterCount
(
out
io
.
Writer
,
found
,
hidden
,
errors
int
,
options
*
printers
.
PrintOptions
,
ignoreNotFound
bool
)
{
switch
{
case
errors
>
0
||
ignoreNotFound
:
// print nothing
...
...
pkg/kubectl/cmd/util/helpers_test.go
View file @
810dbc5e
...
...
@@ -47,10 +47,8 @@ func TestMerge(t *testing.T) {
fragment
string
expected
runtime
.
Object
expectErr
bool
kind
string
}{
{
kind
:
"Pod"
,
obj
:
&
api
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
...
...
@@ -67,7 +65,6 @@ func TestMerge(t *testing.T) {
/* TODO: uncomment this test once Merge is updated to use
strategic-merge-patch. See #8449.
{
kind: "Pod",
obj: &api.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
...
...
@@ -105,7 +102,6 @@ func TestMerge(t *testing.T) {
},
}, */
{
kind
:
"Pod"
,
obj
:
&
api
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
...
...
@@ -136,20 +132,17 @@ func TestMerge(t *testing.T) {
},
},
{
kind
:
"Pod"
,
obj
:
&
api
.
Pod
{},
fragment
:
"invalid json"
,
expected
:
&
api
.
Pod
{},
expectErr
:
true
,
},
{
kind
:
"Service"
,
obj
:
&
api
.
Service
{},
fragment
:
`{ "apiVersion": "badVersion" }`
,
expectErr
:
true
,
},
{
kind
:
"Service"
,
obj
:
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{},
},
...
...
@@ -168,7 +161,6 @@ func TestMerge(t *testing.T) {
},
},
{
kind
:
"Service"
,
obj
:
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
...
...
@@ -190,7 +182,7 @@ func TestMerge(t *testing.T) {
}
for
i
,
test
:=
range
tests
{
out
,
err
:=
Merge
(
testapi
.
Default
.
Codec
(),
test
.
obj
,
test
.
fragment
,
test
.
kind
)
out
,
err
:=
Merge
(
testapi
.
Default
.
Codec
(),
test
.
obj
,
test
.
fragment
)
if
!
test
.
expectErr
{
if
err
!=
nil
{
t
.
Errorf
(
"testcase[%d], unexpected error: %v"
,
i
,
err
)
...
...
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