mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
update more commands for iostreams
This commit is contained in:
parent
3fb88a23d9
commit
8c1b687356
@ -255,17 +255,17 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
|
|||||||
Message: "Basic Commands (Beginner):",
|
Message: "Basic Commands (Beginner):",
|
||||||
Commands: []*cobra.Command{
|
Commands: []*cobra.Command{
|
||||||
create.NewCmdCreate(f, ioStreams),
|
create.NewCmdCreate(f, ioStreams),
|
||||||
NewCmdExposeService(f, out),
|
NewCmdExposeService(f, ioStreams),
|
||||||
NewCmdRun(f, in, out, err),
|
NewCmdRun(f, ioStreams),
|
||||||
set.NewCmdSet(f, in, out, err),
|
set.NewCmdSet(f, ioStreams),
|
||||||
deprecatedAlias("run-container", NewCmdRun(f, in, out, err)),
|
deprecatedAlias("run-container", NewCmdRun(f, ioStreams)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Message: "Basic Commands (Intermediate):",
|
Message: "Basic Commands (Intermediate):",
|
||||||
Commands: []*cobra.Command{
|
Commands: []*cobra.Command{
|
||||||
resource.NewCmdGet(f, out, err),
|
resource.NewCmdGet(f, ioStreams),
|
||||||
NewCmdExplain(f, out, err),
|
NewCmdExplain(f, ioStreams),
|
||||||
NewCmdEdit(f, ioStreams),
|
NewCmdEdit(f, ioStreams),
|
||||||
NewCmdDelete(f, out, err),
|
NewCmdDelete(f, out, err),
|
||||||
},
|
},
|
||||||
|
@ -43,6 +43,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/kubectl/cmd/resource"
|
"k8s.io/kubernetes/pkg/kubectl/cmd/resource"
|
||||||
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
||||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||||
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||||
"k8s.io/kubernetes/pkg/printers"
|
"k8s.io/kubernetes/pkg/printers"
|
||||||
"k8s.io/kubernetes/pkg/util/strings"
|
"k8s.io/kubernetes/pkg/util/strings"
|
||||||
@ -253,7 +254,7 @@ func Example_printServiceWithLabels() {
|
|||||||
NegotiatedSerializer: ns,
|
NegotiatedSerializer: ns,
|
||||||
Client: nil,
|
Client: nil,
|
||||||
}
|
}
|
||||||
cmd := resource.NewCmdGet(tf, os.Stdout, os.Stderr)
|
cmd := resource.NewCmdGet(tf, genericclioptions.NewTestIOStreamsDiscard())
|
||||||
svc := &api.ServiceList{
|
svc := &api.ServiceList{
|
||||||
Items: []api.Service{
|
Items: []api.Service{
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,6 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
@ -26,6 +25,7 @@ import (
|
|||||||
"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/explain"
|
"k8s.io/kubernetes/pkg/kubectl/explain"
|
||||||
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -49,8 +49,20 @@ var (
|
|||||||
kubectl explain pods.spec.containers`))
|
kubectl explain pods.spec.containers`))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ExplainOptions struct {
|
||||||
|
genericclioptions.IOStreams
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewExplainOptions(streams genericclioptions.IOStreams) *ExplainOptions {
|
||||||
|
return &ExplainOptions{
|
||||||
|
IOStreams: streams,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewCmdExplain returns a cobra command for swagger docs
|
// NewCmdExplain returns a cobra command for swagger docs
|
||||||
func NewCmdExplain(f cmdutil.Factory, out, cmdErr io.Writer) *cobra.Command {
|
func NewCmdExplain(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
|
o := NewExplainOptions(streams)
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "explain RESOURCE",
|
Use: "explain RESOURCE",
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
@ -58,7 +70,7 @@ func NewCmdExplain(f cmdutil.Factory, out, cmdErr io.Writer) *cobra.Command {
|
|||||||
Long: explainLong + "\n\n" + cmdutil.ValidResourceTypeList(f),
|
Long: explainLong + "\n\n" + cmdutil.ValidResourceTypeList(f),
|
||||||
Example: explainExamples,
|
Example: explainExamples,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
err := RunExplain(f, out, cmdErr, cmd, args)
|
err := o.RunExplain(f, cmd, args)
|
||||||
cmdutil.CheckErr(err)
|
cmdutil.CheckErr(err)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -68,9 +80,9 @@ func NewCmdExplain(f cmdutil.Factory, out, cmdErr io.Writer) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunExplain executes the appropriate steps to print a model's documentation
|
// RunExplain executes the appropriate steps to print a model's documentation
|
||||||
func RunExplain(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, args []string) error {
|
func (o *ExplainOptions) RunExplain(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
fmt.Fprintf(cmdErr, "You must specify the type of resource to explain. %s\n\n", cmdutil.ValidResourceTypeList(f))
|
fmt.Fprintf(o.ErrOut, "You must specify the type of resource to explain. %s\n\n", cmdutil.ValidResourceTypeList(f))
|
||||||
return cmdutil.UsageErrorf(cmd, "Required resource not specified.")
|
return cmdutil.UsageErrorf(cmd, "Required resource not specified.")
|
||||||
}
|
}
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
@ -120,5 +132,5 @@ func RunExplain(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, ar
|
|||||||
return fmt.Errorf("Couldn't find resource for %q", gvk)
|
return fmt.Errorf("Couldn't find resource for %q", gvk)
|
||||||
}
|
}
|
||||||
|
|
||||||
return explain.PrintModelDescription(fieldsPath, out, schema, gvk, recursive)
|
return explain.PrintModelDescription(fieldsPath, o.Out, schema, gvk, recursive)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -79,18 +78,20 @@ type ExposeServiceOptions struct {
|
|||||||
RecordFlags *genericclioptions.RecordFlags
|
RecordFlags *genericclioptions.RecordFlags
|
||||||
|
|
||||||
Recorder genericclioptions.Recorder
|
Recorder genericclioptions.Recorder
|
||||||
|
genericclioptions.IOStreams
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExposeServiceOptions() *ExposeServiceOptions {
|
func NewExposeServiceOptions(streams genericclioptions.IOStreams) *ExposeServiceOptions {
|
||||||
return &ExposeServiceOptions{
|
return &ExposeServiceOptions{
|
||||||
RecordFlags: genericclioptions.NewRecordFlags(),
|
RecordFlags: genericclioptions.NewRecordFlags(),
|
||||||
|
|
||||||
Recorder: genericclioptions.NoopRecorder{},
|
Recorder: genericclioptions.NoopRecorder{},
|
||||||
|
IOStreams: streams,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCmdExposeService(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
func NewCmdExposeService(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
o := NewExposeServiceOptions()
|
o := NewExposeServiceOptions(streams)
|
||||||
|
|
||||||
validArgs := []string{}
|
validArgs := []string{}
|
||||||
resources := regexp.MustCompile(`\s*,`).Split(exposeResources, -1)
|
resources := regexp.MustCompile(`\s*,`).Split(exposeResources, -1)
|
||||||
@ -106,7 +107,7 @@ func NewCmdExposeService(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
|||||||
Example: exposeExample,
|
Example: exposeExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cmdutil.CheckErr(o.Complete(f, cmd))
|
cmdutil.CheckErr(o.Complete(f, cmd))
|
||||||
cmdutil.CheckErr(o.RunExpose(f, out, cmd, args))
|
cmdutil.CheckErr(o.RunExpose(f, cmd, args))
|
||||||
},
|
},
|
||||||
ValidArgs: validArgs,
|
ValidArgs: validArgs,
|
||||||
ArgAliases: kubectl.ResourceAliases(validArgs),
|
ArgAliases: kubectl.ResourceAliases(validArgs),
|
||||||
@ -150,7 +151,7 @@ func (o *ExposeServiceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) e
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ExposeServiceOptions) RunExpose(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
|
func (o *ExposeServiceOptions) RunExpose(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||||
namespace, enforceNamespace, err := f.DefaultNamespace()
|
namespace, enforceNamespace, err := f.DefaultNamespace()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -284,9 +285,9 @@ func (o *ExposeServiceOptions) RunExpose(f cmdutil.Factory, out io.Writer, cmd *
|
|||||||
info.Refresh(object, true)
|
info.Refresh(object, true)
|
||||||
if cmdutil.GetDryRunFlag(cmd) {
|
if cmdutil.GetDryRunFlag(cmd) {
|
||||||
if len(cmdutil.GetFlagString(cmd, "output")) > 0 {
|
if len(cmdutil.GetFlagString(cmd, "output")) > 0 {
|
||||||
return cmdutil.PrintObject(cmd, object, out)
|
return cmdutil.PrintObject(cmd, object, o.Out)
|
||||||
}
|
}
|
||||||
cmdutil.PrintSuccess(false, out, info.Object, true, "exposed")
|
cmdutil.PrintSuccess(false, o.Out, info.Object, true, "exposed")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := kubectl.CreateOrUpdateAnnotation(cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag), info.Object, cmdutil.InternalVersionJSONEncoder()); err != nil {
|
if err := kubectl.CreateOrUpdateAnnotation(cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag), info.Object, cmdutil.InternalVersionJSONEncoder()); err != nil {
|
||||||
@ -300,10 +301,10 @@ func (o *ExposeServiceOptions) RunExpose(f cmdutil.Factory, out io.Writer, cmd *
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(cmdutil.GetFlagString(cmd, "output")) > 0 {
|
if len(cmdutil.GetFlagString(cmd, "output")) > 0 {
|
||||||
return cmdutil.PrintObject(cmd, object, out)
|
return cmdutil.PrintObject(cmd, object, o.Out)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdutil.PrintSuccess(false, out, info.Object, false, "exposed")
|
cmdutil.PrintSuccess(false, o.Out, info.Object, false, "exposed")
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@ -31,6 +30,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
api "k8s.io/kubernetes/pkg/apis/core"
|
||||||
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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -489,9 +489,9 @@ func TestRunExposeService(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
tf.Namespace = test.ns
|
tf.Namespace = test.ns
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdExposeService(tf, buf)
|
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdExposeService(tf, ioStreams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
for flag, value := range test.flags {
|
for flag, value := range test.flags {
|
||||||
cmd.Flags().Set(flag, value)
|
cmd.Flags().Set(flag, value)
|
||||||
|
@ -11,6 +11,7 @@ go_library(
|
|||||||
"//pkg/kubectl/cmd/templates:go_default_library",
|
"//pkg/kubectl/cmd/templates:go_default_library",
|
||||||
"//pkg/kubectl/cmd/util:go_default_library",
|
"//pkg/kubectl/cmd/util:go_default_library",
|
||||||
"//pkg/kubectl/cmd/util/openapi:go_default_library",
|
"//pkg/kubectl/cmd/util/openapi:go_default_library",
|
||||||
|
"//pkg/kubectl/genericclioptions:go_default_library",
|
||||||
"//pkg/kubectl/resource:go_default_library",
|
"//pkg/kubectl/resource:go_default_library",
|
||||||
"//pkg/kubectl/util/i18n:go_default_library",
|
"//pkg/kubectl/util/i18n:go_default_library",
|
||||||
"//pkg/printers:go_default_library",
|
"//pkg/printers:go_default_library",
|
||||||
@ -50,6 +51,7 @@ go_test(
|
|||||||
"//pkg/kubectl/cmd/util:go_default_library",
|
"//pkg/kubectl/cmd/util:go_default_library",
|
||||||
"//pkg/kubectl/cmd/util/openapi:go_default_library",
|
"//pkg/kubectl/cmd/util/openapi:go_default_library",
|
||||||
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
|
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
|
||||||
|
"//pkg/kubectl/genericclioptions:go_default_library",
|
||||||
"//pkg/kubectl/scheme:go_default_library",
|
"//pkg/kubectl/scheme:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
||||||
|
@ -43,6 +43,7 @@ import (
|
|||||||
"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/cmd/util/openapi"
|
||||||
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
||||||
"k8s.io/kubernetes/pkg/printers"
|
"k8s.io/kubernetes/pkg/printers"
|
||||||
@ -51,8 +52,6 @@ import (
|
|||||||
|
|
||||||
// GetOptions contains the input to the get command.
|
// GetOptions contains the input to the get command.
|
||||||
type GetOptions struct {
|
type GetOptions struct {
|
||||||
Out, ErrOut io.Writer
|
|
||||||
|
|
||||||
resource.FilenameOptions
|
resource.FilenameOptions
|
||||||
|
|
||||||
Raw string
|
Raw string
|
||||||
@ -75,6 +74,8 @@ type GetOptions struct {
|
|||||||
Export bool
|
Export bool
|
||||||
|
|
||||||
IncludeUninitialized bool
|
IncludeUninitialized bool
|
||||||
|
|
||||||
|
genericclioptions.IOStreams
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -126,18 +127,18 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewGetOptions returns a GetOptions with default chunk size 500.
|
// NewGetOptions returns a GetOptions with default chunk size 500.
|
||||||
func NewGetOptions(out io.Writer, errOut io.Writer) *GetOptions {
|
func NewGetOptions(streams genericclioptions.IOStreams) *GetOptions {
|
||||||
return &GetOptions{
|
return &GetOptions{
|
||||||
Out: out,
|
|
||||||
ErrOut: errOut,
|
|
||||||
ChunkSize: 500,
|
ChunkSize: 500,
|
||||||
|
|
||||||
|
IOStreams: streams,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, out io.Writer, errOut io.Writer) *cobra.Command {
|
func NewCmdGet(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
options := NewGetOptions(out, errOut)
|
options := NewGetOptions(streams)
|
||||||
validArgs := cmdutil.ValidArgList(f)
|
validArgs := cmdutil.ValidArgList(f)
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
|
@ -50,6 +50,7 @@ import (
|
|||||||
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/cmd/util/openapi"
|
||||||
openapitesting "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing"
|
openapitesting "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing"
|
||||||
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -211,10 +212,8 @@ func TestGetUnknownSchemaObject(t *testing.T) {
|
|||||||
t.Fatalf("unexpected conversion of unstructured object to structured: %s", diff.ObjectReflectDiff(convertedObj, obj))
|
t.Fatalf("unexpected conversion of unstructured object to structured: %s", diff.ObjectReflectDiff(convertedObj, obj))
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
cmd := NewCmdGet(tf, streams)
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Run(cmd, []string{"type", "foo"})
|
cmd.Run(cmd, []string{"type", "foo"})
|
||||||
|
|
||||||
@ -254,10 +253,9 @@ func TestGetSchemaObject(t *testing.T) {
|
|||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
tf.ClientConfigVal = defaultClientConfig()
|
tf.ClientConfigVal = defaultClientConfig()
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(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,10 +278,9 @@ func TestGetObjectsWithOpenAPIOutputFormatPresent(t *testing.T) {
|
|||||||
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
|
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(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"})
|
||||||
@ -335,10 +332,9 @@ func TestGetObjects(t *testing.T) {
|
|||||||
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
|
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Run(cmd, []string{"pods", "foo"})
|
cmd.Run(cmd, []string{"pods", "foo"})
|
||||||
|
|
||||||
@ -384,10 +380,9 @@ func TestGetObjectIgnoreNotFound(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(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")
|
||||||
@ -430,10 +425,8 @@ func TestGetSortedObjects(t *testing.T) {
|
|||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: "v1"}}}
|
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: "v1"}}}
|
||||||
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
cmd := NewCmdGet(tf, streams)
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
|
|
||||||
// sorting with metedata.name
|
// sorting with metedata.name
|
||||||
@ -462,10 +455,9 @@ func TestGetObjectsIdentifiedByFile(t *testing.T) {
|
|||||||
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
|
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(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{})
|
||||||
@ -490,10 +482,9 @@ func TestGetListObjects(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)},
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Run(cmd, []string{"pods"})
|
cmd.Run(cmd, []string{"pods"})
|
||||||
|
|
||||||
@ -518,10 +509,9 @@ func TestGetAllListObjects(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)},
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Flags().Set("show-all", "true")
|
cmd.Flags().Set("show-all", "true")
|
||||||
cmd.Run(cmd, []string{"pods"})
|
cmd.Run(cmd, []string{"pods"})
|
||||||
@ -547,10 +537,9 @@ func TestGetListComponentStatus(t *testing.T) {
|
|||||||
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, statuses)},
|
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, statuses)},
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Run(cmd, []string{"componentstatuses"})
|
cmd.Run(cmd, []string{"componentstatuses"})
|
||||||
|
|
||||||
@ -598,10 +587,9 @@ func TestGetMixedGenericObjects(t *testing.T) {
|
|||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
tf.ClientConfigVal = defaultClientConfig()
|
tf.ClientConfigVal = defaultClientConfig()
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(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"})
|
||||||
@ -650,10 +638,9 @@ func TestGetMultipleTypeObjects(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Run(cmd, []string{"pods,services"})
|
cmd.Run(cmd, []string{"pods,services"})
|
||||||
|
|
||||||
@ -691,10 +678,9 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
tf.ClientConfigVal = defaultClientConfig()
|
tf.ClientConfigVal = defaultClientConfig()
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
|
|
||||||
cmd.Flags().Set("output", "json")
|
cmd.Flags().Set("output", "json")
|
||||||
@ -796,10 +782,9 @@ func TestGetMultipleTypeObjectsWithLabelSelector(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
|
|
||||||
cmd.Flags().Set("selector", "a=b")
|
cmd.Flags().Set("selector", "a=b")
|
||||||
@ -841,10 +826,9 @@ func TestGetMultipleTypeObjectsWithFieldSelector(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
|
|
||||||
cmd.Flags().Set("field-selector", "a=b")
|
cmd.Flags().Set("field-selector", "a=b")
|
||||||
@ -888,10 +872,9 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
|
|
||||||
cmd.Run(cmd, []string{"services/bar", "node/foo"})
|
cmd.Run(cmd, []string{"services/bar", "node/foo"})
|
||||||
@ -918,10 +901,9 @@ func TestGetByFormatForcesFlag(t *testing.T) {
|
|||||||
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
|
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Flags().Lookup("output").Value.Set("yaml")
|
cmd.Flags().Lookup("output").Value.Set("yaml")
|
||||||
cmd.Flags().Set("show-all", "false")
|
cmd.Flags().Set("show-all", "false")
|
||||||
@ -1035,10 +1017,9 @@ func TestWatchLabelSelector(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
|
|
||||||
cmd.Flags().Set("watch", "true")
|
cmd.Flags().Set("watch", "true")
|
||||||
@ -1088,10 +1069,9 @@ func TestWatchFieldSelector(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
|
|
||||||
cmd.Flags().Set("watch", "true")
|
cmd.Flags().Set("watch", "true")
|
||||||
@ -1135,10 +1115,9 @@ func TestWatchResource(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
|
|
||||||
cmd.Flags().Set("watch", "true")
|
cmd.Flags().Set("watch", "true")
|
||||||
@ -1180,10 +1159,9 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
|
|
||||||
cmd.Flags().Set("watch", "true")
|
cmd.Flags().Set("watch", "true")
|
||||||
@ -1226,10 +1204,9 @@ func TestWatchOnlyResource(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
|
|
||||||
cmd.Flags().Set("watch-only", "true")
|
cmd.Flags().Set("watch-only", "true")
|
||||||
@ -1273,10 +1250,9 @@ func TestWatchOnlyList(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
buf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdGet(tf, buf, errBuf)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdGet(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
|
|
||||||
cmd.Flags().Set("watch-only", "true")
|
cmd.Flags().Set("watch-only", "true")
|
||||||
|
@ -118,12 +118,10 @@ type RunOptions struct {
|
|||||||
Schedule string
|
Schedule string
|
||||||
TTY bool
|
TTY bool
|
||||||
|
|
||||||
In io.Reader
|
genericclioptions.IOStreams
|
||||||
Out io.Writer
|
|
||||||
ErrOut io.Writer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRunOptions(in io.Reader, out, errOut io.Writer) *RunOptions {
|
func NewRunOptions(streams genericclioptions.IOStreams) *RunOptions {
|
||||||
return &RunOptions{
|
return &RunOptions{
|
||||||
PrintFlags: printers.NewPrintFlags("created"),
|
PrintFlags: printers.NewPrintFlags("created"),
|
||||||
DeleteFlags: NewDeleteFlags("to use to replace the resource."),
|
DeleteFlags: NewDeleteFlags("to use to replace the resource."),
|
||||||
@ -131,14 +129,12 @@ func NewRunOptions(in io.Reader, out, errOut io.Writer) *RunOptions {
|
|||||||
|
|
||||||
Recorder: genericclioptions.NoopRecorder{},
|
Recorder: genericclioptions.NoopRecorder{},
|
||||||
|
|
||||||
In: in,
|
IOStreams: streams,
|
||||||
Out: out,
|
|
||||||
ErrOut: errOut,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCmdRun(f cmdutil.Factory, in io.Reader, out, errOut io.Writer) *cobra.Command {
|
func NewCmdRun(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
o := NewRunOptions(in, out, errOut)
|
o := NewRunOptions(streams)
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "run NAME --image=image [--env=\"key=value\"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [--command] -- [COMMAND] [args...]",
|
Use: "run NAME --image=image [--env=\"key=value\"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [--command] -- [COMMAND] [args...]",
|
||||||
|
@ -194,7 +194,7 @@ func TestRunArgsFollowDashRules(t *testing.T) {
|
|||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
tf.ClientConfigVal = &restclient.Config{}
|
tf.ClientConfigVal = &restclient.Config{}
|
||||||
|
|
||||||
cmd := NewCmdRun(tf, os.Stdin, os.Stdout, os.Stderr)
|
cmd := NewCmdRun(tf, genericclioptions.NewTestIOStreamsDiscard())
|
||||||
cmd.Flags().Set("image", "nginx")
|
cmd.Flags().Set("image", "nginx")
|
||||||
cmd.Flags().Set("generator", "run/v1")
|
cmd.Flags().Set("generator", "run/v1")
|
||||||
|
|
||||||
@ -210,9 +210,7 @@ func TestRunArgsFollowDashRules(t *testing.T) {
|
|||||||
PrintFlags: printFlags,
|
PrintFlags: printFlags,
|
||||||
DeleteOptions: deleteFlags.ToOptions(os.Stdout, os.Stderr),
|
DeleteOptions: deleteFlags.ToOptions(os.Stdout, os.Stderr),
|
||||||
|
|
||||||
In: os.Stdin,
|
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
|
||||||
Out: os.Stdout,
|
|
||||||
ErrOut: os.Stderr,
|
|
||||||
|
|
||||||
Image: "nginx",
|
Image: "nginx",
|
||||||
Generator: "run/v1",
|
Generator: "run/v1",
|
||||||
@ -375,14 +373,13 @@ func TestGenerateService(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ioStreams, _, buff, _ := genericclioptions.NewTestIOStreams()
|
||||||
deleteFlags := NewDeleteFlags("to use to replace the resource.")
|
deleteFlags := NewDeleteFlags("to use to replace the resource.")
|
||||||
buff := &bytes.Buffer{}
|
|
||||||
opts := &RunOptions{
|
opts := &RunOptions{
|
||||||
PrintFlags: printFlags,
|
PrintFlags: printFlags,
|
||||||
DeleteOptions: deleteFlags.ToOptions(os.Stdout, os.Stderr),
|
DeleteOptions: deleteFlags.ToOptions(os.Stdout, os.Stderr),
|
||||||
|
|
||||||
Out: buff,
|
IOStreams: ioStreams,
|
||||||
ErrOut: buff,
|
|
||||||
|
|
||||||
Port: test.port,
|
Port: test.port,
|
||||||
Recorder: genericclioptions.NoopRecorder{},
|
Recorder: genericclioptions.NoopRecorder{},
|
||||||
@ -519,19 +516,17 @@ func TestRunValidations(t *testing.T) {
|
|||||||
}
|
}
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
tf.ClientConfigVal = defaultClientConfig()
|
tf.ClientConfigVal = defaultClientConfig()
|
||||||
inBuf := bytes.NewReader([]byte{})
|
|
||||||
outBuf := bytes.NewBuffer([]byte{})
|
|
||||||
errBuf := bytes.NewBuffer([]byte{})
|
|
||||||
|
|
||||||
cmd := NewCmdRun(tf, inBuf, outBuf, errBuf)
|
streams, _, _, bufErr := genericclioptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdRun(tf, streams)
|
||||||
for flagName, flagValue := range test.flags {
|
for flagName, flagValue := range test.flags {
|
||||||
cmd.Flags().Set(flagName, flagValue)
|
cmd.Flags().Set(flagName, flagValue)
|
||||||
}
|
}
|
||||||
cmd.Run(cmd, test.args)
|
cmd.Run(cmd, test.args)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if errBuf.Len() > 0 {
|
if bufErr.Len() > 0 {
|
||||||
err = fmt.Errorf("%v", errBuf.String())
|
err = fmt.Errorf("%v", bufErr.String())
|
||||||
}
|
}
|
||||||
if err != nil && len(test.expectedErr) > 0 {
|
if err != nil && len(test.expectedErr) > 0 {
|
||||||
if !strings.Contains(err.Error(), test.expectedErr) {
|
if !strings.Contains(err.Error(), test.expectedErr) {
|
||||||
|
@ -66,6 +66,7 @@ go_test(
|
|||||||
"//pkg/apis/rbac:go_default_library",
|
"//pkg/apis/rbac:go_default_library",
|
||||||
"//pkg/kubectl/cmd/testing:go_default_library",
|
"//pkg/kubectl/cmd/testing:go_default_library",
|
||||||
"//pkg/kubectl/cmd/util:go_default_library",
|
"//pkg/kubectl/cmd/util:go_default_library",
|
||||||
|
"//pkg/kubectl/genericclioptions:go_default_library",
|
||||||
"//pkg/kubectl/resource:go_default_library",
|
"//pkg/kubectl/resource:go_default_library",
|
||||||
"//pkg/kubectl/scheme:go_default_library",
|
"//pkg/kubectl/scheme:go_default_library",
|
||||||
"//pkg/printers:go_default_library",
|
"//pkg/printers:go_default_library",
|
||||||
|
@ -17,11 +17,10 @@ limitations under the License.
|
|||||||
package set
|
package set
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"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/genericclioptions"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,22 +31,22 @@ var (
|
|||||||
These commands help you make changes to existing application resources.`)
|
These commands help you make changes to existing application resources.`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCmdSet(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cobra.Command {
|
func NewCmdSet(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "set SUBCOMMAND",
|
Use: "set SUBCOMMAND",
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
Short: i18n.T("Set specific features on objects"),
|
Short: i18n.T("Set specific features on objects"),
|
||||||
Long: set_long,
|
Long: set_long,
|
||||||
Run: cmdutil.DefaultSubCommandRun(err),
|
Run: cmdutil.DefaultSubCommandRun(streams.ErrOut),
|
||||||
}
|
}
|
||||||
|
|
||||||
// add subcommands
|
// add subcommands
|
||||||
cmd.AddCommand(NewCmdImage(f, out, err))
|
cmd.AddCommand(NewCmdImage(f, streams))
|
||||||
cmd.AddCommand(NewCmdResources(f, out, err))
|
cmd.AddCommand(NewCmdResources(f, streams))
|
||||||
cmd.AddCommand(NewCmdSelector(f, out))
|
cmd.AddCommand(NewCmdSelector(f, streams))
|
||||||
cmd.AddCommand(NewCmdSubject(f, out, err))
|
cmd.AddCommand(NewCmdSubject(f, streams))
|
||||||
cmd.AddCommand(NewCmdServiceAccount(f, out, err))
|
cmd.AddCommand(NewCmdServiceAccount(f, streams))
|
||||||
cmd.AddCommand(NewCmdEnv(f, in, out, err))
|
cmd.AddCommand(NewCmdEnv(f, streams))
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package set
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -36,6 +35,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/printers"
|
"k8s.io/kubernetes/pkg/printers"
|
||||||
|
|
||||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -94,10 +94,6 @@ var (
|
|||||||
type EnvOptions struct {
|
type EnvOptions struct {
|
||||||
PrintFlags *printers.PrintFlags
|
PrintFlags *printers.PrintFlags
|
||||||
|
|
||||||
Out io.Writer
|
|
||||||
Err io.Writer
|
|
||||||
In io.Reader
|
|
||||||
|
|
||||||
resource.FilenameOptions
|
resource.FilenameOptions
|
||||||
EnvParams []string
|
EnvParams []string
|
||||||
EnvArgs []string
|
EnvArgs []string
|
||||||
@ -123,25 +119,26 @@ type EnvOptions struct {
|
|||||||
Infos []*resource.Info
|
Infos []*resource.Info
|
||||||
|
|
||||||
UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error)
|
UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error)
|
||||||
|
|
||||||
|
genericclioptions.IOStreams
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEnvOptions returns an EnvOptions indicating all containers in the selected
|
// NewEnvOptions returns an EnvOptions indicating all containers in the selected
|
||||||
// pod templates are selected by default and allowing environment to be overwritten
|
// pod templates are selected by default and allowing environment to be overwritten
|
||||||
func NewEnvOptions(in io.Reader, out, errout io.Writer) *EnvOptions {
|
func NewEnvOptions(streams genericclioptions.IOStreams) *EnvOptions {
|
||||||
return &EnvOptions{
|
return &EnvOptions{
|
||||||
PrintFlags: printers.NewPrintFlags("env updated"),
|
PrintFlags: printers.NewPrintFlags("env updated"),
|
||||||
|
|
||||||
Out: out,
|
|
||||||
Err: errout,
|
|
||||||
In: in,
|
|
||||||
ContainerSelector: "*",
|
ContainerSelector: "*",
|
||||||
Overwrite: true,
|
Overwrite: true,
|
||||||
|
|
||||||
|
IOStreams: streams,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdEnv implements the OpenShift cli env command
|
// NewCmdEnv implements the OpenShift cli env command
|
||||||
func NewCmdEnv(f cmdutil.Factory, in io.Reader, out, errout io.Writer) *cobra.Command {
|
func NewCmdEnv(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
options := NewEnvOptions(in, out, errout)
|
options := NewEnvOptions(streams)
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "env RESOURCE/NAME KEY_1=VAL_1 ... KEY_N=VAL_N",
|
Use: "env RESOURCE/NAME KEY_1=VAL_1 ... KEY_N=VAL_N",
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
@ -346,7 +343,7 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
|
|||||||
resolutionErrorsEncountered := false
|
resolutionErrorsEncountered := false
|
||||||
containers, _ := selectContainers(spec.Containers, o.ContainerSelector)
|
containers, _ := selectContainers(spec.Containers, o.ContainerSelector)
|
||||||
if len(containers) == 0 {
|
if len(containers) == 0 {
|
||||||
fmt.Fprintf(o.Err, "warning: %s/%s does not have any containers matching %q\n", info.Mapping.Resource, info.Name, o.ContainerSelector)
|
fmt.Fprintf(o.ErrOut, "warning: %s/%s does not have any containers matching %q\n", info.Mapping.Resource, info.Name, o.ContainerSelector)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
@ -397,7 +394,7 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
|
|||||||
}
|
}
|
||||||
sort.Strings(errs)
|
sort.Strings(errs)
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
fmt.Fprintln(o.Err, err)
|
fmt.Fprintln(o.ErrOut, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,9 @@ limitations under the License.
|
|||||||
package set
|
package set
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -43,6 +41,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
"k8s.io/kubernetes/pkg/api/testapi"
|
"k8s.io/kubernetes/pkg/api/testapi"
|
||||||
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/resource"
|
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||||
)
|
)
|
||||||
@ -65,8 +64,8 @@ func TestSetEnvLocal(t *testing.T) {
|
|||||||
|
|
||||||
outputFormat := "name"
|
outputFormat := "name"
|
||||||
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
cmd := NewCmdEnv(tf, os.Stdin, buf, buf)
|
cmd := NewCmdEnv(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Flags().Set("output", outputFormat)
|
cmd.Flags().Set("output", outputFormat)
|
||||||
cmd.Flags().Set("local", "true")
|
cmd.Flags().Set("local", "true")
|
||||||
@ -80,8 +79,8 @@ func TestSetEnvLocal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
FilenameOptions: resource.FilenameOptions{
|
FilenameOptions: resource.FilenameOptions{
|
||||||
Filenames: []string{"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"}},
|
Filenames: []string{"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"}},
|
||||||
Out: buf,
|
|
||||||
Local: true,
|
Local: true,
|
||||||
|
IOStreams: streams,
|
||||||
}
|
}
|
||||||
err := opts.Complete(tf, cmd, []string{"env=prod"})
|
err := opts.Complete(tf, cmd, []string{"env=prod"})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -114,8 +113,8 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
|
|||||||
|
|
||||||
outputFormat := "name"
|
outputFormat := "name"
|
||||||
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
cmd := NewCmdEnv(tf, os.Stdin, buf, buf)
|
cmd := NewCmdEnv(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Flags().Set("output", outputFormat)
|
cmd.Flags().Set("output", outputFormat)
|
||||||
cmd.Flags().Set("local", "true")
|
cmd.Flags().Set("local", "true")
|
||||||
@ -129,8 +128,8 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
FilenameOptions: resource.FilenameOptions{
|
FilenameOptions: resource.FilenameOptions{
|
||||||
Filenames: []string{"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"}},
|
Filenames: []string{"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"}},
|
||||||
Out: buf,
|
|
||||||
Local: true,
|
Local: true,
|
||||||
|
IOStreams: streams,
|
||||||
}
|
}
|
||||||
err := opts.Complete(tf, cmd, []string{"env=prod"})
|
err := opts.Complete(tf, cmd, []string{"env=prod"})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -507,9 +506,8 @@ func TestSetEnvRemote(t *testing.T) {
|
|||||||
|
|
||||||
outputFormat := "yaml"
|
outputFormat := "yaml"
|
||||||
|
|
||||||
out := new(bytes.Buffer)
|
streams := genericclioptions.NewTestIOStreamsDiscard()
|
||||||
cmd := NewCmdEnv(tf, out, out, out)
|
cmd := NewCmdEnv(tf, streams)
|
||||||
cmd.SetOutput(out)
|
|
||||||
cmd.Flags().Set("output", outputFormat)
|
cmd.Flags().Set("output", outputFormat)
|
||||||
opts := EnvOptions{
|
opts := EnvOptions{
|
||||||
PrintFlags: &printers.PrintFlags{
|
PrintFlags: &printers.PrintFlags{
|
||||||
@ -518,8 +516,9 @@ func TestSetEnvRemote(t *testing.T) {
|
|||||||
|
|
||||||
OutputFormat: &outputFormat,
|
OutputFormat: &outputFormat,
|
||||||
},
|
},
|
||||||
Out: out,
|
Local: false,
|
||||||
Local: false}
|
IOStreams: streams,
|
||||||
|
}
|
||||||
err := opts.Complete(tf, cmd, input.args)
|
err := opts.Complete(tf, cmd, input.args)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = opts.RunEnv(tf)
|
err = opts.RunEnv(tf)
|
||||||
|
@ -18,7 +18,6 @@ package set
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/printers"
|
"k8s.io/kubernetes/pkg/printers"
|
||||||
|
|
||||||
@ -45,8 +44,6 @@ type SetImageOptions struct {
|
|||||||
|
|
||||||
Infos []*resource.Info
|
Infos []*resource.Info
|
||||||
Selector string
|
Selector string
|
||||||
Out io.Writer
|
|
||||||
Err io.Writer
|
|
||||||
DryRun bool
|
DryRun bool
|
||||||
All bool
|
All bool
|
||||||
Output string
|
Output string
|
||||||
@ -59,6 +56,8 @@ type SetImageOptions struct {
|
|||||||
UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error)
|
UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error)
|
||||||
Resources []string
|
Resources []string
|
||||||
ContainerImages map[string]string
|
ContainerImages map[string]string
|
||||||
|
|
||||||
|
genericclioptions.IOStreams
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -85,20 +84,19 @@ var (
|
|||||||
kubectl set image -f path/to/file.yaml nginx=nginx:1.9.1 --local -o yaml`)
|
kubectl set image -f path/to/file.yaml nginx=nginx:1.9.1 --local -o yaml`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewImageOptions(out, errOut io.Writer) *SetImageOptions {
|
func NewImageOptions(streams genericclioptions.IOStreams) *SetImageOptions {
|
||||||
return &SetImageOptions{
|
return &SetImageOptions{
|
||||||
PrintFlags: printers.NewPrintFlags("image updated"),
|
PrintFlags: printers.NewPrintFlags("image updated"),
|
||||||
RecordFlags: genericclioptions.NewRecordFlags(),
|
RecordFlags: genericclioptions.NewRecordFlags(),
|
||||||
|
|
||||||
Recorder: genericclioptions.NoopRecorder{},
|
Recorder: genericclioptions.NoopRecorder{},
|
||||||
|
|
||||||
Out: out,
|
IOStreams: streams,
|
||||||
Err: errOut,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCmdImage(f cmdutil.Factory, out, errOut io.Writer) *cobra.Command {
|
func NewCmdImage(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
o := NewImageOptions(out, errOut)
|
o := NewImageOptions(streams)
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "image (-f FILENAME | TYPE NAME) CONTAINER_NAME_1=CONTAINER_IMAGE_1 ... CONTAINER_NAME_N=CONTAINER_IMAGE_N",
|
Use: "image (-f FILENAME | TYPE NAME) CONTAINER_NAME_1=CONTAINER_IMAGE_1 ... CONTAINER_NAME_N=CONTAINER_IMAGE_N",
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package set
|
package set
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -42,6 +41,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
"k8s.io/kubernetes/pkg/api/testapi"
|
"k8s.io/kubernetes/pkg/api/testapi"
|
||||||
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/resource"
|
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||||
)
|
)
|
||||||
@ -65,8 +65,8 @@ func TestImageLocal(t *testing.T) {
|
|||||||
|
|
||||||
outputFormat := "name"
|
outputFormat := "name"
|
||||||
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
cmd := NewCmdImage(tf, buf, buf)
|
cmd := NewCmdImage(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Flags().Set("output", outputFormat)
|
cmd.Flags().Set("output", outputFormat)
|
||||||
cmd.Flags().Set("local", "true")
|
cmd.Flags().Set("local", "true")
|
||||||
@ -80,8 +80,9 @@ func TestImageLocal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
FilenameOptions: resource.FilenameOptions{
|
FilenameOptions: resource.FilenameOptions{
|
||||||
Filenames: []string{"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"}},
|
Filenames: []string{"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"}},
|
||||||
Out: buf,
|
Local: true,
|
||||||
Local: true}
|
IOStreams: streams,
|
||||||
|
}
|
||||||
err := opts.Complete(tf, cmd, []string{"cassandra=thingy"})
|
err := opts.Complete(tf, cmd, []string{"cassandra=thingy"})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = opts.Validate()
|
err = opts.Validate()
|
||||||
@ -187,8 +188,8 @@ func TestSetMultiResourcesImageLocal(t *testing.T) {
|
|||||||
|
|
||||||
outputFormat := "name"
|
outputFormat := "name"
|
||||||
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
cmd := NewCmdImage(tf, buf, buf)
|
cmd := NewCmdImage(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Flags().Set("output", outputFormat)
|
cmd.Flags().Set("output", outputFormat)
|
||||||
cmd.Flags().Set("local", "true")
|
cmd.Flags().Set("local", "true")
|
||||||
@ -202,8 +203,9 @@ func TestSetMultiResourcesImageLocal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
FilenameOptions: resource.FilenameOptions{
|
FilenameOptions: resource.FilenameOptions{
|
||||||
Filenames: []string{"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"}},
|
Filenames: []string{"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"}},
|
||||||
Out: buf,
|
Local: true,
|
||||||
Local: true}
|
IOStreams: streams,
|
||||||
|
}
|
||||||
err := opts.Complete(tf, cmd, []string{"*=thingy"})
|
err := opts.Complete(tf, cmd, []string{"*=thingy"})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = opts.Validate()
|
err = opts.Validate()
|
||||||
@ -583,9 +585,8 @@ func TestSetImageRemote(t *testing.T) {
|
|||||||
|
|
||||||
outputFormat := "yaml"
|
outputFormat := "yaml"
|
||||||
|
|
||||||
out := new(bytes.Buffer)
|
streams := genericclioptions.NewTestIOStreamsDiscard()
|
||||||
cmd := NewCmdImage(tf, out, out)
|
cmd := NewCmdImage(tf, streams)
|
||||||
cmd.SetOutput(out)
|
|
||||||
cmd.Flags().Set("output", outputFormat)
|
cmd.Flags().Set("output", outputFormat)
|
||||||
opts := SetImageOptions{
|
opts := SetImageOptions{
|
||||||
PrintFlags: &printers.PrintFlags{
|
PrintFlags: &printers.PrintFlags{
|
||||||
@ -595,8 +596,9 @@ func TestSetImageRemote(t *testing.T) {
|
|||||||
OutputFormat: &outputFormat,
|
OutputFormat: &outputFormat,
|
||||||
},
|
},
|
||||||
|
|
||||||
Out: out,
|
Local: false,
|
||||||
Local: false}
|
IOStreams: streams,
|
||||||
|
}
|
||||||
err := opts.Complete(tf, cmd, input.args)
|
err := opts.Complete(tf, cmd, input.args)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = opts.Run()
|
err = opts.Run()
|
||||||
|
@ -18,7 +18,6 @@ package set
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/printers"
|
"k8s.io/kubernetes/pkg/printers"
|
||||||
@ -69,8 +68,6 @@ type SetResourcesOptions struct {
|
|||||||
RecordFlags *genericclioptions.RecordFlags
|
RecordFlags *genericclioptions.RecordFlags
|
||||||
|
|
||||||
Infos []*resource.Info
|
Infos []*resource.Info
|
||||||
Out io.Writer
|
|
||||||
Err io.Writer
|
|
||||||
Selector string
|
Selector string
|
||||||
ContainerSelector string
|
ContainerSelector string
|
||||||
Output string
|
Output string
|
||||||
@ -88,25 +85,27 @@ type SetResourcesOptions struct {
|
|||||||
|
|
||||||
UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error)
|
UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error)
|
||||||
Resources []string
|
Resources []string
|
||||||
|
|
||||||
|
genericclioptions.IOStreams
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewResourcesOptions returns a ResourcesOptions indicating all containers in the selected
|
// NewResourcesOptions returns a ResourcesOptions indicating all containers in the selected
|
||||||
// pod templates are selected by default.
|
// pod templates are selected by default.
|
||||||
func NewResourcesOptions(out io.Writer, errOut io.Writer) *SetResourcesOptions {
|
func NewResourcesOptions(streams genericclioptions.IOStreams) *SetResourcesOptions {
|
||||||
return &SetResourcesOptions{
|
return &SetResourcesOptions{
|
||||||
PrintFlags: printers.NewPrintFlags("resource requirements updated"),
|
PrintFlags: printers.NewPrintFlags("resource requirements updated"),
|
||||||
RecordFlags: genericclioptions.NewRecordFlags(),
|
RecordFlags: genericclioptions.NewRecordFlags(),
|
||||||
|
|
||||||
Recorder: genericclioptions.NoopRecorder{},
|
Recorder: genericclioptions.NoopRecorder{},
|
||||||
|
|
||||||
Out: out,
|
|
||||||
Err: errOut,
|
|
||||||
ContainerSelector: "*",
|
ContainerSelector: "*",
|
||||||
|
|
||||||
|
IOStreams: streams,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCmdResources(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
|
func NewCmdResources(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
o := NewResourcesOptions(out, errOut)
|
o := NewResourcesOptions(streams)
|
||||||
|
|
||||||
resourceTypesWithPodTemplate := []string{}
|
resourceTypesWithPodTemplate := []string{}
|
||||||
for _, resource := range f.SuggestedPodTemplateResources() {
|
for _, resource := range f.SuggestedPodTemplateResources() {
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package set
|
package set
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -42,6 +41,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
"k8s.io/kubernetes/pkg/api/testapi"
|
"k8s.io/kubernetes/pkg/api/testapi"
|
||||||
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/resource"
|
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||||
)
|
)
|
||||||
@ -64,8 +64,8 @@ func TestResourcesLocal(t *testing.T) {
|
|||||||
|
|
||||||
outputFormat := "name"
|
outputFormat := "name"
|
||||||
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
cmd := NewCmdResources(tf, buf, buf)
|
cmd := NewCmdResources(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Flags().Set("output", outputFormat)
|
cmd.Flags().Set("output", outputFormat)
|
||||||
cmd.Flags().Set("local", "true")
|
cmd.Flags().Set("local", "true")
|
||||||
@ -79,11 +79,12 @@ func TestResourcesLocal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
FilenameOptions: resource.FilenameOptions{
|
FilenameOptions: resource.FilenameOptions{
|
||||||
Filenames: []string{"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"}},
|
Filenames: []string{"../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml"}},
|
||||||
Out: buf,
|
|
||||||
Local: true,
|
Local: true,
|
||||||
Limits: "cpu=200m,memory=512Mi",
|
Limits: "cpu=200m,memory=512Mi",
|
||||||
Requests: "cpu=200m,memory=512Mi",
|
Requests: "cpu=200m,memory=512Mi",
|
||||||
ContainerSelector: "*"}
|
ContainerSelector: "*",
|
||||||
|
IOStreams: streams,
|
||||||
|
}
|
||||||
|
|
||||||
err := opts.Complete(tf, cmd, []string{})
|
err := opts.Complete(tf, cmd, []string{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -118,8 +119,8 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) {
|
|||||||
|
|
||||||
outputFormat := "name"
|
outputFormat := "name"
|
||||||
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
cmd := NewCmdResources(tf, buf, buf)
|
cmd := NewCmdResources(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
cmd.Flags().Set("output", outputFormat)
|
cmd.Flags().Set("output", outputFormat)
|
||||||
cmd.Flags().Set("local", "true")
|
cmd.Flags().Set("local", "true")
|
||||||
@ -133,11 +134,12 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
FilenameOptions: resource.FilenameOptions{
|
FilenameOptions: resource.FilenameOptions{
|
||||||
Filenames: []string{"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"}},
|
Filenames: []string{"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"}},
|
||||||
Out: buf,
|
|
||||||
Local: true,
|
Local: true,
|
||||||
Limits: "cpu=200m,memory=512Mi",
|
Limits: "cpu=200m,memory=512Mi",
|
||||||
Requests: "cpu=200m,memory=512Mi",
|
Requests: "cpu=200m,memory=512Mi",
|
||||||
ContainerSelector: "*"}
|
ContainerSelector: "*",
|
||||||
|
IOStreams: streams,
|
||||||
|
}
|
||||||
|
|
||||||
err := opts.Complete(tf, cmd, []string{})
|
err := opts.Complete(tf, cmd, []string{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -501,9 +503,8 @@ func TestSetResourcesRemote(t *testing.T) {
|
|||||||
|
|
||||||
outputFormat := "yaml"
|
outputFormat := "yaml"
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
streams := genericclioptions.NewTestIOStreamsDiscard()
|
||||||
cmd := NewCmdResources(tf, buf, buf)
|
cmd := NewCmdResources(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
|
||||||
cmd.Flags().Set("output", outputFormat)
|
cmd.Flags().Set("output", outputFormat)
|
||||||
opts := SetResourcesOptions{
|
opts := SetResourcesOptions{
|
||||||
PrintFlags: &printers.PrintFlags{
|
PrintFlags: &printers.PrintFlags{
|
||||||
@ -513,9 +514,10 @@ func TestSetResourcesRemote(t *testing.T) {
|
|||||||
OutputFormat: &outputFormat,
|
OutputFormat: &outputFormat,
|
||||||
},
|
},
|
||||||
|
|
||||||
Out: buf,
|
|
||||||
Limits: "cpu=200m,memory=512Mi",
|
Limits: "cpu=200m,memory=512Mi",
|
||||||
ContainerSelector: "*"}
|
ContainerSelector: "*",
|
||||||
|
IOStreams: streams,
|
||||||
|
}
|
||||||
err := opts.Complete(tf, cmd, input.args)
|
err := opts.Complete(tf, cmd, input.args)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = opts.Validate()
|
err = opts.Validate()
|
||||||
|
@ -18,7 +18,6 @@ package set
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/printers"
|
"k8s.io/kubernetes/pkg/printers"
|
||||||
|
|
||||||
@ -53,7 +52,6 @@ type SetSelectorOptions struct {
|
|||||||
resources []string
|
resources []string
|
||||||
selector *metav1.LabelSelector
|
selector *metav1.LabelSelector
|
||||||
|
|
||||||
out io.Writer
|
|
||||||
ClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error)
|
ClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error)
|
||||||
|
|
||||||
PrintObj printers.ResourcePrinterFunc
|
PrintObj printers.ResourcePrinterFunc
|
||||||
@ -61,6 +59,8 @@ type SetSelectorOptions struct {
|
|||||||
|
|
||||||
builder *resource.Builder
|
builder *resource.Builder
|
||||||
mapper meta.RESTMapper
|
mapper meta.RESTMapper
|
||||||
|
|
||||||
|
genericclioptions.IOStreams
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -77,20 +77,20 @@ var (
|
|||||||
kubectl create deployment my-dep -o yaml --dry-run | kubectl label --local -f - environment=qa -o yaml | kubectl create -f -`)
|
kubectl create deployment my-dep -o yaml --dry-run | kubectl label --local -f - environment=qa -o yaml | kubectl create -f -`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewSelectorOptions(out io.Writer) *SetSelectorOptions {
|
func NewSelectorOptions(streams genericclioptions.IOStreams) *SetSelectorOptions {
|
||||||
return &SetSelectorOptions{
|
return &SetSelectorOptions{
|
||||||
PrintFlags: printers.NewPrintFlags("selector updated"),
|
PrintFlags: printers.NewPrintFlags("selector updated"),
|
||||||
RecordFlags: genericclioptions.NewRecordFlags(),
|
RecordFlags: genericclioptions.NewRecordFlags(),
|
||||||
|
|
||||||
Recorder: genericclioptions.NoopRecorder{},
|
Recorder: genericclioptions.NoopRecorder{},
|
||||||
|
|
||||||
out: out,
|
IOStreams: streams,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdSelector is the "set selector" command.
|
// NewCmdSelector is the "set selector" command.
|
||||||
func NewCmdSelector(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
func NewCmdSelector(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
o := NewSelectorOptions(out)
|
o := NewSelectorOptions(streams)
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "selector (-f FILENAME | TYPE NAME) EXPRESSIONS [--resource-version=version]",
|
Use: "selector (-f FILENAME | TYPE NAME) EXPRESSIONS [--resource-version=version]",
|
||||||
@ -226,7 +226,7 @@ func (o *SetSelectorOptions) RunSelector() error {
|
|||||||
return patch.Err
|
return patch.Err
|
||||||
}
|
}
|
||||||
if o.local || o.dryrun {
|
if o.local || o.dryrun {
|
||||||
return o.PrintObj(info.Object, o.out)
|
return o.PrintObj(info.Object, o.Out)
|
||||||
}
|
}
|
||||||
|
|
||||||
patched, err := resource.NewHelper(info.Client, info.Mapping).Patch(info.Namespace, info.Name, types.StrategicMergePatchType, patch.Patch)
|
patched, err := resource.NewHelper(info.Client, info.Mapping).Patch(info.Namespace, info.Name, types.StrategicMergePatchType, patch.Patch)
|
||||||
@ -235,7 +235,7 @@ func (o *SetSelectorOptions) RunSelector() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info.Refresh(patched, true)
|
info.Refresh(patched, true)
|
||||||
return o.PrintObj(patch.Info.AsVersioned(), o.out)
|
return o.PrintObj(patch.Info.AsVersioned(), o.Out)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package set
|
package set
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@ -34,6 +33,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"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUpdateSelectorForObjectTypes(t *testing.T) {
|
func TestUpdateSelectorForObjectTypes(t *testing.T) {
|
||||||
@ -331,9 +331,8 @@ func TestSelectorTest(t *testing.T) {
|
|||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}}
|
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}}
|
||||||
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
cmd := NewCmdSelector(tf, buf)
|
cmd := NewCmdSelector(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
|
||||||
cmd.Flags().Set("output", "name")
|
cmd.Flags().Set("output", "name")
|
||||||
cmd.Flags().Set("local", "true")
|
cmd.Flags().Set("local", "true")
|
||||||
cmd.Flags().Set("filename", "../../../../test/e2e/testing-manifests/statefulset/cassandra/service.yaml")
|
cmd.Flags().Set("filename", "../../../../test/e2e/testing-manifests/statefulset/cassandra/service.yaml")
|
||||||
|
@ -19,7 +19,6 @@ package set
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/printers"
|
"k8s.io/kubernetes/pkg/printers"
|
||||||
|
|
||||||
@ -62,8 +61,6 @@ type SetServiceAccountOptions struct {
|
|||||||
RecordFlags *genericclioptions.RecordFlags
|
RecordFlags *genericclioptions.RecordFlags
|
||||||
|
|
||||||
fileNameOptions resource.FilenameOptions
|
fileNameOptions resource.FilenameOptions
|
||||||
out io.Writer
|
|
||||||
err io.Writer
|
|
||||||
dryRun bool
|
dryRun bool
|
||||||
shortOutput bool
|
shortOutput bool
|
||||||
all bool
|
all bool
|
||||||
@ -75,23 +72,24 @@ type SetServiceAccountOptions struct {
|
|||||||
|
|
||||||
PrintObj printers.ResourcePrinterFunc
|
PrintObj printers.ResourcePrinterFunc
|
||||||
Recorder genericclioptions.Recorder
|
Recorder genericclioptions.Recorder
|
||||||
|
|
||||||
|
genericclioptions.IOStreams
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSetServiceAccountOptions(out, errOut io.Writer) *SetServiceAccountOptions {
|
func NewSetServiceAccountOptions(streams genericclioptions.IOStreams) *SetServiceAccountOptions {
|
||||||
return &SetServiceAccountOptions{
|
return &SetServiceAccountOptions{
|
||||||
PrintFlags: printers.NewPrintFlags("serviceaccount updated"),
|
PrintFlags: printers.NewPrintFlags("serviceaccount updated"),
|
||||||
RecordFlags: genericclioptions.NewRecordFlags(),
|
RecordFlags: genericclioptions.NewRecordFlags(),
|
||||||
|
|
||||||
Recorder: genericclioptions.NoopRecorder{},
|
Recorder: genericclioptions.NoopRecorder{},
|
||||||
|
|
||||||
out: out,
|
IOStreams: streams,
|
||||||
err: errOut,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdServiceAccount returns the "set serviceaccount" command.
|
// NewCmdServiceAccount returns the "set serviceaccount" command.
|
||||||
func NewCmdServiceAccount(f cmdutil.Factory, out, errOut io.Writer) *cobra.Command {
|
func NewCmdServiceAccount(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
o := NewSetServiceAccountOptions(out, errOut)
|
o := NewSetServiceAccountOptions(streams)
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "serviceaccount (-f FILENAME | TYPE NAME) SERVICE_ACCOUNT",
|
Use: "serviceaccount (-f FILENAME | TYPE NAME) SERVICE_ACCOUNT",
|
||||||
@ -199,7 +197,7 @@ func (o *SetServiceAccountOptions) Run() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if o.local || o.dryRun {
|
if o.local || o.dryRun {
|
||||||
if err := o.PrintObj(patch.Info.AsVersioned(), o.out); err != nil {
|
if err := o.PrintObj(patch.Info.AsVersioned(), o.Out); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
@ -211,7 +209,7 @@ func (o *SetServiceAccountOptions) Run() error {
|
|||||||
}
|
}
|
||||||
info.Refresh(patched, true)
|
info.Refresh(patched, true)
|
||||||
|
|
||||||
if err := o.PrintObj(info.AsVersioned(), o.out); err != nil {
|
if err := o.PrintObj(info.AsVersioned(), o.Out); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
"k8s.io/kubernetes/pkg/api/testapi"
|
"k8s.io/kubernetes/pkg/api/testapi"
|
||||||
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/resource"
|
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||||
)
|
)
|
||||||
@ -83,9 +84,8 @@ func TestSetServiceAccountLocal(t *testing.T) {
|
|||||||
outputFormat := "yaml"
|
outputFormat := "yaml"
|
||||||
|
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
out := new(bytes.Buffer)
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
cmd := NewCmdServiceAccount(tf, out, out)
|
cmd := NewCmdServiceAccount(tf, streams)
|
||||||
cmd.SetOutput(out)
|
|
||||||
cmd.Flags().Set("output", outputFormat)
|
cmd.Flags().Set("output", outputFormat)
|
||||||
cmd.Flags().Set("local", "true")
|
cmd.Flags().Set("local", "true")
|
||||||
testapi.Default = testapi.Groups[input.apiGroup]
|
testapi.Default = testapi.Groups[input.apiGroup]
|
||||||
@ -98,13 +98,14 @@ func TestSetServiceAccountLocal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
fileNameOptions: resource.FilenameOptions{
|
fileNameOptions: resource.FilenameOptions{
|
||||||
Filenames: []string{input.yaml}},
|
Filenames: []string{input.yaml}},
|
||||||
out: out,
|
local: true,
|
||||||
local: true}
|
IOStreams: streams,
|
||||||
|
}
|
||||||
err := saConfig.Complete(tf, cmd, []string{serviceAccount})
|
err := saConfig.Complete(tf, cmd, []string{serviceAccount})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = saConfig.Run()
|
err = saConfig.Run()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Contains(t, out.String(), "serviceAccountName: "+serviceAccount, fmt.Sprintf("serviceaccount not updated for %s", input.yaml))
|
assert.Contains(t, buf.String(), "serviceAccountName: "+serviceAccount, fmt.Sprintf("serviceaccount not updated for %s", input.yaml))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,9 +129,8 @@ func TestSetServiceAccountMultiLocal(t *testing.T) {
|
|||||||
|
|
||||||
outputFormat := "name"
|
outputFormat := "name"
|
||||||
|
|
||||||
buf := bytes.NewBuffer([]byte{})
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
cmd := NewCmdServiceAccount(tf, buf, buf)
|
cmd := NewCmdServiceAccount(tf, streams)
|
||||||
cmd.SetOutput(buf)
|
|
||||||
cmd.Flags().Set("output", outputFormat)
|
cmd.Flags().Set("output", outputFormat)
|
||||||
cmd.Flags().Set("local", "true")
|
cmd.Flags().Set("local", "true")
|
||||||
opts := SetServiceAccountOptions{
|
opts := SetServiceAccountOptions{
|
||||||
@ -142,8 +142,9 @@ func TestSetServiceAccountMultiLocal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
fileNameOptions: resource.FilenameOptions{
|
fileNameOptions: resource.FilenameOptions{
|
||||||
Filenames: []string{"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"}},
|
Filenames: []string{"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"}},
|
||||||
out: buf,
|
local: true,
|
||||||
local: true}
|
IOStreams: streams,
|
||||||
|
}
|
||||||
|
|
||||||
err := opts.Complete(tf, cmd, []string{serviceAccount})
|
err := opts.Complete(tf, cmd, []string{serviceAccount})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -373,9 +374,8 @@ func TestSetServiceAccountRemote(t *testing.T) {
|
|||||||
|
|
||||||
outputFormat := "yaml"
|
outputFormat := "yaml"
|
||||||
|
|
||||||
out := new(bytes.Buffer)
|
streams := genericclioptions.NewTestIOStreamsDiscard()
|
||||||
cmd := NewCmdServiceAccount(tf, out, out)
|
cmd := NewCmdServiceAccount(tf, streams)
|
||||||
cmd.SetOutput(out)
|
|
||||||
cmd.Flags().Set("output", outputFormat)
|
cmd.Flags().Set("output", outputFormat)
|
||||||
saConfig := SetServiceAccountOptions{
|
saConfig := SetServiceAccountOptions{
|
||||||
PrintFlags: &printers.PrintFlags{
|
PrintFlags: &printers.PrintFlags{
|
||||||
@ -385,8 +385,9 @@ func TestSetServiceAccountRemote(t *testing.T) {
|
|||||||
OutputFormat: &outputFormat,
|
OutputFormat: &outputFormat,
|
||||||
},
|
},
|
||||||
|
|
||||||
out: out,
|
local: false,
|
||||||
local: false}
|
IOStreams: streams,
|
||||||
|
}
|
||||||
err := saConfig.Complete(tf, cmd, input.args)
|
err := saConfig.Complete(tf, cmd, input.args)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = saConfig.Run()
|
err = saConfig.Run()
|
||||||
@ -420,9 +421,8 @@ func TestServiceAccountValidation(t *testing.T) {
|
|||||||
outputFormat := ""
|
outputFormat := ""
|
||||||
|
|
||||||
tf.Namespace = "test"
|
tf.Namespace = "test"
|
||||||
out := bytes.NewBuffer([]byte{})
|
streams := genericclioptions.NewTestIOStreamsDiscard()
|
||||||
cmd := NewCmdServiceAccount(tf, out, out)
|
cmd := NewCmdServiceAccount(tf, streams)
|
||||||
cmd.SetOutput(out)
|
|
||||||
|
|
||||||
saConfig := &SetServiceAccountOptions{
|
saConfig := &SetServiceAccountOptions{
|
||||||
PrintFlags: &printers.PrintFlags{
|
PrintFlags: &printers.PrintFlags{
|
||||||
@ -431,6 +431,7 @@ func TestServiceAccountValidation(t *testing.T) {
|
|||||||
|
|
||||||
OutputFormat: &outputFormat,
|
OutputFormat: &outputFormat,
|
||||||
},
|
},
|
||||||
|
IOStreams: streams,
|
||||||
}
|
}
|
||||||
err := saConfig.Complete(tf, cmd, input.args)
|
err := saConfig.Complete(tf, cmd, input.args)
|
||||||
assert.EqualError(t, err, input.errorString)
|
assert.EqualError(t, err, input.errorString)
|
||||||
|
@ -18,7 +18,6 @@ package set
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/printers"
|
"k8s.io/kubernetes/pkg/printers"
|
||||||
@ -32,6 +31,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/apis/rbac"
|
"k8s.io/kubernetes/pkg/apis/rbac"
|
||||||
"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/genericclioptions"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
||||||
)
|
)
|
||||||
@ -61,8 +61,6 @@ type SubjectOptions struct {
|
|||||||
resource.FilenameOptions
|
resource.FilenameOptions
|
||||||
|
|
||||||
Infos []*resource.Info
|
Infos []*resource.Info
|
||||||
Out io.Writer
|
|
||||||
Err io.Writer
|
|
||||||
Selector string
|
Selector string
|
||||||
ContainerSelector string
|
ContainerSelector string
|
||||||
Output string
|
Output string
|
||||||
@ -75,15 +73,20 @@ type SubjectOptions struct {
|
|||||||
ServiceAccounts []string
|
ServiceAccounts []string
|
||||||
|
|
||||||
PrintObj printers.ResourcePrinterFunc
|
PrintObj printers.ResourcePrinterFunc
|
||||||
|
|
||||||
|
genericclioptions.IOStreams
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCmdSubject(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
|
func NewSubjectOptions(streams genericclioptions.IOStreams) *SubjectOptions {
|
||||||
options := &SubjectOptions{
|
return &SubjectOptions{
|
||||||
PrintFlags: printers.NewPrintFlags("subjects updated"),
|
PrintFlags: printers.NewPrintFlags("subjects updated"),
|
||||||
|
|
||||||
Out: out,
|
IOStreams: streams,
|
||||||
Err: errOut,
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCmdSubject(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
|
options := NewSubjectOptions(streams)
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--serviceaccount=namespace:serviceaccountname] [--dry-run]",
|
Use: "subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--serviceaccount=namespace:serviceaccountname] [--dry-run]",
|
||||||
|
@ -17,20 +17,17 @@ limitations under the License.
|
|||||||
package set
|
package set
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
clientcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
clientcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||||
"os"
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLocalAndDryRunFlags(t *testing.T) {
|
func TestLocalAndDryRunFlags(t *testing.T) {
|
||||||
out := &bytes.Buffer{}
|
|
||||||
errout := &bytes.Buffer{}
|
|
||||||
f := clientcmdutil.NewFactory(nil)
|
f := clientcmdutil.NewFactory(nil)
|
||||||
setCmd := NewCmdSet(f, os.Stdin, out, errout)
|
setCmd := NewCmdSet(f, genericclioptions.NewTestIOStreamsDiscard())
|
||||||
ensureLocalAndDryRunFlagsOnChildren(t, setCmd, "")
|
ensureLocalAndDryRunFlagsOnChildren(t, setCmd, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user