Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl/cmd: remove a bunch of unused parameters #43297

Merged
merged 1 commit into from
Apr 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion federation/pkg/kubefed/kubefed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/annotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions pkg/kubectl/cmd/annotate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/clusterinfo_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubectl/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
Expand All @@ -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, ""),
},
},
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/config/current_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ 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)
},
}

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
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/config/current_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubectl/cmd/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var (
)

// NewCmdCp creates a new Copy command.
func NewCmdCp(f cmdutil.Factory, cmdIn io.Reader, cmdOut, 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."),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions pkg/kubectl/cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions pkg/kubectl/cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/expose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 1 addition & 3 deletions pkg/kubectl/cmd/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@ 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"
)

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"),
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubectl/cmd/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/kubectl/cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"),
Expand Down