Migrate genericclioptions.IOStreams usage to genericiooptions

Kubernetes-commit: 00c30941260a27e6929aef84c7fdbc8f1508518c
This commit is contained in:
Arda Güçlü 2023-04-05 14:07:46 +03:00 committed by Kubernetes Publisher
parent 8da1ed5082
commit 3f05cfcd78
150 changed files with 736 additions and 641 deletions

View File

@ -19,14 +19,15 @@ package cmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n" "k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates" "k8s.io/kubectl/pkg/util/templates"
) )
// NewCmdAlpha creates a command that acts as an alternate root command for features in alpha // NewCmdAlpha creates a command that acts as an alternate root command for features in alpha
func NewCmdAlpha(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdAlpha(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "alpha", Use: "alpha",
Short: i18n.T("Commands for features in alpha"), Short: i18n.T("Commands for features in alpha"),

View File

@ -33,6 +33,7 @@ import (
"k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/json"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -63,11 +64,11 @@ type AnnotateFlags struct {
resourceVersion string resourceVersion string
Selector string Selector string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewAnnotateFlags returns a default AnnotateFlags // NewAnnotateFlags returns a default AnnotateFlags
func NewAnnotateFlags(streams genericclioptions.IOStreams) *AnnotateFlags { func NewAnnotateFlags(streams genericiooptions.IOStreams) *AnnotateFlags {
return &AnnotateFlags{ return &AnnotateFlags{
PrintFlags: genericclioptions.NewPrintFlags("annotate").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("annotate").WithTypeSetter(scheme.Scheme),
RecordFlags: genericclioptions.NewRecordFlags(), RecordFlags: genericclioptions.NewRecordFlags(),
@ -88,7 +89,7 @@ type AnnotateOptions struct {
fieldManager string fieldManager string
resource.FilenameOptions resource.FilenameOptions
genericclioptions.IOStreams genericiooptions.IOStreams
list bool list bool
local bool local bool
@ -143,7 +144,7 @@ var (
) )
// NewCmdAnnotate creates the `annotate` command // NewCmdAnnotate creates the `annotate` command
func NewCmdAnnotate(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdAnnotate(parent string, f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
flags := NewAnnotateFlags(streams) flags := NewAnnotateFlags(streams)
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -166,7 +167,7 @@ func NewCmdAnnotate(parent string, f cmdutil.Factory, streams genericclioptions.
} }
// AddFlags registers flags for a cli. // AddFlags registers flags for a cli.
func (flags *AnnotateFlags) AddFlags(cmd *cobra.Command, ioStreams genericclioptions.IOStreams) { func (flags *AnnotateFlags) AddFlags(cmd *cobra.Command, ioStreams genericiooptions.IOStreams) {
flags.PrintFlags.AddFlags(cmd) flags.PrintFlags.AddFlags(cmd)
flags.RecordFlags.AddFlags(cmd) flags.RecordFlags.AddFlags(cmd)

View File

@ -28,7 +28,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
@ -440,7 +440,7 @@ func TestAnnotateErrors(t *testing.T) {
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
iostreams, _, bufOut, bufErr := genericclioptions.NewTestIOStreams() iostreams, _, bufOut, bufErr := genericiooptions.NewTestIOStreams()
cmd := NewCmdAnnotate("kubectl", tf, iostreams) cmd := NewCmdAnnotate("kubectl", tf, iostreams)
cmd.SetOut(bufOut) cmd.SetOut(bufOut)
cmd.SetErr(bufOut) cmd.SetErr(bufOut)
@ -498,7 +498,7 @@ func TestAnnotateObject(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
iostreams, _, bufOut, _ := genericclioptions.NewTestIOStreams() iostreams, _, bufOut, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdAnnotate("kubectl", tf, iostreams) cmd := NewCmdAnnotate("kubectl", tf, iostreams)
cmd.SetOut(bufOut) cmd.SetOut(bufOut)
cmd.SetErr(bufOut) cmd.SetErr(bufOut)
@ -564,7 +564,7 @@ func TestAnnotateResourceVersion(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
iostreams, _, bufOut, _ := genericclioptions.NewTestIOStreams() iostreams, _, bufOut, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdAnnotate("kubectl", tf, iostreams) cmd := NewCmdAnnotate("kubectl", tf, iostreams)
cmd.SetOut(bufOut) cmd.SetOut(bufOut)
cmd.SetErr(bufOut) cmd.SetErr(bufOut)
@ -619,7 +619,7 @@ func TestAnnotateObjectFromFile(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
iostreams, _, bufOut, _ := genericclioptions.NewTestIOStreams() iostreams, _, bufOut, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdAnnotate("kubectl", tf, iostreams) cmd := NewCmdAnnotate("kubectl", tf, iostreams)
cmd.SetOut(bufOut) cmd.SetOut(bufOut)
cmd.SetErr(bufOut) cmd.SetErr(bufOut)
@ -651,7 +651,7 @@ func TestAnnotateLocal(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
iostreams, _, _, _ := genericclioptions.NewTestIOStreams() iostreams, _, _, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdAnnotate("kubectl", tf, iostreams) cmd := NewCmdAnnotate("kubectl", tf, iostreams)
flags := NewAnnotateFlags(iostreams) flags := NewAnnotateFlags(iostreams)
flags.Local = true flags.Local = true
@ -707,7 +707,7 @@ func TestAnnotateMultipleObjects(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
iostreams, _, _, _ := genericclioptions.NewTestIOStreams() iostreams, _, _, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdAnnotate("kubectl", tf, iostreams) cmd := NewCmdAnnotate("kubectl", tf, iostreams)
cmd.SetOut(iostreams.Out) cmd.SetOut(iostreams.Out)
cmd.SetErr(iostreams.Out) cmd.SetErr(iostreams.Out)

View File

@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/client-go/discovery" "k8s.io/client-go/discovery"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -74,7 +75,7 @@ type APIResourceOptions struct {
discoveryClient discovery.CachedDiscoveryInterface discoveryClient discovery.CachedDiscoveryInterface
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// groupResource contains the APIGroup and APIResource // groupResource contains the APIGroup and APIResource
@ -85,7 +86,7 @@ type groupResource struct {
} }
// NewAPIResourceOptions creates the options for APIResource // NewAPIResourceOptions creates the options for APIResource
func NewAPIResourceOptions(ioStreams genericclioptions.IOStreams) *APIResourceOptions { func NewAPIResourceOptions(ioStreams genericiooptions.IOStreams) *APIResourceOptions {
return &APIResourceOptions{ return &APIResourceOptions{
IOStreams: ioStreams, IOStreams: ioStreams,
Namespaced: true, Namespaced: true,
@ -93,7 +94,7 @@ func NewAPIResourceOptions(ioStreams genericclioptions.IOStreams) *APIResourceOp
} }
// NewCmdAPIResources creates the `api-resources` command // NewCmdAPIResources creates the `api-resources` command
func NewCmdAPIResources(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdAPIResources(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewAPIResourceOptions(ioStreams) o := NewAPIResourceOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -22,17 +22,17 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
) )
func TestAPIResourcesComplete(t *testing.T) { func TestAPIResourcesComplete(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup() defer tf.Cleanup()
cmd := NewCmdAPIResources(tf, genericclioptions.NewTestIOStreamsDiscard()) cmd := NewCmdAPIResources(tf, genericiooptions.NewTestIOStreamsDiscard())
parentCmd := &cobra.Command{Use: "kubectl"} parentCmd := &cobra.Command{Use: "kubectl"}
parentCmd.AddCommand(cmd) parentCmd.AddCommand(cmd)
o := NewAPIResourceOptions(genericclioptions.NewTestIOStreamsDiscard()) o := NewAPIResourceOptions(genericiooptions.NewTestIOStreamsDiscard())
err := o.Complete(tf, cmd, []string{}) err := o.Complete(tf, cmd, []string{})
if err != nil { if err != nil {
@ -79,7 +79,7 @@ func TestAPIResourcesValidate(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(tt *testing.T) { t.Run(tc.name, func(tt *testing.T) {
o := NewAPIResourceOptions(genericclioptions.NewTestIOStreamsDiscard()) o := NewAPIResourceOptions(genericiooptions.NewTestIOStreamsDiscard())
tc.optionSetupFn(o) tc.optionSetupFn(o)
err := o.Validate() err := o.Validate()
if tc.expectedError == "" { if tc.expectedError == "" {
@ -305,7 +305,7 @@ bazzes b somegroup/v1 true Baz
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(tt *testing.T) { t.Run(tc.name, func(tt *testing.T) {
dc.Invalidations = 0 dc.Invalidations = 0
ioStreams, _, out, errOut := genericclioptions.NewTestIOStreams() ioStreams, _, out, errOut := genericiooptions.NewTestIOStreams()
cmd := NewCmdAPIResources(tf, ioStreams) cmd := NewCmdAPIResources(tf, ioStreams)
tc.commandSetupFn(cmd) tc.commandSetupFn(cmd)
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})

View File

@ -24,6 +24,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/discovery" "k8s.io/client-go/discovery"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n" "k8s.io/kubectl/pkg/util/i18n"
@ -40,18 +41,18 @@ var (
type APIVersionsOptions struct { type APIVersionsOptions struct {
discoveryClient discovery.CachedDiscoveryInterface discoveryClient discovery.CachedDiscoveryInterface
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewAPIVersionsOptions creates the options for APIVersions // NewAPIVersionsOptions creates the options for APIVersions
func NewAPIVersionsOptions(ioStreams genericclioptions.IOStreams) *APIVersionsOptions { func NewAPIVersionsOptions(ioStreams genericiooptions.IOStreams) *APIVersionsOptions {
return &APIVersionsOptions{ return &APIVersionsOptions{
IOStreams: ioStreams, IOStreams: ioStreams,
} }
} }
// NewCmdAPIVersions creates the `api-versions` command // NewCmdAPIVersions creates the `api-versions` command
func NewCmdAPIVersions(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdAPIVersions(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewAPIVersionsOptions(ioStreams) o := NewAPIVersionsOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "api-versions", Use: "api-versions",

View File

@ -17,21 +17,22 @@ limitations under the License.
package apiresources package apiresources
import ( import (
"github.com/spf13/cobra"
"testing" "testing"
"github.com/spf13/cobra"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
) )
func TestAPIVersionsComplete(t *testing.T) { func TestAPIVersionsComplete(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup() defer tf.Cleanup()
cmd := NewCmdAPIVersions(tf, genericclioptions.NewTestIOStreamsDiscard()) cmd := NewCmdAPIVersions(tf, genericiooptions.NewTestIOStreamsDiscard())
parentCmd := &cobra.Command{Use: "kubectl"} parentCmd := &cobra.Command{Use: "kubectl"}
parentCmd.AddCommand(cmd) parentCmd.AddCommand(cmd)
o := NewAPIVersionsOptions(genericclioptions.NewTestIOStreamsDiscard()) o := NewAPIVersionsOptions(genericiooptions.NewTestIOStreamsDiscard())
err := o.Complete(tf, cmd, []string{}) err := o.Complete(tf, cmd, []string{})
if err != nil { if err != nil {
@ -76,7 +77,7 @@ func TestAPIVersionsRun(t *testing.T) {
tf := cmdtesting.NewTestFactory().WithDiscoveryClient(dc) tf := cmdtesting.NewTestFactory().WithDiscoveryClient(dc)
defer tf.Cleanup() defer tf.Cleanup()
ioStreams, _, out, errOut := genericclioptions.NewTestIOStreams() ioStreams, _, out, errOut := genericiooptions.NewTestIOStreams()
cmd := NewCmdAPIVersions(tf, ioStreams) cmd := NewCmdAPIVersions(tf, ioStreams)
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})

View File

@ -35,6 +35,7 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/dynamic" "k8s.io/client-go/dynamic"
@ -75,7 +76,7 @@ type ApplyFlags struct {
PruneWhitelist []string // TODO: Remove this in kubectl 1.28 or later PruneWhitelist []string // TODO: Remove this in kubectl 1.28 or later
PruneAllowlist []string PruneAllowlist []string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// ApplyOptions defines flags and other configuration parameters for the `apply` command // ApplyOptions defines flags and other configuration parameters for the `apply` command
@ -109,7 +110,7 @@ type ApplyOptions struct {
Namespace string Namespace string
EnforceNamespace bool EnforceNamespace bool
genericclioptions.IOStreams genericiooptions.IOStreams
// Objects (and some denormalized data) which are to be // Objects (and some denormalized data) which are to be
// applied. The standard way to fill in this structure // applied. The standard way to fill in this structure
@ -179,7 +180,7 @@ var (
var ApplySetToolVersion = version.Get().GitVersion var ApplySetToolVersion = version.Get().GitVersion
// NewApplyFlags returns a default ApplyFlags // NewApplyFlags returns a default ApplyFlags
func NewApplyFlags(streams genericclioptions.IOStreams) *ApplyFlags { func NewApplyFlags(streams genericiooptions.IOStreams) *ApplyFlags {
return &ApplyFlags{ return &ApplyFlags{
RecordFlags: genericclioptions.NewRecordFlags(), RecordFlags: genericclioptions.NewRecordFlags(),
DeleteFlags: delete.NewDeleteFlags("The files that contain the configurations to apply."), DeleteFlags: delete.NewDeleteFlags("The files that contain the configurations to apply."),
@ -193,7 +194,7 @@ func NewApplyFlags(streams genericclioptions.IOStreams) *ApplyFlags {
} }
// NewCmdApply creates the `apply` command // NewCmdApply creates the `apply` command
func NewCmdApply(baseName string, f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdApply(baseName string, f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
flags := NewApplyFlags(ioStreams) flags := NewApplyFlags(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -19,7 +19,7 @@ package apply
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/cmd/util/editor" "k8s.io/kubectl/pkg/cmd/util/editor"
"k8s.io/kubectl/pkg/util/completion" "k8s.io/kubectl/pkg/util/completion"
@ -58,7 +58,7 @@ var (
) )
// NewCmdApplyEditLastApplied created the cobra CLI command for the `apply edit-last-applied` command. // NewCmdApplyEditLastApplied created the cobra CLI command for the `apply edit-last-applied` command.
func NewCmdApplyEditLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdApplyEditLastApplied(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := editor.NewEditOptions(editor.ApplyEditMode, ioStreams) o := editor.NewEditOptions(editor.ApplyEditMode, ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -27,6 +27,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -56,7 +57,7 @@ type SetLastAppliedOptions struct {
builder *resource.Builder builder *resource.Builder
unstructuredClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error) unstructuredClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error)
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// PatchBuffer caches changes that are to be applied. // PatchBuffer caches changes that are to be applied.
@ -84,7 +85,7 @@ var (
) )
// NewSetLastAppliedOptions takes option arguments from a CLI stream and returns it at SetLastAppliedOptions type. // NewSetLastAppliedOptions takes option arguments from a CLI stream and returns it at SetLastAppliedOptions type.
func NewSetLastAppliedOptions(ioStreams genericclioptions.IOStreams) *SetLastAppliedOptions { func NewSetLastAppliedOptions(ioStreams genericiooptions.IOStreams) *SetLastAppliedOptions {
return &SetLastAppliedOptions{ return &SetLastAppliedOptions{
PrintFlags: genericclioptions.NewPrintFlags("configured").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("configured").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -92,7 +93,7 @@ func NewSetLastAppliedOptions(ioStreams genericclioptions.IOStreams) *SetLastApp
} }
// NewCmdApplySetLastApplied creates the cobra CLI `apply` subcommand `set-last-applied`.` // NewCmdApplySetLastApplied creates the cobra CLI `apply` subcommand `set-last-applied`.`
func NewCmdApplySetLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdApplySetLastApplied(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewSetLastAppliedOptions(ioStreams) o := NewSetLastAppliedOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "set-last-applied -f FILENAME", Use: "set-last-applied -f FILENAME",

View File

@ -44,6 +44,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
sptest "k8s.io/apimachinery/pkg/util/strategicpatch/testing" sptest "k8s.io/apimachinery/pkg/util/strategicpatch/testing"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
dynamicfakeclient "k8s.io/client-go/dynamic/fake" dynamicfakeclient "k8s.io/client-go/dynamic/fake"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
@ -90,7 +91,7 @@ func TestApplyExtraArgsFail(t *testing.T) {
defer f.Cleanup() defer f.Cleanup()
cmd := &cobra.Command{} cmd := &cobra.Command{}
flags := NewApplyFlags(genericclioptions.NewTestIOStreamsDiscard()) flags := NewApplyFlags(genericiooptions.NewTestIOStreamsDiscard())
flags.AddFlags(cmd) flags.AddFlags(cmd)
_, err := flags.ToOptions(f, cmd, "kubectl", []string{"rc"}) _, err := flags.ToOptions(f, cmd, "kubectl", []string{"rc"})
require.EqualError(t, err, "Unexpected args: [rc]\nSee ' -h' for help and examples") require.EqualError(t, err, "Unexpected args: [rc]\nSee ' -h' for help and examples")
@ -105,13 +106,13 @@ func TestAlphaEnablement(t *testing.T) {
defer f.Cleanup() defer f.Cleanup()
cmd := &cobra.Command{} cmd := &cobra.Command{}
flags := NewApplyFlags(genericclioptions.NewTestIOStreamsDiscard()) flags := NewApplyFlags(genericiooptions.NewTestIOStreamsDiscard())
flags.AddFlags(cmd) flags.AddFlags(cmd)
require.Nil(t, cmd.Flags().Lookup(flag), "flag %q should not be registered without the %q feature enabled", flag, feature) require.Nil(t, cmd.Flags().Lookup(flag), "flag %q should not be registered without the %q feature enabled", flag, feature)
cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{feature}, t, func(t *testing.T) { cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{feature}, t, func(t *testing.T) {
cmd := &cobra.Command{} cmd := &cobra.Command{}
flags := NewApplyFlags(genericclioptions.NewTestIOStreamsDiscard()) flags := NewApplyFlags(genericiooptions.NewTestIOStreamsDiscard())
flags.AddFlags(cmd) flags.AddFlags(cmd)
require.NotNil(t, cmd.Flags().Lookup(flag), "flag %q should be registered with the %q feature enabled", flag, feature) require.NotNil(t, cmd.Flags().Lookup(flag), "flag %q should be registered with the %q feature enabled", flag, feature)
}) })
@ -239,7 +240,7 @@ func TestApplyFlagValidation(t *testing.T) {
f.UnstructuredClient = f.Client f.UnstructuredClient = f.Client
cmdtesting.WithAlphaEnvs(test.enableAlphas, t, func(t *testing.T) { cmdtesting.WithAlphaEnvs(test.enableAlphas, t, func(t *testing.T) {
cmd := &cobra.Command{} cmd := &cobra.Command{}
flags := NewApplyFlags(genericclioptions.NewTestIOStreamsDiscard()) flags := NewApplyFlags(genericiooptions.NewTestIOStreamsDiscard())
flags.AddFlags(cmd) flags.AddFlags(cmd)
cmd.Flags().Set("filename", "unused") cmd.Flags().Set("filename", "unused")
for _, arg := range test.args { for _, arg := range test.args {
@ -498,7 +499,7 @@ func TestRunApplyPrintsValidObjectList(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameCM) cmd.Flags().Set("filename", filenameCM)
cmd.Flags().Set("output", "json") cmd.Flags().Set("output", "json")
@ -638,7 +639,7 @@ func TestRunApplyViewLastApplied(t *testing.T) {
} }
}) })
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdApplyViewLastApplied(tf, ioStreams) cmd := NewCmdApplyViewLastApplied(tf, ioStreams)
if test.filePath != "" { if test.filePath != "" {
cmd.Flags().Set("filename", test.filePath) cmd.Flags().Set("filename", test.filePath)
@ -684,7 +685,7 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -731,7 +732,7 @@ func TestApplyObject(t *testing.T) {
tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -779,7 +780,7 @@ func TestApplyPruneObjects(t *testing.T) {
tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("prune", "true") cmd.Flags().Set("prune", "true")
@ -1021,7 +1022,7 @@ func TestApplyPruneObjectsWithAllowlist(t *testing.T) {
} }
} }
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("prune", "true") cmd.Flags().Set("prune", "true")
@ -1193,7 +1194,7 @@ func TestApplyCSAMigration(t *testing.T) {
tf.OpenAPISchemaFunc = FakeOpenAPISchema.OpenAPISchemaFn tf.OpenAPISchemaFunc = FakeOpenAPISchema.OpenAPISchemaFn
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "yaml") cmd.Flags().Set("output", "yaml")
@ -1222,7 +1223,7 @@ func TestApplyCSAMigration(t *testing.T) {
// Apply the upgraded object. // Apply the upgraded object.
// Expect only a single PATCH call to apiserver // Expect only a single PATCH call to apiserver
ioStreams, _, _, errBuf = genericclioptions.NewTestIOStreams() ioStreams, _, _, errBuf = genericiooptions.NewTestIOStreams()
cmd = NewCmdApply("kubectl", tf, ioStreams) cmd = NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "yaml") cmd.Flags().Set("output", "yaml")
@ -1281,7 +1282,7 @@ func TestApplyObjectOutput(t *testing.T) {
tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "yaml") cmd.Flags().Set("output", "yaml")
@ -1342,7 +1343,7 @@ func TestApplyRetry(t *testing.T) {
tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -1391,7 +1392,7 @@ func TestApplyNonExistObject(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -1444,7 +1445,7 @@ func TestApplyEmptyPatch(t *testing.T) {
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
// 1. apply non exist object // 1. apply non exist object
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -1459,7 +1460,7 @@ func TestApplyEmptyPatch(t *testing.T) {
} }
// 2. test apply already exist object, will not send empty patch request // 2. test apply already exist object, will not send empty patch request
ioStreams, _, buf, _ = genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ = genericiooptions.NewTestIOStreams()
cmd = NewCmdApply("kubectl", tf, ioStreams) cmd = NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -1517,7 +1518,7 @@ func testApplyMultipleObjects(t *testing.T, asList bool) {
tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
if asList { if asList {
cmd.Flags().Set("filename", filenameRCSVC) cmd.Flags().Set("filename", filenameRCSVC)
@ -1612,7 +1613,7 @@ func TestApplyNULLPreservation(t *testing.T) {
tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameDeployObjClientside) cmd.Flags().Set("filename", filenameDeployObjClientside)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -1674,7 +1675,7 @@ func TestUnstructuredApply(t *testing.T) {
tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameWidgetClientside) cmd.Flags().Set("filename", filenameWidgetClientside)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -1738,7 +1739,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) {
tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn tf.OpenAPISchemaFunc = testingOpenAPISchema.OpenAPISchemaFn
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameWidgetClientside) cmd.Flags().Set("filename", filenameWidgetClientside)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -1843,7 +1844,7 @@ func TestRunApplySetLastApplied(t *testing.T) {
} }
}) })
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdApplySetLastApplied(tf, ioStreams) cmd := NewCmdApplySetLastApplied(tf, ioStreams)
cmd.Flags().Set("filename", test.filePath) cmd.Flags().Set("filename", test.filePath)
cmd.Flags().Set("output", test.output) cmd.Flags().Set("output", test.output)
@ -1981,7 +1982,7 @@ func TestForceApply(t *testing.T) {
tf.Client = tf.UnstructuredClient tf.Client = tf.UnstructuredClient
tf.ClientConfigVal = &restclient.Config{} tf.ClientConfigVal = &restclient.Config{}
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -2022,7 +2023,7 @@ func TestDontAllowForceApplyWithServerDryRun(t *testing.T) {
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("dry-run", "server") cmd.Flags().Set("dry-run", "server")
@ -2050,7 +2051,7 @@ func TestDontAllowForceApplyWithServerSide(t *testing.T) {
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("server-side", "true") cmd.Flags().Set("server-side", "true")
@ -2072,7 +2073,7 @@ func TestDontAllowApplyWithPodGeneratedName(t *testing.T) {
defer tf.Cleanup() defer tf.Cleanup()
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenamePodGeneratedName) cmd.Flags().Set("filename", filenamePodGeneratedName)
cmd.Flags().Set("dry-run", "client") cmd.Flags().Set("dry-run", "client")
@ -2165,7 +2166,7 @@ func TestApplySetParentValidation(t *testing.T) {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.ApplySet}, t, func(t *testing.T) { cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.ApplySet}, t, func(t *testing.T) {
cmd := &cobra.Command{} cmd := &cobra.Command{}
flags := NewApplyFlags(genericclioptions.NewTestIOStreamsDiscard()) flags := NewApplyFlags(genericiooptions.NewTestIOStreamsDiscard())
flags.AddFlags(cmd) flags.AddFlags(cmd)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("applyset", test.applysetFlag) cmd.Flags().Set("applyset", test.applysetFlag)
@ -2311,7 +2312,7 @@ func TestLoadObjects(t *testing.T) {
cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.ApplySet}, t, func(t *testing.T) { cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.ApplySet}, t, func(t *testing.T) {
cmd := &cobra.Command{} cmd := &cobra.Command{}
flags := NewApplyFlags(genericclioptions.NewTestIOStreamsDiscard()) flags := NewApplyFlags(genericiooptions.NewTestIOStreamsDiscard())
flags.AddFlags(cmd) flags.AddFlags(cmd)
cmd.Flags().Set("filename", testFile+".yaml") cmd.Flags().Set("filename", testFile+".yaml")
cmd.Flags().Set("applyset", filepath.Base(filepath.Dir(testFile))) cmd.Flags().Set("applyset", filepath.Base(filepath.Dir(testFile)))
@ -2381,7 +2382,7 @@ func TestApplySetParentManagement(t *testing.T) {
// Initially, the rc 'exists' server side but the svc and applyset secret do not // Initially, the rc 'exists' server side but the svc and applyset secret do not
// This should 'update' the rc and create the secret // This should 'update' the rc and create the secret
ioStreams, _, outbuff, errbuff := genericclioptions.NewTestIOStreams() ioStreams, _, outbuff, errbuff := genericiooptions.NewTestIOStreams()
cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.ApplySet}, t, func(t *testing.T) { cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.ApplySet}, t, func(t *testing.T) {
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("filename", filenameRC)
@ -2609,7 +2610,7 @@ func TestApplySetInvalidLiveParent(t *testing.T) {
setUpClientsForApplySetWithSSA(t, tf, secret) setUpClientsForApplySetWithSSA(t, tf, secret)
cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.ApplySet}, t, func(t *testing.T) { cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.ApplySet}, t, func(t *testing.T) {
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameSVC) cmd.Flags().Set("filename", filenameSVC)
cmd.Flags().Set("server-side", "true") cmd.Flags().Set("server-side", "true")
@ -2630,7 +2631,7 @@ func TestApplySet_ClusterScopedCustomResourceParent(t *testing.T) {
cr := readUnstructuredFromFile(t, filenameApplySetCR) cr := readUnstructuredFromFile(t, filenameApplySetCR)
setUpClientsForApplySetWithSSA(t, tf, replicationController, crd) setUpClientsForApplySetWithSSA(t, tf, replicationController, crd)
ioStreams, _, outbuff, errbuff := genericclioptions.NewTestIOStreams() ioStreams, _, outbuff, errbuff := genericiooptions.NewTestIOStreams()
cmdutil.BehaviorOnFatal(func(s string, i int) { cmdutil.BehaviorOnFatal(func(s string, i int) {
require.Equal(t, "error: custom resource ApplySet parents cannot be created automatically", s) require.Equal(t, "error: custom resource ApplySet parents cannot be created automatically", s)
}) })
@ -2836,7 +2837,7 @@ func TestApplyWithPruneV2(t *testing.T) {
t.Logf("applying manifest %v", manifest) t.Logf("applying manifest %v", manifest)
cmd := &cobra.Command{} cmd := &cobra.Command{}
flags := NewApplyFlags(genericclioptions.NewTestIOStreamsDiscard()) flags := NewApplyFlags(genericiooptions.NewTestIOStreamsDiscard())
flags.AddFlags(cmd) flags.AddFlags(cmd)
cmd.Flags().Set("filename", filepath.Join(testdir, manifest+".yaml")) cmd.Flags().Set("filename", filepath.Join(testdir, manifest+".yaml"))
cmd.Flags().Set("applyset", filepath.Base(testdir)) cmd.Flags().Set("applyset", filepath.Base(testdir))
@ -2929,7 +2930,7 @@ metadata:
} }
tf.UnstructuredClient = tf.Client tf.UnstructuredClient = tf.Client
ioStreams, _, outbuff, errbuff := genericclioptions.NewTestIOStreams() ioStreams, _, outbuff, errbuff := genericiooptions.NewTestIOStreams()
cmdutil.BehaviorOnFatal(fatalNoExit(t, ioStreams)) cmdutil.BehaviorOnFatal(fatalNoExit(t, ioStreams))
defer cmdutil.DefaultBehaviorOnFatal() defer cmdutil.DefaultBehaviorOnFatal()
@ -3117,7 +3118,7 @@ func TestApplyWithPruneV2Fail(t *testing.T) {
t.Logf("applying manifest %v", manifest) t.Logf("applying manifest %v", manifest)
var unifiedOutput bytes.Buffer var unifiedOutput bytes.Buffer
ioStreams := genericclioptions.IOStreams{ ioStreams := genericiooptions.IOStreams{
ErrOut: &unifiedOutput, ErrOut: &unifiedOutput,
Out: &unifiedOutput, Out: &unifiedOutput,
In: bytes.NewBufferString(""), In: bytes.NewBufferString(""),
@ -3165,7 +3166,7 @@ func TestApplyWithPruneV2Fail(t *testing.T) {
// fatalNoExit is a handler that replaces the default cmdutil.BehaviorOnFatal, // fatalNoExit is a handler that replaces the default cmdutil.BehaviorOnFatal,
// that still prints as expected, but does not call os.Exit (which terminates our tests) // that still prints as expected, but does not call os.Exit (which terminates our tests)
func fatalNoExit(t *testing.T, ioStreams genericclioptions.IOStreams) func(msg string, code int) { func fatalNoExit(t *testing.T, ioStreams genericiooptions.IOStreams) func(msg string, code int) {
return func(msg string, code int) { return func(msg string, code int) {
if len(msg) > 0 { if len(msg) > 0 {
// add newline if needed // add newline if needed
@ -3216,7 +3217,7 @@ func TestApplySetDryRun(t *testing.T) {
} }
t.Run("server side dry run", func(t *testing.T) { t.Run("server side dry run", func(t *testing.T) {
ioStreams, _, outbuff, _ := genericclioptions.NewTestIOStreams() ioStreams, _, outbuff, _ := genericiooptions.NewTestIOStreams()
tf.Client = fakeDryRunClient(t, true) tf.Client = fakeDryRunClient(t, true)
tf.UnstructuredClient = tf.Client tf.UnstructuredClient = tf.Client
cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.ApplySet}, t, func(t *testing.T) { cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.ApplySet}, t, func(t *testing.T) {
@ -3234,7 +3235,7 @@ func TestApplySetDryRun(t *testing.T) {
}) })
t.Run("client side dry run", func(t *testing.T) { t.Run("client side dry run", func(t *testing.T) {
ioStreams, _, outbuff, _ := genericclioptions.NewTestIOStreams() ioStreams, _, outbuff, _ := genericiooptions.NewTestIOStreams()
tf.Client = fakeDryRunClient(t, false) tf.Client = fakeDryRunClient(t, false)
tf.UnstructuredClient = tf.Client tf.UnstructuredClient = tf.Client
cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.ApplySet}, t, func(t *testing.T) { cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.ApplySet}, t, func(t *testing.T) {

View File

@ -22,7 +22,7 @@ import (
"fmt" "fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util" "k8s.io/kubectl/pkg/util"
@ -41,7 +41,7 @@ type ViewLastAppliedOptions struct {
All bool All bool
Factory cmdutil.Factory Factory cmdutil.Factory
genericclioptions.IOStreams genericiooptions.IOStreams
} }
var ( var (
@ -60,7 +60,7 @@ var (
) )
// NewViewLastAppliedOptions takes option arguments from a CLI stream and returns it at ViewLastAppliedOptions type. // NewViewLastAppliedOptions takes option arguments from a CLI stream and returns it at ViewLastAppliedOptions type.
func NewViewLastAppliedOptions(ioStreams genericclioptions.IOStreams) *ViewLastAppliedOptions { func NewViewLastAppliedOptions(ioStreams genericiooptions.IOStreams) *ViewLastAppliedOptions {
return &ViewLastAppliedOptions{ return &ViewLastAppliedOptions{
OutputFormat: "yaml", OutputFormat: "yaml",
@ -69,7 +69,7 @@ func NewViewLastAppliedOptions(ioStreams genericclioptions.IOStreams) *ViewLastA
} }
// NewCmdApplyViewLastApplied creates the cobra CLI `apply` subcommand `view-last-applied`.` // NewCmdApplyViewLastApplied creates the cobra CLI `apply` subcommand `view-last-applied`.`
func NewCmdApplyViewLastApplied(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdApplyViewLastApplied(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
options := NewViewLastAppliedOptions(ioStreams) options := NewViewLastAppliedOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -26,7 +26,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/client-go/dynamic" "k8s.io/client-go/dynamic"
"k8s.io/klog/v2" "k8s.io/klog/v2"
@ -40,7 +40,7 @@ type ApplySetDeleteOptions struct {
Printer printers.ResourcePrinter Printer printers.ResourcePrinter
IOStreams genericclioptions.IOStreams IOStreams genericiooptions.IOStreams
} }
// PruneObject is an apiserver object that should be deleted as part of prune. // PruneObject is an apiserver object that should be deleted as part of prune.

View File

@ -29,6 +29,7 @@ import (
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/remotecommand" "k8s.io/client-go/tools/remotecommand"
@ -88,7 +89,7 @@ type AttachOptions struct {
} }
// NewAttachOptions creates the options for attach // NewAttachOptions creates the options for attach
func NewAttachOptions(streams genericclioptions.IOStreams) *AttachOptions { func NewAttachOptions(streams genericiooptions.IOStreams) *AttachOptions {
return &AttachOptions{ return &AttachOptions{
StreamOptions: exec.StreamOptions{ StreamOptions: exec.StreamOptions{
IOStreams: streams, IOStreams: streams,
@ -99,7 +100,7 @@ func NewAttachOptions(streams genericclioptions.IOStreams) *AttachOptions {
} }
// NewCmdAttach returns the attach Cobra command // NewCmdAttach returns the attach Cobra command
func NewCmdAttach(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdAttach(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
o := NewAttachOptions(streams) o := NewAttachOptions(streams)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "attach (POD | TYPE/NAME) -c CONTAINER", Use: "attach (POD | TYPE/NAME) -c CONTAINER",

View File

@ -31,6 +31,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
"k8s.io/client-go/tools/remotecommand" "k8s.io/client-go/tools/remotecommand"
@ -308,7 +309,7 @@ func TestAttach(t *testing.T) {
options := &AttachOptions{ options := &AttachOptions{
StreamOptions: exec.StreamOptions{ StreamOptions: exec.StreamOptions{
ContainerName: test.container, ContainerName: test.container,
IOStreams: genericclioptions.NewTestIOStreamsDiscard(), IOStreams: genericiooptions.NewTestIOStreamsDiscard(),
}, },
Attach: remoteAttach, Attach: remoteAttach,
GetPodTimeout: 1000, GetPodTimeout: 1000,
@ -379,7 +380,7 @@ func TestAttachWarnings(t *testing.T) {
tf := cmdtesting.NewTestFactory().WithNamespace("test") tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
streams, _, _, bufErr := genericclioptions.NewTestIOStreams() streams, _, _, bufErr := genericiooptions.NewTestIOStreams()
codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
ns := scheme.Codecs.WithoutConversion() ns := scheme.Codecs.WithoutConversion()

View File

@ -18,13 +18,13 @@ package auth
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
) )
// NewCmdAuth returns an initialized Command instance for 'auth' sub command // NewCmdAuth returns an initialized Command instance for 'auth' sub command
func NewCmdAuth(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdAuth(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
// Parent command to which all subcommands are added. // Parent command to which all subcommands are added.
cmds := &cobra.Command{ cmds := &cobra.Command{
Use: "auth", Use: "auth",

View File

@ -34,7 +34,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
discovery "k8s.io/client-go/discovery" discovery "k8s.io/client-go/discovery"
authorizationv1client "k8s.io/client-go/kubernetes/typed/authorization/v1" authorizationv1client "k8s.io/client-go/kubernetes/typed/authorization/v1"
@ -62,7 +62,7 @@ type CanIOptions struct {
ResourceName string ResourceName string
List bool List bool
genericclioptions.IOStreams genericiooptions.IOStreams
WarningPrinter *printers.WarningPrinter WarningPrinter *printers.WarningPrinter
} }
@ -110,7 +110,7 @@ var (
) )
// NewCmdCanI returns an initialized Command for 'auth can-i' sub command // NewCmdCanI returns an initialized Command for 'auth can-i' sub command
func NewCmdCanI(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdCanI(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
o := &CanIOptions{ o := &CanIOptions{
IOStreams: streams, IOStreams: streams,
} }

View File

@ -27,7 +27,7 @@ import (
authorizationv1 "k8s.io/api/authorization/v1" authorizationv1 "k8s.io/api/authorization/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
@ -215,7 +215,7 @@ func TestRunAccessList(t *testing.T) {
} }
}), }),
} }
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
options.IOStreams = ioStreams options.IOStreams = ioStreams
if err := options.Complete(tf, []string{}); err != nil { if err := options.Complete(tf, []string{}); err != nil {
t.Errorf("got unexpected error when do Complete(): %v", err) t.Errorf("got unexpected error when do Complete(): %v", err)
@ -291,7 +291,7 @@ func TestRunResourceFor(t *testing.T) {
tf := cmdtesting.NewTestFactory().WithNamespace("test") tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
ioStreams, _, _, buf := genericclioptions.NewTestIOStreams() ioStreams, _, _, buf := genericiooptions.NewTestIOStreams()
test.o.IOStreams = ioStreams test.o.IOStreams = ioStreams
test.o.WarningPrinter = printers.NewWarningPrinter(test.o.IOStreams.ErrOut, printers.WarningPrinterOptions{Color: false}) test.o.WarningPrinter = printers.NewWarningPrinter(test.o.IOStreams.ErrOut, printers.WarningPrinterOptions{Color: false})

View File

@ -28,6 +28,7 @@ import (
rbacv1alpha1 "k8s.io/api/rbac/v1alpha1" rbacv1alpha1 "k8s.io/api/rbac/v1alpha1"
rbacv1beta1 "k8s.io/api/rbac/v1beta1" rbacv1beta1 "k8s.io/api/rbac/v1beta1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1" corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
@ -53,7 +54,7 @@ type ReconcileOptions struct {
PrintObject printers.ResourcePrinterFunc PrintObject printers.ResourcePrinterFunc
genericclioptions.IOStreams genericiooptions.IOStreams
} }
var ( var (
@ -76,7 +77,7 @@ var (
) )
// NewReconcileOptions returns a new ReconcileOptions instance // NewReconcileOptions returns a new ReconcileOptions instance
func NewReconcileOptions(ioStreams genericclioptions.IOStreams) *ReconcileOptions { func NewReconcileOptions(ioStreams genericiooptions.IOStreams) *ReconcileOptions {
return &ReconcileOptions{ return &ReconcileOptions{
FilenameOptions: &resource.FilenameOptions{}, FilenameOptions: &resource.FilenameOptions{},
PrintFlags: genericclioptions.NewPrintFlags("reconciled").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("reconciled").WithTypeSetter(scheme.Scheme),
@ -85,7 +86,7 @@ func NewReconcileOptions(ioStreams genericclioptions.IOStreams) *ReconcileOption
} }
// NewCmdReconcile holds the options for 'auth reconcile' sub command // NewCmdReconcile holds the options for 'auth reconcile' sub command
func NewCmdReconcile(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdReconcile(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
o := NewReconcileOptions(streams) o := NewReconcileOptions(streams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
authenticationv1alpha1client "k8s.io/client-go/kubernetes/typed/authentication/v1alpha1" authenticationv1alpha1client "k8s.io/client-go/kubernetes/typed/authentication/v1alpha1"
authenticationv1beta1client "k8s.io/client-go/kubernetes/typed/authentication/v1beta1" authenticationv1beta1client "k8s.io/client-go/kubernetes/typed/authentication/v1beta1"
@ -45,11 +46,11 @@ type WhoAmIFlags struct {
RESTClientGetter genericclioptions.RESTClientGetter RESTClientGetter genericclioptions.RESTClientGetter
PrintFlags *genericclioptions.PrintFlags PrintFlags *genericclioptions.PrintFlags
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewWhoAmIFlags returns a default WhoAmIFlags. // NewWhoAmIFlags returns a default WhoAmIFlags.
func NewWhoAmIFlags(restClientGetter genericclioptions.RESTClientGetter, streams genericclioptions.IOStreams) *WhoAmIFlags { func NewWhoAmIFlags(restClientGetter genericclioptions.RESTClientGetter, streams genericiooptions.IOStreams) *WhoAmIFlags {
return &WhoAmIFlags{ return &WhoAmIFlags{
RESTClientGetter: restClientGetter, RESTClientGetter: restClientGetter,
PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme),
@ -107,7 +108,7 @@ type WhoAmIOptions struct {
resourcePrinterFunc printers.ResourcePrinterFunc resourcePrinterFunc printers.ResourcePrinterFunc
genericclioptions.IOStreams genericiooptions.IOStreams
} }
var ( var (
@ -129,7 +130,7 @@ var (
) )
// NewCmdWhoAmI returns an initialized Command for 'auth whoami' sub command. Experimental. // NewCmdWhoAmI returns an initialized Command for 'auth whoami' sub command. Experimental.
func NewCmdWhoAmI(restClientGetter genericclioptions.RESTClientGetter, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdWhoAmI(restClientGetter genericclioptions.RESTClientGetter, streams genericiooptions.IOStreams) *cobra.Command {
flags := NewWhoAmIFlags(restClientGetter, streams) flags := NewWhoAmIFlags(restClientGetter, streams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -27,6 +27,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
autoscalingv1client "k8s.io/client-go/kubernetes/typed/autoscaling/v1" autoscalingv1client "k8s.io/client-go/kubernetes/typed/autoscaling/v1"
@ -80,11 +81,11 @@ type AutoscaleOptions struct {
HPAClient autoscalingv1client.HorizontalPodAutoscalersGetter HPAClient autoscalingv1client.HorizontalPodAutoscalersGetter
scaleKindResolver scale.ScaleKindResolver scaleKindResolver scale.ScaleKindResolver
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewAutoscaleOptions creates the options for autoscale // NewAutoscaleOptions creates the options for autoscale
func NewAutoscaleOptions(ioStreams genericclioptions.IOStreams) *AutoscaleOptions { func NewAutoscaleOptions(ioStreams genericiooptions.IOStreams) *AutoscaleOptions {
return &AutoscaleOptions{ return &AutoscaleOptions{
PrintFlags: genericclioptions.NewPrintFlags("autoscaled").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("autoscaled").WithTypeSetter(scheme.Scheme),
FilenameOptions: &resource.FilenameOptions{}, FilenameOptions: &resource.FilenameOptions{},
@ -96,7 +97,7 @@ func NewAutoscaleOptions(ioStreams genericclioptions.IOStreams) *AutoscaleOption
} }
// NewCmdAutoscale returns the autoscale Cobra command // NewCmdAutoscale returns the autoscale Cobra command
func NewCmdAutoscale(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdAutoscale(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewAutoscaleOptions(ioStreams) o := NewAutoscaleOptions(ioStreams)
validArgs := []string{"deployment", "replicaset", "replicationcontroller", "statefulset"} validArgs := []string{"deployment", "replicaset", "replicationcontroller", "statefulset"}

View File

@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
v1 "k8s.io/client-go/kubernetes/typed/certificates/v1" v1 "k8s.io/client-go/kubernetes/typed/certificates/v1"
@ -40,7 +41,7 @@ import (
) )
// NewCmdCertificate returns `certificate` Cobra command // NewCmdCertificate returns `certificate` Cobra command
func NewCmdCertificate(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCertificate(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericiooptions.IOStreams) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "certificate SUBCOMMAND", Use: "certificate SUBCOMMAND",
DisableFlagsInUseLine: true, DisableFlagsInUseLine: true,
@ -70,11 +71,11 @@ type CertificateOptions struct {
certificatesV1Client v1.CertificatesV1Interface certificatesV1Client v1.CertificatesV1Interface
builder *resource.Builder builder *resource.Builder
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewCertificateOptions creates CertificateOptions struct for `certificate` command // NewCertificateOptions creates CertificateOptions struct for `certificate` command
func NewCertificateOptions(ioStreams genericclioptions.IOStreams, operation string) *CertificateOptions { func NewCertificateOptions(ioStreams genericiooptions.IOStreams, operation string) *CertificateOptions {
return &CertificateOptions{ return &CertificateOptions{
PrintFlags: genericclioptions.NewPrintFlags(operation).WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags(operation).WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -119,7 +120,7 @@ func (o *CertificateOptions) Validate() error {
} }
// NewCmdCertificateApprove returns the `certificate approve` Cobra command // NewCmdCertificateApprove returns the `certificate approve` Cobra command
func NewCmdCertificateApprove(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCertificateApprove(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewCertificateOptions(ioStreams, "approved") o := NewCertificateOptions(ioStreams, "approved")
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -167,7 +168,7 @@ func (o *CertificateOptions) RunCertificateApprove(force bool) error {
} }
// NewCmdCertificateDeny returns the `certificate deny` Cobra command // NewCmdCertificateDeny returns the `certificate deny` Cobra command
func NewCmdCertificateDeny(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCertificateDeny(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewCertificateOptions(ioStreams, "denied") o := NewCertificateOptions(ioStreams, "denied")
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -29,7 +29,7 @@ import (
certificatesv1 "k8s.io/api/certificates/v1" certificatesv1 "k8s.io/api/certificates/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
@ -235,7 +235,7 @@ func TestCertificates(t *testing.T) {
NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer, NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer,
Client: fakeClient, Client: fakeClient,
} }
streams, _, buf, errbuf := genericclioptions.NewTestIOStreams() streams, _, buf, errbuf := genericiooptions.NewTestIOStreams()
tf.ClientConfigVal.Transport = fakeClient.Transport tf.ClientConfigVal.Transport = fakeClient.Transport
defer func() { defer func() {

View File

@ -25,6 +25,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilnet "k8s.io/apimachinery/pkg/util/net" utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -47,7 +48,7 @@ var (
) )
type ClusterInfoOptions struct { type ClusterInfoOptions struct {
genericclioptions.IOStreams genericiooptions.IOStreams
Namespace string Namespace string
@ -55,7 +56,7 @@ type ClusterInfoOptions struct {
Client *restclient.Config Client *restclient.Config
} }
func NewCmdClusterInfo(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdClusterInfo(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := &ClusterInfoOptions{ o := &ClusterInfoOptions{
IOStreams: ioStreams, IOStreams: ioStreams,
} }

View File

@ -29,6 +29,7 @@ import (
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
appsv1client "k8s.io/client-go/kubernetes/typed/apps/v1" appsv1client "k8s.io/client-go/kubernetes/typed/apps/v1"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1" corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
@ -59,10 +60,10 @@ type ClusterInfoDumpOptions struct {
RESTClientGetter genericclioptions.RESTClientGetter RESTClientGetter genericclioptions.RESTClientGetter
LogsForObject polymorphichelpers.LogsForObjectFunc LogsForObject polymorphichelpers.LogsForObjectFunc
genericclioptions.IOStreams genericiooptions.IOStreams
} }
func NewCmdClusterInfoDump(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdClusterInfoDump(restClientGetter genericclioptions.RESTClientGetter, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := &ClusterInfoDumpOptions{ o := &ClusterInfoDumpOptions{
PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme).WithDefaultOutput("json"), PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme).WithDefaultOutput("json"),

View File

@ -21,7 +21,7 @@ import (
"path" "path"
"testing" "testing"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
) )
@ -41,7 +41,7 @@ func TestSetupOutputWriterNoOp(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
_, _, buf, _ := genericclioptions.NewTestIOStreams() _, _, buf, _ := genericiooptions.NewTestIOStreams()
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup() defer f.Cleanup()
@ -63,7 +63,7 @@ func TestSetupOutputWriterFile(t *testing.T) {
fullPath := path.Join(dir, file) + extension fullPath := path.Join(dir, file) + extension
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
_, _, buf, _ := genericclioptions.NewTestIOStreams() _, _, buf, _ := genericiooptions.NewTestIOStreams()
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup() defer f.Cleanup()

View File

@ -28,6 +28,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
cliflag "k8s.io/component-base/cli/flag" cliflag "k8s.io/component-base/cli/flag"
@ -92,7 +93,7 @@ type KubectlOptions struct {
Arguments []string Arguments []string
ConfigFlags *genericclioptions.ConfigFlags ConfigFlags *genericclioptions.ConfigFlags
genericclioptions.IOStreams genericiooptions.IOStreams
} }
var defaultConfigFlags = genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag().WithDiscoveryBurst(300).WithDiscoveryQPS(50.0) var defaultConfigFlags = genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag().WithDiscoveryBurst(300).WithDiscoveryQPS(50.0)
@ -103,7 +104,7 @@ func NewDefaultKubectlCommand() *cobra.Command {
PluginHandler: NewDefaultPluginHandler(plugin.ValidPluginFilenamePrefixes), PluginHandler: NewDefaultPluginHandler(plugin.ValidPluginFilenamePrefixes),
Arguments: os.Args, Arguments: os.Args,
ConfigFlags: defaultConfigFlags, ConfigFlags: defaultConfigFlags,
IOStreams: genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}, IOStreams: genericiooptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr},
}) })
} }

View File

@ -27,13 +27,14 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
) )
func TestNormalizationFuncGlobalExistence(t *testing.T) { func TestNormalizationFuncGlobalExistence(t *testing.T) {
// This test can be safely deleted when we will not support multiple flag formats // This test can be safely deleted when we will not support multiple flag formats
root := NewKubectlCommand(KubectlOptions{IOStreams: genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}}) root := NewKubectlCommand(KubectlOptions{IOStreams: genericiooptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}})
if root.Parent() != nil { if root.Parent() != nil {
t.Fatal("We expect the root command to be returned") t.Fatal("We expect the root command to be returned")
@ -132,7 +133,7 @@ func TestKubectlSubcommandShadowPlugin(t *testing.T) {
pluginsHandler := &testPluginHandler{ pluginsHandler := &testPluginHandler{
pluginsDirectory: "plugin/testdata", pluginsDirectory: "plugin/testdata",
} }
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
root := NewDefaultKubectlCommandWithArgs(KubectlOptions{PluginHandler: pluginsHandler, Arguments: test.args, IOStreams: ioStreams}) root := NewDefaultKubectlCommandWithArgs(KubectlOptions{PluginHandler: pluginsHandler, Arguments: test.args, IOStreams: ioStreams})
if err := root.Execute(); err != nil { if err := root.Execute(); err != nil {
@ -236,7 +237,7 @@ func TestKubectlCommandHandlesPlugins(t *testing.T) {
pluginsHandler := &testPluginHandler{ pluginsHandler := &testPluginHandler{
pluginsDirectory: "plugin/testdata", pluginsDirectory: "plugin/testdata",
} }
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
root := NewDefaultKubectlCommandWithArgs(KubectlOptions{PluginHandler: pluginsHandler, Arguments: test.args, IOStreams: ioStreams}) root := NewDefaultKubectlCommandWithArgs(KubectlOptions{PluginHandler: pluginsHandler, Arguments: test.args, IOStreams: ioStreams})
if err := root.Execute(); err != nil { if err := root.Execute(); err != nil {

View File

@ -22,7 +22,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
) )
func TestBashCompletions(t *testing.T) { func TestBashCompletions(t *testing.T) {
@ -69,7 +69,7 @@ See 'kubectl completion -h' for help and examples`,
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(tt *testing.T) { t.Run(tc.name, func(tt *testing.T) {
_, _, out, _ := genericclioptions.NewTestIOStreams() _, _, out, _ := genericiooptions.NewTestIOStreams()
parentCmd := &cobra.Command{ parentCmd := &cobra.Command{
Use: "kubectl", Use: "kubectl",
} }

View File

@ -23,7 +23,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n" "k8s.io/kubectl/pkg/util/i18n"
@ -31,7 +31,7 @@ import (
) )
// NewCmdConfig creates a command object for the "config" action, and adds all child commands to it. // NewCmdConfig creates a command object for the "config" action, and adds all child commands to it.
func NewCmdConfig(pathOptions *clientcmd.PathOptions, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdConfig(pathOptions *clientcmd.PathOptions, streams genericiooptions.IOStreams) *cobra.Command {
if len(pathOptions.ExplicitFileFlag) == 0 { if len(pathOptions.ExplicitFileFlag) == 0 {
pathOptions.ExplicitFileFlag = clientcmd.RecommendedConfigPathFlag pathOptions.ExplicitFileFlag = clientcmd.RecommendedConfigPathFlag
} }
@ -54,7 +54,7 @@ func NewCmdConfig(pathOptions *clientcmd.PathOptions, streams genericclioptions.
// file paths are common to all sub commands // file paths are common to all sub commands
cmd.PersistentFlags().StringVar(&pathOptions.LoadingRules.ExplicitPath, pathOptions.ExplicitFileFlag, pathOptions.LoadingRules.ExplicitPath, "use a particular kubeconfig file") cmd.PersistentFlags().StringVar(&pathOptions.LoadingRules.ExplicitPath, pathOptions.ExplicitFileFlag, pathOptions.LoadingRules.ExplicitPath, "use a particular kubeconfig file")
// TODO(juanvallejo): update all subcommands to work with genericclioptions.IOStreams // TODO(juanvallejo): update all subcommands to work with genericiooptions.IOStreams
cmd.AddCommand(NewCmdConfigView(streams, pathOptions)) cmd.AddCommand(NewCmdConfigView(streams, pathOptions))
cmd.AddCommand(NewCmdConfigSetCluster(streams.Out, pathOptions)) cmd.AddCommand(NewCmdConfigSetCluster(streams.Out, pathOptions))
cmd.AddCommand(NewCmdConfigSetCredentials(streams.Out, pathOptions)) cmd.AddCommand(NewCmdConfigSetCredentials(streams.Out, pathOptions))

View File

@ -26,7 +26,7 @@ import (
apiequality "k8s.io/apimachinery/pkg/api/equality" apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/diff"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -862,7 +862,7 @@ func testConfigCommand(args []string, startingConfig clientcmdapi.Config, t *tes
argsToUse = append(argsToUse, "--kubeconfig="+fakeKubeFile.Name()) argsToUse = append(argsToUse, "--kubeconfig="+fakeKubeFile.Name())
argsToUse = append(argsToUse, args...) argsToUse = append(argsToUse, args...)
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdConfig(clientcmd.NewDefaultPathOptions(), streams) cmd := NewCmdConfig(clientcmd.NewDefaultPathOptions(), streams)
// "context" is a global flag, inherited from base kubectl command in the real world // "context" is a global flag, inherited from base kubectl command in the real world
cmd.PersistentFlags().String("context", "", "The name of the kubeconfig context to use") cmd.PersistentFlags().String("context", "", "The name of the kubeconfig context to use")

View File

@ -21,7 +21,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -44,11 +44,11 @@ type DeleteUserOptions struct {
config *clientcmdapi.Config config *clientcmdapi.Config
configFile string configFile string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewDeleteUserOptions creates the options for the command // NewDeleteUserOptions creates the options for the command
func NewDeleteUserOptions(ioStreams genericclioptions.IOStreams, configAccess clientcmd.ConfigAccess) *DeleteUserOptions { func NewDeleteUserOptions(ioStreams genericiooptions.IOStreams, configAccess clientcmd.ConfigAccess) *DeleteUserOptions {
return &DeleteUserOptions{ return &DeleteUserOptions{
configAccess: configAccess, configAccess: configAccess,
IOStreams: ioStreams, IOStreams: ioStreams,
@ -56,7 +56,7 @@ func NewDeleteUserOptions(ioStreams genericclioptions.IOStreams, configAccess cl
} }
// NewCmdConfigDeleteUser returns a Command instance for 'config delete-user' sub command // NewCmdConfigDeleteUser returns a Command instance for 'config delete-user' sub command
func NewCmdConfigDeleteUser(streams genericclioptions.IOStreams, configAccess clientcmd.ConfigAccess) *cobra.Command { func NewCmdConfigDeleteUser(streams genericiooptions.IOStreams, configAccess clientcmd.ConfigAccess) *cobra.Command {
o := NewDeleteUserOptions(streams, configAccess) o := NewDeleteUserOptions(streams, configAccess)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -21,7 +21,7 @@ import (
"strings" "strings"
"testing" "testing"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
@ -51,7 +51,7 @@ func TestDeleteUserComplete(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup() defer tf.Cleanup()
ioStreams, _, out, _ := genericclioptions.NewTestIOStreams() ioStreams, _, out, _ := genericiooptions.NewTestIOStreams()
pathOptions, err := tf.PathOptionsWithConfig(clientcmdapi.Config{}) pathOptions, err := tf.PathOptionsWithConfig(clientcmdapi.Config{})
if err != nil { if err != nil {
t.Fatalf("unexpected error executing command: %v", err) t.Fatalf("unexpected error executing command: %v", err)
@ -116,7 +116,7 @@ func TestDeleteUserValidate(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup() defer tf.Cleanup()
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
pathOptions, err := tf.PathOptionsWithConfig(test.config) pathOptions, err := tf.PathOptionsWithConfig(test.config)
if err != nil { if err != nil {
t.Fatalf("unexpected error executing command: %v", err) t.Fatalf("unexpected error executing command: %v", err)
@ -165,7 +165,7 @@ func TestDeleteUserRun(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup() defer tf.Cleanup()
ioStreams, _, out, _ := genericclioptions.NewTestIOStreams() ioStreams, _, out, _ := genericiooptions.NewTestIOStreams()
pathOptions, err := tf.PathOptionsWithConfig(test.config) pathOptions, err := tf.PathOptionsWithConfig(test.config)
if err != nil { if err != nil {
t.Fatalf("unexpected error executing command: %v", err) t.Fatalf("unexpected error executing command: %v", err)

View File

@ -27,7 +27,7 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
@ -46,7 +46,7 @@ type GetContextsOptions struct {
outputFormat string outputFormat string
noHeaders bool noHeaders bool
genericclioptions.IOStreams genericiooptions.IOStreams
} }
var ( var (
@ -62,7 +62,7 @@ var (
// NewCmdConfigGetContexts creates a command object for the "get-contexts" action, which // NewCmdConfigGetContexts creates a command object for the "get-contexts" action, which
// retrieves one or more contexts from a kubeconfig. // retrieves one or more contexts from a kubeconfig.
func NewCmdConfigGetContexts(streams genericclioptions.IOStreams, configAccess clientcmd.ConfigAccess) *cobra.Command { func NewCmdConfigGetContexts(streams genericiooptions.IOStreams, configAccess clientcmd.ConfigAccess) *cobra.Command {
options := &GetContextsOptions{ options := &GetContextsOptions{
configAccess: configAccess, configAccess: configAccess,

View File

@ -20,7 +20,7 @@ import (
"os" "os"
"testing" "testing"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
) )
@ -156,7 +156,7 @@ func (test getContextsTest) run(t *testing.T) {
pathOptions := clientcmd.NewDefaultPathOptions() pathOptions := clientcmd.NewDefaultPathOptions()
pathOptions.GlobalFile = fakeKubeFile.Name() pathOptions.GlobalFile = fakeKubeFile.Name()
pathOptions.EnvVar = "" pathOptions.EnvVar = ""
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
options := GetContextsOptions{ options := GetContextsOptions{
configAccess: pathOptions, configAccess: pathOptions,
} }

View File

@ -22,7 +22,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n" "k8s.io/kubectl/pkg/util/i18n"
@ -39,11 +39,11 @@ var (
type GetUsersOptions struct { type GetUsersOptions struct {
configAccess clientcmd.ConfigAccess configAccess clientcmd.ConfigAccess
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewGetUsersOptions creates the options for the command // NewGetUsersOptions creates the options for the command
func NewGetUsersOptions(ioStreams genericclioptions.IOStreams, configAccess clientcmd.ConfigAccess) *GetUsersOptions { func NewGetUsersOptions(ioStreams genericiooptions.IOStreams, configAccess clientcmd.ConfigAccess) *GetUsersOptions {
return &GetUsersOptions{ return &GetUsersOptions{
configAccess: configAccess, configAccess: configAccess,
IOStreams: ioStreams, IOStreams: ioStreams,
@ -52,7 +52,7 @@ func NewGetUsersOptions(ioStreams genericclioptions.IOStreams, configAccess clie
// NewCmdConfigGetUsers creates a command object for the "get-users" action, which // NewCmdConfigGetUsers creates a command object for the "get-users" action, which
// lists all users defined in the kubeconfig. // lists all users defined in the kubeconfig.
func NewCmdConfigGetUsers(streams genericclioptions.IOStreams, configAccess clientcmd.ConfigAccess) *cobra.Command { func NewCmdConfigGetUsers(streams genericiooptions.IOStreams, configAccess clientcmd.ConfigAccess) *cobra.Command {
o := NewGetUsersOptions(streams, configAccess) o := NewGetUsersOptions(streams, configAccess)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -19,7 +19,7 @@ package config
import ( import (
"testing" "testing"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
) )
@ -56,7 +56,7 @@ minikube
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup() defer tf.Cleanup()
ioStreams, _, out, _ := genericclioptions.NewTestIOStreams() ioStreams, _, out, _ := genericiooptions.NewTestIOStreams()
pathOptions, err := tf.PathOptionsWithConfig(test.config) pathOptions, err := tf.PathOptionsWithConfig(test.config)
if err != nil { if err != nil {
t.Fatalf("unexpected error executing command: %v", err) t.Fatalf("unexpected error executing command: %v", err)

View File

@ -18,8 +18,11 @@ package config
import ( import (
"errors" "errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
@ -45,7 +48,7 @@ type ViewOptions struct {
Context string Context string
OutputFormat string OutputFormat string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
var ( var (
@ -66,7 +69,7 @@ var (
) )
// NewCmdConfigView returns a Command instance for 'config view' sub command // NewCmdConfigView returns a Command instance for 'config view' sub command
func NewCmdConfigView(streams genericclioptions.IOStreams, ConfigAccess clientcmd.ConfigAccess) *cobra.Command { func NewCmdConfigView(streams genericiooptions.IOStreams, ConfigAccess clientcmd.ConfigAccess) *cobra.Command {
o := &ViewOptions{ o := &ViewOptions{
PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme).WithDefaultOutput("yaml"), PrintFlags: genericclioptions.NewPrintFlags("").WithTypeSetter(scheme.Scheme).WithDefaultOutput("yaml"),
ConfigAccess: ConfigAccess, ConfigAccess: ConfigAccess,

View File

@ -20,7 +20,7 @@ import (
"os" "os"
"testing" "testing"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
) )
@ -305,7 +305,7 @@ func (test viewClusterTest) run(t *testing.T) {
pathOptions := clientcmd.NewDefaultPathOptions() pathOptions := clientcmd.NewDefaultPathOptions()
pathOptions.GlobalFile = fakeKubeFile.Name() pathOptions.GlobalFile = fakeKubeFile.Name()
pathOptions.EnvVar = "" pathOptions.EnvVar = ""
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdConfigView(streams, pathOptions) cmd := NewCmdConfigView(streams, pathOptions)
// "context" is a global flag, inherited from base kubectl command in the real world // "context" is a global flag, inherited from base kubectl command in the real world
cmd.Flags().String("context", "", "The name of the kubeconfig context to use") cmd.Flags().String("context", "", "The name of the kubeconfig context to use")

View File

@ -27,7 +27,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/kubectl/pkg/cmd/exec" "k8s.io/kubectl/pkg/cmd/exec"
@ -78,18 +78,18 @@ type CopyOptions struct {
args []string args []string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewCopyOptions creates the options for copy // NewCopyOptions creates the options for copy
func NewCopyOptions(ioStreams genericclioptions.IOStreams) *CopyOptions { func NewCopyOptions(ioStreams genericiooptions.IOStreams) *CopyOptions {
return &CopyOptions{ return &CopyOptions{
IOStreams: ioStreams, IOStreams: ioStreams,
} }
} }
// NewCmdCp creates a new Copy command. // NewCmdCp creates a new Copy command.
func NewCmdCp(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCp(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewCopyOptions(ioStreams) o := NewCopyOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -266,7 +266,7 @@ func (o *CopyOptions) Run() error {
func (o *CopyOptions) checkDestinationIsDir(dest fileSpec) error { func (o *CopyOptions) checkDestinationIsDir(dest fileSpec) error {
options := &exec.ExecOptions{ options := &exec.ExecOptions{
StreamOptions: exec.StreamOptions{ StreamOptions: exec.StreamOptions{
IOStreams: genericclioptions.IOStreams{ IOStreams: genericiooptions.IOStreams{
Out: bytes.NewBuffer([]byte{}), Out: bytes.NewBuffer([]byte{}),
ErrOut: bytes.NewBuffer([]byte{}), ErrOut: bytes.NewBuffer([]byte{}),
}, },
@ -314,7 +314,7 @@ func (o *CopyOptions) copyToPod(src, dest fileSpec, options *exec.ExecOptions) e
} }
options.StreamOptions = exec.StreamOptions{ options.StreamOptions = exec.StreamOptions{
IOStreams: genericclioptions.IOStreams{ IOStreams: genericiooptions.IOStreams{
In: reader, In: reader,
Out: o.Out, Out: o.Out,
ErrOut: o.ErrOut, ErrOut: o.ErrOut,
@ -361,7 +361,7 @@ func (t *TarPipe) initReadFrom(n uint64) {
t.reader, t.outStream = io.Pipe() t.reader, t.outStream = io.Pipe()
options := &exec.ExecOptions{ options := &exec.ExecOptions{
StreamOptions: exec.StreamOptions{ StreamOptions: exec.StreamOptions{
IOStreams: genericclioptions.IOStreams{ IOStreams: genericiooptions.IOStreams{
In: nil, In: nil,
Out: t.outStream, Out: t.outStream,
ErrOut: t.o.Out, ErrOut: t.o.Out,

View File

@ -31,11 +31,11 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
kexec "k8s.io/kubectl/pkg/cmd/exec" kexec "k8s.io/kubectl/pkg/cmd/exec"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
@ -405,7 +405,7 @@ func TestTarUntar(t *testing.T) {
} }
} }
opts := NewCopyOptions(genericclioptions.NewTestIOStreamsDiscard()) opts := NewCopyOptions(genericiooptions.NewTestIOStreamsDiscard())
writer := &bytes.Buffer{} writer := &bytes.Buffer{}
if err := makeTar(newLocalPath(dir), newRemotePath(dir), writer); err != nil { if err := makeTar(newLocalPath(dir), newRemotePath(dir), writer); err != nil {
@ -467,7 +467,7 @@ func TestTarUntarWrongPrefix(t *testing.T) {
} }
createTmpFile(t, completePath, "sample data") createTmpFile(t, completePath, "sample data")
opts := NewCopyOptions(genericclioptions.NewTestIOStreamsDiscard()) opts := NewCopyOptions(genericiooptions.NewTestIOStreamsDiscard())
writer := &bytes.Buffer{} writer := &bytes.Buffer{}
if err := makeTar(newLocalPath(dir), newRemotePath(dir), writer); err != nil { if err := makeTar(newLocalPath(dir), newRemotePath(dir), writer); err != nil {
@ -589,7 +589,7 @@ func TestBadTar(t *testing.T) {
t.FailNow() t.FailNow()
} }
opts := NewCopyOptions(genericclioptions.NewTestIOStreamsDiscard()) opts := NewCopyOptions(genericiooptions.NewTestIOStreamsDiscard())
if err := opts.untarAll("", "", "/prefix", remotePath{}, newLocalPath(dir), &buf); err != nil { if err := opts.untarAll("", "", "/prefix", remotePath{}, newLocalPath(dir), &buf); err != nil {
t.Errorf("unexpected error: %v ", err) t.Errorf("unexpected error: %v ", err)
t.FailNow() t.FailNow()
@ -618,7 +618,7 @@ func TestCopyToPod(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdCp(tf, ioStreams) cmd := NewCmdCp(tf, ioStreams)
@ -689,7 +689,7 @@ func TestCopyToPodNoPreserve(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdCp(tf, ioStreams) cmd := NewCmdCp(tf, ioStreams)
@ -753,7 +753,7 @@ func TestValidate(t *testing.T) {
expectedErr: true, expectedErr: true,
}, },
} }
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
opts := NewCopyOptions(ioStreams) opts := NewCopyOptions(ioStreams)
for _, test := range tests { for _, test := range tests {
@ -908,7 +908,7 @@ func TestUntar(t *testing.T) {
// Capture warnings to stderr for debugging. // Capture warnings to stderr for debugging.
output := (*testWriter)(t) output := (*testWriter)(t)
opts := NewCopyOptions(genericclioptions.IOStreams{In: &bytes.Buffer{}, Out: output, ErrOut: output}) opts := NewCopyOptions(genericiooptions.IOStreams{In: &bytes.Buffer{}, Out: output, ErrOut: output})
require.NoError(t, opts.untarAll("", "", "", remotePath{}, newLocalPath(basedir), buf)) require.NoError(t, opts.untarAll("", "", "", remotePath{}, newLocalPath(basedir), buf))
@ -959,7 +959,7 @@ func TestUntar_SingleFile(t *testing.T) {
// Capture warnings to stderr for debugging. // Capture warnings to stderr for debugging.
output := (*testWriter)(t) output := (*testWriter)(t)
opts := NewCopyOptions(genericclioptions.IOStreams{In: &bytes.Buffer{}, Out: output, ErrOut: output}) opts := NewCopyOptions(genericiooptions.IOStreams{In: &bytes.Buffer{}, Out: output, ErrOut: output})
require.NoError(t, opts.untarAll("", "", srcName, remotePath{}, newLocalPath(dest), buf)) require.NoError(t, opts.untarAll("", "", srcName, remotePath{}, newLocalPath(dest), buf))
cmpFileData(t, dest, content) cmpFileData(t, dest, content)

View File

@ -33,6 +33,7 @@ import (
kruntime "k8s.io/apimachinery/pkg/runtime" kruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/dynamic" "k8s.io/client-go/dynamic"
@ -65,7 +66,7 @@ type CreateOptions struct {
Recorder genericclioptions.Recorder Recorder genericclioptions.Recorder
PrintObj func(obj kruntime.Object) error PrintObj func(obj kruntime.Object) error
genericclioptions.IOStreams genericiooptions.IOStreams
} }
var ( var (
@ -86,7 +87,7 @@ var (
) )
// NewCreateOptions returns an initialized CreateOptions instance // NewCreateOptions returns an initialized CreateOptions instance
func NewCreateOptions(ioStreams genericclioptions.IOStreams) *CreateOptions { func NewCreateOptions(ioStreams genericiooptions.IOStreams) *CreateOptions {
return &CreateOptions{ return &CreateOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
RecordFlags: genericclioptions.NewRecordFlags(), RecordFlags: genericclioptions.NewRecordFlags(),
@ -98,7 +99,7 @@ func NewCreateOptions(ioStreams genericclioptions.IOStreams) *CreateOptions {
} }
// NewCmdCreate returns new initialized instance of create sub command // NewCmdCreate returns new initialized instance of create sub command
func NewCmdCreate(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreate(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewCreateOptions(ioStreams) o := NewCreateOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -302,7 +303,7 @@ func (o *CreateOptions) RunCreate(f cmdutil.Factory, cmd *cobra.Command) error {
} }
// RunEditOnCreate performs edit on creation // RunEditOnCreate performs edit on creation
func RunEditOnCreate(f cmdutil.Factory, printFlags *genericclioptions.PrintFlags, recordFlags *genericclioptions.RecordFlags, ioStreams genericclioptions.IOStreams, cmd *cobra.Command, options *resource.FilenameOptions, fieldManager string) error { func RunEditOnCreate(f cmdutil.Factory, printFlags *genericclioptions.PrintFlags, recordFlags *genericclioptions.RecordFlags, ioStreams genericiooptions.IOStreams, cmd *cobra.Command, options *resource.FilenameOptions, fieldManager string) error {
editOptions := editor.NewEditOptions(editor.EditBeforeCreateMode, ioStreams) editOptions := editor.NewEditOptions(editor.EditBeforeCreateMode, ioStreams)
editOptions.FilenameOptions = *options editOptions.FilenameOptions = *options
validationDirective, err := cmdutil.GetValidationDirective(cmd) validationDirective, err := cmdutil.GetValidationDirective(cmd)
@ -358,11 +359,11 @@ type CreateSubcommandOptions struct {
PrintObj printers.ResourcePrinterFunc PrintObj printers.ResourcePrinterFunc
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewCreateSubcommandOptions returns initialized CreateSubcommandOptions // NewCreateSubcommandOptions returns initialized CreateSubcommandOptions
func NewCreateSubcommandOptions(ioStreams genericclioptions.IOStreams) *CreateSubcommandOptions { func NewCreateSubcommandOptions(ioStreams genericiooptions.IOStreams) *CreateSubcommandOptions {
return &CreateSubcommandOptions{ return &CreateSubcommandOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,

View File

@ -25,7 +25,7 @@ import (
rbacv1 "k8s.io/api/rbac/v1" rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
cliflag "k8s.io/component-base/cli/flag" cliflag "k8s.io/component-base/cli/flag"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -70,7 +70,7 @@ type CreateClusterRoleOptions struct {
} }
// NewCmdCreateClusterRole initializes and returns new ClusterRoles command // NewCmdCreateClusterRole initializes and returns new ClusterRoles command
func NewCmdCreateClusterRole(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateClusterRole(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
c := &CreateClusterRoleOptions{ c := &CreateClusterRoleOptions{
CreateRoleOptions: NewCreateRoleOptions(ioStreams), CreateRoleOptions: NewCreateRoleOptions(ioStreams),
AggregationRule: map[string]string{}, AggregationRule: map[string]string{},

View File

@ -23,7 +23,7 @@ import (
"k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -149,7 +149,7 @@ func TestCreateClusterRole(t *testing.T) {
} }
for name, test := range tests { for name, test := range tests {
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdCreateClusterRole(tf, ioStreams) cmd := NewCmdCreateClusterRole(tf, ioStreams)
cmd.Flags().Set("dry-run", "client") cmd.Flags().Set("dry-run", "client")
cmd.Flags().Set("output", "yaml") cmd.Flags().Set("output", "yaml")
@ -496,7 +496,7 @@ func TestClusterRoleValidate(t *testing.T) {
for name, test := range tests { for name, test := range tests {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
test.clusterRoleOptions.IOStreams = genericclioptions.NewTestIOStreamsDiscard() test.clusterRoleOptions.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
var err error var err error
test.clusterRoleOptions.Mapper, err = tf.ToRESTMapper() test.clusterRoleOptions.Mapper, err = tf.ToRESTMapper()
if err != nil { if err != nil {

View File

@ -27,6 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
rbacclientv1 "k8s.io/client-go/kubernetes/typed/rbac/v1" rbacclientv1 "k8s.io/client-go/kubernetes/typed/rbac/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -62,11 +63,11 @@ type ClusterRoleBindingOptions struct {
DryRunStrategy cmdutil.DryRunStrategy DryRunStrategy cmdutil.DryRunStrategy
ValidationDirective string ValidationDirective string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewClusterRoleBindingOptions creates a new *ClusterRoleBindingOptions with sane defaults // NewClusterRoleBindingOptions creates a new *ClusterRoleBindingOptions with sane defaults
func NewClusterRoleBindingOptions(ioStreams genericclioptions.IOStreams) *ClusterRoleBindingOptions { func NewClusterRoleBindingOptions(ioStreams genericiooptions.IOStreams) *ClusterRoleBindingOptions {
return &ClusterRoleBindingOptions{ return &ClusterRoleBindingOptions{
Users: []string{}, Users: []string{},
Groups: []string{}, Groups: []string{},
@ -77,7 +78,7 @@ func NewClusterRoleBindingOptions(ioStreams genericclioptions.IOStreams) *Cluste
} }
// NewCmdCreateClusterRoleBinding returns an initialized command instance of ClusterRoleBinding // NewCmdCreateClusterRoleBinding returns an initialized command instance of ClusterRoleBinding
func NewCmdCreateClusterRoleBinding(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateClusterRoleBinding(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewClusterRoleBindingOptions(ioStreams) o := NewClusterRoleBindingOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -31,6 +31,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1" corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -98,11 +99,11 @@ type ConfigMapOptions struct {
DryRunStrategy cmdutil.DryRunStrategy DryRunStrategy cmdutil.DryRunStrategy
ValidationDirective string ValidationDirective string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewConfigMapOptions creates a new *ConfigMapOptions with default value // NewConfigMapOptions creates a new *ConfigMapOptions with default value
func NewConfigMapOptions(ioStreams genericclioptions.IOStreams) *ConfigMapOptions { func NewConfigMapOptions(ioStreams genericiooptions.IOStreams) *ConfigMapOptions {
return &ConfigMapOptions{ return &ConfigMapOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -110,7 +111,7 @@ func NewConfigMapOptions(ioStreams genericclioptions.IOStreams) *ConfigMapOption
} }
// NewCmdCreateConfigMap creates the `create configmap` Cobra command // NewCmdCreateConfigMap creates the `create configmap` Cobra command
func NewCmdCreateConfigMap(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateConfigMap(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewConfigMapOptions(ioStreams) o := NewConfigMapOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -27,6 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
batchv1client "k8s.io/client-go/kubernetes/typed/batch/v1" batchv1client "k8s.io/client-go/kubernetes/typed/batch/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -69,11 +70,11 @@ type CreateCronJobOptions struct {
FieldManager string FieldManager string
CreateAnnotation bool CreateAnnotation bool
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewCreateCronJobOptions returns an initialized CreateCronJobOptions instance // NewCreateCronJobOptions returns an initialized CreateCronJobOptions instance
func NewCreateCronJobOptions(ioStreams genericclioptions.IOStreams) *CreateCronJobOptions { func NewCreateCronJobOptions(ioStreams genericiooptions.IOStreams) *CreateCronJobOptions {
return &CreateCronJobOptions{ return &CreateCronJobOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -81,7 +82,7 @@ func NewCreateCronJobOptions(ioStreams genericclioptions.IOStreams) *CreateCronJ
} }
// NewCmdCreateCronJob is a command to create CronJobs. // NewCmdCreateCronJob is a command to create CronJobs.
func NewCmdCreateCronJob(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateCronJob(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewCreateCronJobOptions(ioStreams) o := NewCreateCronJobOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]", Use: "cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]",

View File

@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
utilrand "k8s.io/apimachinery/pkg/util/rand" utilrand "k8s.io/apimachinery/pkg/util/rand"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
appsv1client "k8s.io/client-go/kubernetes/typed/apps/v1" appsv1client "k8s.io/client-go/kubernetes/typed/apps/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -75,11 +76,11 @@ type CreateDeploymentOptions struct {
DryRunStrategy cmdutil.DryRunStrategy DryRunStrategy cmdutil.DryRunStrategy
ValidationDirective string ValidationDirective string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewCreateDeploymentOptions returns an initialized CreateDeploymentOptions instance // NewCreateDeploymentOptions returns an initialized CreateDeploymentOptions instance
func NewCreateDeploymentOptions(ioStreams genericclioptions.IOStreams) *CreateDeploymentOptions { func NewCreateDeploymentOptions(ioStreams genericiooptions.IOStreams) *CreateDeploymentOptions {
return &CreateDeploymentOptions{ return &CreateDeploymentOptions{
Port: -1, Port: -1,
Replicas: 1, Replicas: 1,
@ -90,7 +91,7 @@ func NewCreateDeploymentOptions(ioStreams genericclioptions.IOStreams) *CreateDe
// NewCmdCreateDeployment is a macro command to create a new deployment. // NewCmdCreateDeployment is a macro command to create a new deployment.
// This command is better known to users as `kubectl create deployment`. // This command is better known to users as `kubectl create deployment`.
func NewCmdCreateDeployment(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateDeployment(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewCreateDeploymentOptions(ioStreams) o := NewCreateDeploymentOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "deployment NAME --image=image -- [COMMAND] [args...]", Use: "deployment NAME --image=image -- [COMMAND] [args...]",

View File

@ -26,6 +26,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
@ -51,7 +52,7 @@ func TestCreateDeployment(t *testing.T) {
} }
tf.ClientConfigVal = &restclient.Config{} tf.ClientConfigVal = &restclient.Config{}
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdCreateDeployment(tf, ioStreams) cmd := NewCmdCreateDeployment(tf, ioStreams)
cmd.Flags().Set("dry-run", "client") cmd.Flags().Set("dry-run", "client")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -82,7 +83,7 @@ func TestCreateDeploymentWithPort(t *testing.T) {
} }
tf.ClientConfigVal = &restclient.Config{} tf.ClientConfigVal = &restclient.Config{}
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdCreateDeployment(tf, ioStreams) cmd := NewCmdCreateDeployment(tf, ioStreams)
cmd.Flags().Set("dry-run", "client") cmd.Flags().Set("dry-run", "client")
cmd.Flags().Set("output", "yaml") cmd.Flags().Set("output", "yaml")
@ -113,7 +114,7 @@ func TestCreateDeploymentWithReplicas(t *testing.T) {
} }
tf.ClientConfigVal = &restclient.Config{} tf.ClientConfigVal = &restclient.Config{}
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdCreateDeployment(tf, ioStreams) cmd := NewCmdCreateDeployment(tf, ioStreams)
cmd.Flags().Set("dry-run", "client") cmd.Flags().Set("dry-run", "client")
cmd.Flags().Set("output", "jsonpath={.spec.replicas}") cmd.Flags().Set("output", "jsonpath={.spec.replicas}")
@ -143,7 +144,7 @@ func TestCreateDeploymentNoImage(t *testing.T) {
} }
tf.ClientConfigVal = &restclient.Config{} tf.ClientConfigVal = &restclient.Config{}
ioStreams := genericclioptions.NewTestIOStreamsDiscard() ioStreams := genericiooptions.NewTestIOStreamsDiscard()
cmd := NewCmdCreateDeployment(tf, ioStreams) cmd := NewCmdCreateDeployment(tf, ioStreams)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
options := &CreateDeploymentOptions{ options := &CreateDeploymentOptions{

View File

@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
networkingv1client "k8s.io/client-go/kubernetes/typed/networking/v1" networkingv1client "k8s.io/client-go/kubernetes/typed/networking/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -121,11 +122,11 @@ type CreateIngressOptions struct {
FieldManager string FieldManager string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewCreateIngressOptions creates the CreateIngressOptions to be used later // NewCreateIngressOptions creates the CreateIngressOptions to be used later
func NewCreateIngressOptions(ioStreams genericclioptions.IOStreams) *CreateIngressOptions { func NewCreateIngressOptions(ioStreams genericiooptions.IOStreams) *CreateIngressOptions {
return &CreateIngressOptions{ return &CreateIngressOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -134,7 +135,7 @@ func NewCreateIngressOptions(ioStreams genericclioptions.IOStreams) *CreateIngre
// NewCmdCreateIngress is a macro command to create a new ingress. // NewCmdCreateIngress is a macro command to create a new ingress.
// This command is better known to users as `kubectl create ingress`. // This command is better known to users as `kubectl create ingress`.
func NewCmdCreateIngress(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateIngress(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewCreateIngressOptions(ioStreams) o := NewCreateIngressOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -27,6 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
batchv1client "k8s.io/client-go/kubernetes/typed/batch/v1" batchv1client "k8s.io/client-go/kubernetes/typed/batch/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -71,11 +72,11 @@ type CreateJobOptions struct {
FieldManager string FieldManager string
CreateAnnotation bool CreateAnnotation bool
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewCreateJobOptions initializes and returns new CreateJobOptions instance // NewCreateJobOptions initializes and returns new CreateJobOptions instance
func NewCreateJobOptions(ioStreams genericclioptions.IOStreams) *CreateJobOptions { func NewCreateJobOptions(ioStreams genericiooptions.IOStreams) *CreateJobOptions {
return &CreateJobOptions{ return &CreateJobOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -83,7 +84,7 @@ func NewCreateJobOptions(ioStreams genericclioptions.IOStreams) *CreateJobOption
} }
// NewCmdCreateJob is a command to ease creating Jobs from CronJobs. // NewCmdCreateJob is a command to ease creating Jobs from CronJobs.
func NewCmdCreateJob(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateJob(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewCreateJobOptions(ioStreams) o := NewCreateJobOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]", Use: "job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]",

View File

@ -30,6 +30,7 @@ import (
"k8s.io/kubectl/pkg/util" "k8s.io/kubectl/pkg/util"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n" "k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates" "k8s.io/kubectl/pkg/util/templates"
@ -60,11 +61,11 @@ type NamespaceOptions struct {
PrintObj func(obj runtime.Object) error PrintObj func(obj runtime.Object) error
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewNamespaceOptions creates a new *NamespaceOptions with sane defaults // NewNamespaceOptions creates a new *NamespaceOptions with sane defaults
func NewNamespaceOptions(ioStreams genericclioptions.IOStreams) *NamespaceOptions { func NewNamespaceOptions(ioStreams genericiooptions.IOStreams) *NamespaceOptions {
return &NamespaceOptions{ return &NamespaceOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -72,7 +73,7 @@ func NewNamespaceOptions(ioStreams genericclioptions.IOStreams) *NamespaceOption
} }
// NewCmdCreateNamespace is a macro command to create a new namespace // NewCmdCreateNamespace is a macro command to create a new namespace
func NewCmdCreateNamespace(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateNamespace(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewNamespaceOptions(ioStreams) o := NewNamespaceOptions(ioStreams)

View File

@ -28,6 +28,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
policyv1client "k8s.io/client-go/kubernetes/typed/policy/v1" policyv1client "k8s.io/client-go/kubernetes/typed/policy/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -72,11 +73,11 @@ type PodDisruptionBudgetOpts struct {
DryRunStrategy cmdutil.DryRunStrategy DryRunStrategy cmdutil.DryRunStrategy
ValidationDirective string ValidationDirective string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewPodDisruptionBudgetOpts creates a new *PodDisruptionBudgetOpts with sane defaults // NewPodDisruptionBudgetOpts creates a new *PodDisruptionBudgetOpts with sane defaults
func NewPodDisruptionBudgetOpts(ioStreams genericclioptions.IOStreams) *PodDisruptionBudgetOpts { func NewPodDisruptionBudgetOpts(ioStreams genericiooptions.IOStreams) *PodDisruptionBudgetOpts {
return &PodDisruptionBudgetOpts{ return &PodDisruptionBudgetOpts{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -84,7 +85,7 @@ func NewPodDisruptionBudgetOpts(ioStreams genericclioptions.IOStreams) *PodDisru
} }
// NewCmdCreatePodDisruptionBudget is a macro command to create a new pod disruption budget. // NewCmdCreatePodDisruptionBudget is a macro command to create a new pod disruption budget.
func NewCmdCreatePodDisruptionBudget(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreatePodDisruptionBudget(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewPodDisruptionBudgetOpts(ioStreams) o := NewPodDisruptionBudgetOpts(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -27,6 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
schedulingv1client "k8s.io/client-go/kubernetes/typed/scheduling/v1" schedulingv1client "k8s.io/client-go/kubernetes/typed/scheduling/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -67,11 +68,11 @@ type PriorityClassOptions struct {
DryRunStrategy cmdutil.DryRunStrategy DryRunStrategy cmdutil.DryRunStrategy
ValidationDirective string ValidationDirective string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewPriorityClassOptions returns an initialized PriorityClassOptions instance // NewPriorityClassOptions returns an initialized PriorityClassOptions instance
func NewPriorityClassOptions(ioStreams genericclioptions.IOStreams) *PriorityClassOptions { func NewPriorityClassOptions(ioStreams genericiooptions.IOStreams) *PriorityClassOptions {
return &PriorityClassOptions{ return &PriorityClassOptions{
Value: 0, Value: 0,
PreemptionPolicy: "PreemptLowerPriority", PreemptionPolicy: "PreemptLowerPriority",
@ -81,7 +82,7 @@ func NewPriorityClassOptions(ioStreams genericclioptions.IOStreams) *PriorityCla
} }
// NewCmdCreatePriorityClass is a macro command to create a new priorityClass. // NewCmdCreatePriorityClass is a macro command to create a new priorityClass.
func NewCmdCreatePriorityClass(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreatePriorityClass(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewPriorityClassOptions(ioStreams) o := NewPriorityClassOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
@ -51,7 +52,7 @@ func TestCreatePriorityClass(t *testing.T) {
outputFormat := "name" outputFormat := "name"
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdCreatePriorityClass(tf, ioStreams) cmd := NewCmdCreatePriorityClass(tf, ioStreams)
cmd.Flags().Set("value", "1000") cmd.Flags().Set("value", "1000")
cmd.Flags().Set("global-default", "true") cmd.Flags().Set("global-default", "true")

View File

@ -28,6 +28,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
coreclient "k8s.io/client-go/kubernetes/typed/core/v1" coreclient "k8s.io/client-go/kubernetes/typed/core/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -68,11 +69,11 @@ type QuotaOpts struct {
DryRunStrategy cmdutil.DryRunStrategy DryRunStrategy cmdutil.DryRunStrategy
ValidationDirective string ValidationDirective string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewQuotaOpts creates a new *QuotaOpts with sane defaults // NewQuotaOpts creates a new *QuotaOpts with sane defaults
func NewQuotaOpts(ioStreams genericclioptions.IOStreams) *QuotaOpts { func NewQuotaOpts(ioStreams genericiooptions.IOStreams) *QuotaOpts {
return &QuotaOpts{ return &QuotaOpts{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -80,7 +81,7 @@ func NewQuotaOpts(ioStreams genericclioptions.IOStreams) *QuotaOpts {
} }
// NewCmdCreateQuota is a macro command to create a new quota // NewCmdCreateQuota is a macro command to create a new quota
func NewCmdCreateQuota(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateQuota(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewQuotaOpts(ioStreams) o := NewQuotaOpts(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
clientgorbacv1 "k8s.io/client-go/kubernetes/typed/rbac/v1" clientgorbacv1 "k8s.io/client-go/kubernetes/typed/rbac/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -148,11 +149,11 @@ type CreateRoleOptions struct {
FieldManager string FieldManager string
CreateAnnotation bool CreateAnnotation bool
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewCreateRoleOptions returns an initialized CreateRoleOptions instance // NewCreateRoleOptions returns an initialized CreateRoleOptions instance
func NewCreateRoleOptions(ioStreams genericclioptions.IOStreams) *CreateRoleOptions { func NewCreateRoleOptions(ioStreams genericiooptions.IOStreams) *CreateRoleOptions {
return &CreateRoleOptions{ return &CreateRoleOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
@ -161,7 +162,7 @@ func NewCreateRoleOptions(ioStreams genericclioptions.IOStreams) *CreateRoleOpti
} }
// NewCmdCreateRole returnns an initialized Command instance for 'create role' sub command // NewCmdCreateRole returnns an initialized Command instance for 'create role' sub command
func NewCmdCreateRole(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateRole(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewCreateRoleOptions(ioStreams) o := NewCreateRoleOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -27,6 +27,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/diff"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -133,7 +134,7 @@ func TestCreateRole(t *testing.T) {
for name, test := range tests { for name, test := range tests {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdCreateRole(tf, ioStreams) cmd := NewCmdCreateRole(tf, ioStreams)
cmd.Flags().Set("dry-run", "client") cmd.Flags().Set("dry-run", "client")
cmd.Flags().Set("output", "yaml") cmd.Flags().Set("output", "yaml")
@ -341,7 +342,7 @@ func TestValidate(t *testing.T) {
} }
for name, test := range tests { for name, test := range tests {
test.roleOptions.IOStreams = genericclioptions.NewTestIOStreamsDiscard() test.roleOptions.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
var err error var err error
test.roleOptions.Mapper, err = tf.ToRESTMapper() test.roleOptions.Mapper, err = tf.ToRESTMapper()
@ -645,7 +646,7 @@ func TestComplete(t *testing.T) {
} }
for name, test := range tests { for name, test := range tests {
cmd := NewCmdCreateRole(tf, genericclioptions.NewTestIOStreamsDiscard()) cmd := NewCmdCreateRole(tf, genericiooptions.NewTestIOStreamsDiscard())
cmd.Flags().Set("resource", test.resources) cmd.Flags().Set("resource", test.resources)
err := test.roleOptions.Complete(tf, cmd, test.params) err := test.roleOptions.Complete(tf, cmd, test.params)

View File

@ -27,6 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
rbacclientv1 "k8s.io/client-go/kubernetes/typed/rbac/v1" rbacclientv1 "k8s.io/client-go/kubernetes/typed/rbac/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -67,11 +68,11 @@ type RoleBindingOptions struct {
DryRunStrategy cmdutil.DryRunStrategy DryRunStrategy cmdutil.DryRunStrategy
ValidationDirective string ValidationDirective string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewRoleBindingOptions creates a new *RoleBindingOptions with sane defaults // NewRoleBindingOptions creates a new *RoleBindingOptions with sane defaults
func NewRoleBindingOptions(ioStreams genericclioptions.IOStreams) *RoleBindingOptions { func NewRoleBindingOptions(ioStreams genericiooptions.IOStreams) *RoleBindingOptions {
return &RoleBindingOptions{ return &RoleBindingOptions{
Users: []string{}, Users: []string{},
Groups: []string{}, Groups: []string{},
@ -82,7 +83,7 @@ func NewRoleBindingOptions(ioStreams genericclioptions.IOStreams) *RoleBindingOp
} }
// NewCmdCreateRoleBinding returns an initialized Command instance for 'create rolebinding' sub command // NewCmdCreateRoleBinding returns an initialized Command instance for 'create rolebinding' sub command
func NewCmdCreateRoleBinding(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateRoleBinding(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewRoleBindingOptions(ioStreams) o := NewRoleBindingOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1" corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -41,7 +42,7 @@ import (
// NewCmdCreateSecret groups subcommands to create various types of secrets. // NewCmdCreateSecret groups subcommands to create various types of secrets.
// This is the entry point of create_secret.go which will be called by create.go // This is the entry point of create_secret.go which will be called by create.go
func NewCmdCreateSecret(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateSecret(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "secret", Use: "secret",
Short: i18n.T("Create a secret using specified subcommand"), Short: i18n.T("Create a secret using specified subcommand"),
@ -114,11 +115,11 @@ type CreateSecretOptions struct {
DryRunStrategy cmdutil.DryRunStrategy DryRunStrategy cmdutil.DryRunStrategy
ValidationDirective string ValidationDirective string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewSecretOptions creates a new *CreateSecretOptions with default value // NewSecretOptions creates a new *CreateSecretOptions with default value
func NewSecretOptions(ioStreams genericclioptions.IOStreams) *CreateSecretOptions { func NewSecretOptions(ioStreams genericiooptions.IOStreams) *CreateSecretOptions {
return &CreateSecretOptions{ return &CreateSecretOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -126,7 +127,7 @@ func NewSecretOptions(ioStreams genericclioptions.IOStreams) *CreateSecretOption
} }
// NewCmdCreateSecretGeneric is a command to create generic secrets from files, directories, or literal values // NewCmdCreateSecretGeneric is a command to create generic secrets from files, directories, or literal values
func NewCmdCreateSecretGeneric(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateSecretGeneric(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewSecretOptions(ioStreams) o := NewSecretOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -27,6 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1" corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -111,11 +112,11 @@ type CreateSecretDockerRegistryOptions struct {
DryRunStrategy cmdutil.DryRunStrategy DryRunStrategy cmdutil.DryRunStrategy
ValidationDirective string ValidationDirective string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewSecretDockerRegistryOptions creates a new *CreateSecretDockerRegistryOptions with default value // NewSecretDockerRegistryOptions creates a new *CreateSecretDockerRegistryOptions with default value
func NewSecretDockerRegistryOptions(ioStreams genericclioptions.IOStreams) *CreateSecretDockerRegistryOptions { func NewSecretDockerRegistryOptions(ioStreams genericiooptions.IOStreams) *CreateSecretDockerRegistryOptions {
return &CreateSecretDockerRegistryOptions{ return &CreateSecretDockerRegistryOptions{
Server: "https://index.docker.io/v1/", Server: "https://index.docker.io/v1/",
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
@ -124,7 +125,7 @@ func NewSecretDockerRegistryOptions(ioStreams genericclioptions.IOStreams) *Crea
} }
// NewCmdCreateSecretDockerRegistry is a macro command for creating secrets to work with Docker registries // NewCmdCreateSecretDockerRegistry is a macro command for creating secrets to work with Docker registries
func NewCmdCreateSecretDockerRegistry(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateSecretDockerRegistry(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewSecretDockerRegistryOptions(ioStreams) o := NewSecretDockerRegistryOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -27,6 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1" corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -72,11 +73,11 @@ type CreateSecretTLSOptions struct {
DryRunStrategy cmdutil.DryRunStrategy DryRunStrategy cmdutil.DryRunStrategy
ValidationDirective string ValidationDirective string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewSecretTLSOptions creates a new *CreateSecretTLSOptions with default value // NewSecretTLSOptions creates a new *CreateSecretTLSOptions with default value
func NewSecretTLSOptions(ioStrems genericclioptions.IOStreams) *CreateSecretTLSOptions { func NewSecretTLSOptions(ioStrems genericiooptions.IOStreams) *CreateSecretTLSOptions {
return &CreateSecretTLSOptions{ return &CreateSecretTLSOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: ioStrems, IOStreams: ioStrems,
@ -84,7 +85,7 @@ func NewSecretTLSOptions(ioStrems genericclioptions.IOStreams) *CreateSecretTLSO
} }
// NewCmdCreateSecretTLS is a macro command for creating secrets to work with TLS client or server // NewCmdCreateSecretTLS is a macro command for creating secrets to work with TLS client or server
func NewCmdCreateSecretTLS(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateSecretTLS(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewSecretTLSOptions(ioStreams) o := NewSecretTLSOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1" corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -40,7 +41,7 @@ import (
) )
// NewCmdCreateService is a macro command to create a new service // NewCmdCreateService is a macro command to create a new service
func NewCmdCreateService(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateService(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "service", Use: "service",
Aliases: []string{"svc"}, Aliases: []string{"svc"},
@ -76,11 +77,11 @@ type ServiceOptions struct {
Client corev1client.CoreV1Interface Client corev1client.CoreV1Interface
DryRunStrategy cmdutil.DryRunStrategy DryRunStrategy cmdutil.DryRunStrategy
ValidationDirective string ValidationDirective string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewServiceOptions creates a ServiceOptions struct // NewServiceOptions creates a ServiceOptions struct
func NewServiceOptions(ioStreams genericclioptions.IOStreams, serviceType corev1.ServiceType) *ServiceOptions { func NewServiceOptions(ioStreams genericiooptions.IOStreams, serviceType corev1.ServiceType) *ServiceOptions {
return &ServiceOptions{ return &ServiceOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -239,7 +240,7 @@ var (
) )
// NewCmdCreateServiceClusterIP is a command to create a ClusterIP service // NewCmdCreateServiceClusterIP is a command to create a ClusterIP service
func NewCmdCreateServiceClusterIP(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateServiceClusterIP(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewServiceOptions(ioStreams, corev1.ServiceTypeClusterIP) o := NewServiceOptions(ioStreams, corev1.ServiceTypeClusterIP)
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -277,7 +278,7 @@ var (
) )
// NewCmdCreateServiceNodePort is a macro command for creating a NodePort service // NewCmdCreateServiceNodePort is a macro command for creating a NodePort service
func NewCmdCreateServiceNodePort(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateServiceNodePort(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewServiceOptions(ioStreams, corev1.ServiceTypeNodePort) o := NewServiceOptions(ioStreams, corev1.ServiceTypeNodePort)
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -314,7 +315,7 @@ var (
) )
// NewCmdCreateServiceLoadBalancer is a macro command for creating a LoadBalancer service // NewCmdCreateServiceLoadBalancer is a macro command for creating a LoadBalancer service
func NewCmdCreateServiceLoadBalancer(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateServiceLoadBalancer(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewServiceOptions(ioStreams, corev1.ServiceTypeLoadBalancer) o := NewServiceOptions(ioStreams, corev1.ServiceTypeLoadBalancer)
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -354,7 +355,7 @@ var (
) )
// NewCmdCreateServiceExternalName is a macro command for creating an ExternalName service // NewCmdCreateServiceExternalName is a macro command for creating an ExternalName service
func NewCmdCreateServiceExternalName(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateServiceExternalName(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewServiceOptions(ioStreams, corev1.ServiceTypeExternalName) o := NewServiceOptions(ioStreams, corev1.ServiceTypeExternalName)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -17,15 +17,16 @@ limitations under the License.
package create package create
import ( import (
"k8s.io/cli-runtime/pkg/genericclioptions" "testing"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
"testing"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality" apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/cli-runtime/pkg/genericiooptions"
) )
func TestCreateServices(t *testing.T) { func TestCreateServices(t *testing.T) {
@ -279,7 +280,7 @@ func TestCreateServiceWithNamespace(t *testing.T) {
tf.ClientConfigVal = &restclient.Config{} tf.ClientConfigVal = &restclient.Config{}
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdCreateServiceClusterIP(tf, ioStreams) cmd := NewCmdCreateServiceClusterIP(tf, ioStreams)
cmd.Flags().Set("dry-run", "client") cmd.Flags().Set("dry-run", "client")
cmd.Flags().Set("output", "jsonpath={.metadata.namespace}") cmd.Flags().Set("output", "jsonpath={.metadata.namespace}")

View File

@ -27,6 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
coreclient "k8s.io/client-go/kubernetes/typed/core/v1" coreclient "k8s.io/client-go/kubernetes/typed/core/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -62,11 +63,11 @@ type ServiceAccountOpts struct {
Mapper meta.RESTMapper Mapper meta.RESTMapper
Client *coreclient.CoreV1Client Client *coreclient.CoreV1Client
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewServiceAccountOpts creates a new *ServiceAccountOpts with sane defaults // NewServiceAccountOpts creates a new *ServiceAccountOpts with sane defaults
func NewServiceAccountOpts(ioStreams genericclioptions.IOStreams) *ServiceAccountOpts { func NewServiceAccountOpts(ioStreams genericiooptions.IOStreams) *ServiceAccountOpts {
return &ServiceAccountOpts{ return &ServiceAccountOpts{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -74,7 +75,7 @@ func NewServiceAccountOpts(ioStreams genericclioptions.IOStreams) *ServiceAccoun
} }
// NewCmdCreateServiceAccount is a macro command to create a new service account // NewCmdCreateServiceAccount is a macro command to create a new service account
func NewCmdCreateServiceAccount(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateServiceAccount(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewServiceAccountOpts(ioStreams) o := NewServiceAccountOpts(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -21,7 +21,7 @@ import (
"testing" "testing"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
@ -34,8 +34,8 @@ func TestExtraArgsFail(t *testing.T) {
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup() defer f.Cleanup()
c := NewCmdCreate(f, genericclioptions.NewTestIOStreamsDiscard()) c := NewCmdCreate(f, genericiooptions.NewTestIOStreamsDiscard())
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
options := NewCreateOptions(ioStreams) options := NewCreateOptions(ioStreams)
if options.Complete(f, c, []string{"rc"}) == nil { if options.Complete(f, c, []string{"rc"}) == nil {
t.Errorf("unexpected non-error") t.Errorf("unexpected non-error")
@ -66,7 +66,7 @@ func TestCreateObject(t *testing.T) {
}), }),
} }
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdCreate(tf, ioStreams) cmd := NewCmdCreate(tf, ioStreams)
cmd.Flags().Set("filename", "../../../testdata/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../testdata/redis-master-controller.yaml")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -103,7 +103,7 @@ func TestCreateMultipleObject(t *testing.T) {
}), }),
} }
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdCreate(tf, ioStreams) cmd := NewCmdCreate(tf, ioStreams)
cmd.Flags().Set("filename", "../../../testdata/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../testdata/redis-master-controller.yaml")
cmd.Flags().Set("filename", "../../../testdata/frontend-service.yaml") cmd.Flags().Set("filename", "../../../testdata/frontend-service.yaml")
@ -140,7 +140,7 @@ func TestCreateDirectory(t *testing.T) {
}), }),
} }
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdCreate(tf, ioStreams) cmd := NewCmdCreate(tf, ioStreams)
cmd.Flags().Set("filename", "../../../testdata/replace/legacy") cmd.Flags().Set("filename", "../../../testdata/replace/legacy")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")

View File

@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1" corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -66,7 +67,7 @@ type TokenOptions struct {
CoreClient corev1client.CoreV1Interface CoreClient corev1client.CoreV1Interface
// IOStreams are the output streams for the operation. Required. // IOStreams are the output streams for the operation. Required.
genericclioptions.IOStreams genericiooptions.IOStreams
} }
var ( var (
@ -98,7 +99,7 @@ var (
} }
) )
func NewTokenOpts(ioStreams genericclioptions.IOStreams) *TokenOptions { func NewTokenOpts(ioStreams genericiooptions.IOStreams) *TokenOptions {
return &TokenOptions{ return &TokenOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -106,7 +107,7 @@ func NewTokenOpts(ioStreams genericclioptions.IOStreams) *TokenOptions {
} }
// NewCmdCreateToken returns an initialized Command for 'create token' sub command // NewCmdCreateToken returns an initialized Command for 'create token' sub command
func NewCmdCreateToken(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCreateToken(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewTokenOpts(ioStreams) o := NewTokenOpts(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -33,7 +33,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -299,7 +299,7 @@ status:
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, stdout, _ := genericclioptions.NewTestIOStreams() ioStreams, _, stdout, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdCreateToken(tf, ioStreams) cmd := NewCmdCreateToken(tf, ioStreams)
if test.output != "" { if test.output != "" {
cmd.Flags().Set("output", test.output) cmd.Flags().Set("output", test.output)

View File

@ -38,6 +38,7 @@ import (
"k8s.io/apimachinery/pkg/util/strategicpatch" "k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
@ -135,14 +136,14 @@ type DebugOptions struct {
podClient corev1client.CoreV1Interface podClient corev1client.CoreV1Interface
Builder *resource.Builder Builder *resource.Builder
genericclioptions.IOStreams genericiooptions.IOStreams
WarningPrinter *printers.WarningPrinter WarningPrinter *printers.WarningPrinter
resource.FilenameOptions resource.FilenameOptions
} }
// NewDebugOptions returns a DebugOptions initialized with default values. // NewDebugOptions returns a DebugOptions initialized with default values.
func NewDebugOptions(streams genericclioptions.IOStreams) *DebugOptions { func NewDebugOptions(streams genericiooptions.IOStreams) *DebugOptions {
return &DebugOptions{ return &DebugOptions{
Args: []string{}, Args: []string{},
IOStreams: streams, IOStreams: streams,
@ -152,7 +153,7 @@ func NewDebugOptions(streams genericclioptions.IOStreams) *DebugOptions {
} }
// NewCmdDebug returns a cobra command that runs kubectl debug. // NewCmdDebug returns a cobra command that runs kubectl debug.
func NewCmdDebug(restClientGetter genericclioptions.RESTClientGetter, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdDebug(restClientGetter genericclioptions.RESTClientGetter, streams genericiooptions.IOStreams) *cobra.Command {
o := NewDebugOptions(streams) o := NewDebugOptions(streams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -28,7 +28,7 @@ import (
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
"k8s.io/utils/pointer" "k8s.io/utils/pointer"
) )
@ -316,7 +316,7 @@ func TestGenerateDebugContainer(t *testing.T) {
}, },
} { } {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
tc.opts.IOStreams = genericclioptions.NewTestIOStreamsDiscard() tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
suffixCounter = 0 suffixCounter = 0
if tc.pod == nil { if tc.pod == nil {
@ -1334,7 +1334,7 @@ func TestGeneratePodCopyWithDebugContainer(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err) t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
} }
tc.opts.IOStreams = genericclioptions.NewTestIOStreamsDiscard() tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
suffixCounter = 0 suffixCounter = 0
if tc.havePod == nil { if tc.havePod == nil {
@ -1716,7 +1716,7 @@ func TestGenerateNodeDebugPod(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err) t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
} }
tc.opts.IOStreams = genericclioptions.NewTestIOStreamsDiscard() tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
suffixCounter = 0 suffixCounter = 0
pod, err := tc.opts.generateNodeDebugPod(tc.node) pod, err := tc.opts.generateNodeDebugPod(tc.node)
@ -1732,7 +1732,7 @@ func TestGenerateNodeDebugPod(t *testing.T) {
func TestCompleteAndValidate(t *testing.T) { func TestCompleteAndValidate(t *testing.T) {
tf := cmdtesting.NewTestFactory().WithNamespace("test") tf := cmdtesting.NewTestFactory().WithNamespace("test")
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
cmpFilter := cmp.FilterPath(func(p cmp.Path) bool { cmpFilter := cmp.FilterPath(func(p cmp.Path) bool {
switch p.String() { switch p.String() {
// IOStreams contains unexported fields // IOStreams contains unexported fields

View File

@ -30,6 +30,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/dynamic" "k8s.io/client-go/dynamic"
@ -132,11 +133,11 @@ type DeleteOptions struct {
Mapper meta.RESTMapper Mapper meta.RESTMapper
Result *resource.Result Result *resource.Result
genericclioptions.IOStreams genericiooptions.IOStreams
WarningPrinter *printers.WarningPrinter WarningPrinter *printers.WarningPrinter
} }
func NewCmdDelete(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdDelete(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
deleteFlags := NewDeleteCommandFlags("containing the resource to delete.") deleteFlags := NewDeleteCommandFlags("containing the resource to delete.")
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -25,6 +25,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/dynamic" "k8s.io/client-go/dynamic"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
) )
@ -49,7 +50,7 @@ type DeleteFlags struct {
Raw *string Raw *string
} }
func (f *DeleteFlags) ToOptions(dynamicClient dynamic.Interface, streams genericclioptions.IOStreams) (*DeleteOptions, error) { func (f *DeleteFlags) ToOptions(dynamicClient dynamic.Interface, streams genericiooptions.IOStreams) (*DeleteOptions, error) {
options := &DeleteOptions{ options := &DeleteOptions{
DynamicClient: dynamicClient, DynamicClient: dynamicClient,
IOStreams: streams, IOStreams: streams,
@ -226,7 +227,7 @@ func NewDeleteFlags(usage string) *DeleteFlags {
} }
} }
func parseCascadingFlag(streams genericclioptions.IOStreams, cascadingFlag string) (metav1.DeletionPropagation, error) { func parseCascadingFlag(streams genericiooptions.IOStreams, cascadingFlag string) (metav1.DeletionPropagation, error) {
boolValue, err := strconv.ParseBool(cascadingFlag) boolValue, err := strconv.ParseBool(cascadingFlag)
// The flag is not a boolean // The flag is not a boolean
if err != nil { if err != nil {

View File

@ -29,7 +29,7 @@ import (
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
@ -77,7 +77,7 @@ func TestDeleteObjectByTuple(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
@ -88,7 +88,7 @@ func TestDeleteObjectByTuple(t *testing.T) {
} }
// Test cascading delete of object without client-side reaper doesn't make GET requests // Test cascading delete of object without client-side reaper doesn't make GET requests
streams, _, buf, _ = genericclioptions.NewTestIOStreams() streams, _, buf, _ = genericiooptions.NewTestIOStreams()
cmd = NewCmdDelete(tf, streams) cmd = NewCmdDelete(tf, streams)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -139,7 +139,7 @@ func TestCascadingStrategy(t *testing.T) {
// DeleteOptions.PropagationPolicy should be Background, when cascading strategy is empty (default). // DeleteOptions.PropagationPolicy should be Background, when cascading strategy is empty (default).
backgroundPolicy := metav1.DeletePropagationBackground backgroundPolicy := metav1.DeletePropagationBackground
policy = &backgroundPolicy policy = &backgroundPolicy
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
@ -151,7 +151,7 @@ func TestCascadingStrategy(t *testing.T) {
// DeleteOptions.PropagationPolicy should be Foreground, when cascading strategy is foreground. // DeleteOptions.PropagationPolicy should be Foreground, when cascading strategy is foreground.
foregroundPolicy := metav1.DeletePropagationForeground foregroundPolicy := metav1.DeletePropagationForeground
policy = &foregroundPolicy policy = &foregroundPolicy
streams, _, buf, _ = genericclioptions.NewTestIOStreams() streams, _, buf, _ = genericiooptions.NewTestIOStreams()
cmd = NewCmdDelete(tf, streams) cmd = NewCmdDelete(tf, streams)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
cmd.Flags().Set("cascade", "foreground") cmd.Flags().Set("cascade", "foreground")
@ -164,7 +164,7 @@ func TestCascadingStrategy(t *testing.T) {
// Test that delete options should be set to orphan when cascading strategy is orphan. // Test that delete options should be set to orphan when cascading strategy is orphan.
orphanPolicy := metav1.DeletePropagationOrphan orphanPolicy := metav1.DeletePropagationOrphan
policy = &orphanPolicy policy = &orphanPolicy
streams, _, buf, _ = genericclioptions.NewTestIOStreams() streams, _, buf, _ = genericiooptions.NewTestIOStreams()
cmd = NewCmdDelete(tf, streams) cmd = NewCmdDelete(tf, streams)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
cmd.Flags().Set("cascade", "orphan") cmd.Flags().Set("cascade", "orphan")
@ -206,7 +206,7 @@ func TestDeleteNamedObject(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
@ -217,7 +217,7 @@ func TestDeleteNamedObject(t *testing.T) {
} }
// Test cascading delete of object without client-side reaper doesn't make GET requests // Test cascading delete of object without client-side reaper doesn't make GET requests
streams, _, buf, _ = genericclioptions.NewTestIOStreams() streams, _, buf, _ = genericiooptions.NewTestIOStreams()
cmd = NewCmdDelete(tf, streams) cmd = NewCmdDelete(tf, streams)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
@ -250,7 +250,7 @@ func TestDeleteObject(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
cmd.Flags().Set("filename", "../../../testdata/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../testdata/redis-master-controller.yaml")
cmd.Flags().Set("cascade", "false") cmd.Flags().Set("cascade", "false")
@ -386,7 +386,7 @@ func TestGracePeriodScenarios(t *testing.T) {
} }
// Test the command using the flags specified in the test case // Test the command using the flags specified in the test case
streams, _, out, errOut := genericclioptions.NewTestIOStreams() streams, _, out, errOut := genericiooptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
if test.forceFlag { if test.forceFlag {
@ -442,7 +442,7 @@ func TestDeleteObjectNotFound(t *testing.T) {
GracePeriod: -1, GracePeriod: -1,
CascadingStrategy: metav1.DeletePropagationOrphan, CascadingStrategy: metav1.DeletePropagationOrphan,
Output: "name", Output: "name",
IOStreams: genericclioptions.NewTestIOStreamsDiscard(), IOStreams: genericiooptions.NewTestIOStreamsDiscard(),
} }
err := options.Complete(tf, []string{}, fakecmd()) err := options.Complete(tf, []string{}, fakecmd())
if err != nil { if err != nil {
@ -471,7 +471,7 @@ func TestDeleteObjectIgnoreNotFound(t *testing.T) {
} }
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
cmd.Flags().Set("filename", "../../../testdata/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../testdata/redis-master-controller.yaml")
@ -522,7 +522,7 @@ func TestDeleteAllNotFound(t *testing.T) {
DeleteAll: true, DeleteAll: true,
IgnoreNotFound: false, IgnoreNotFound: false,
Output: "name", Output: "name",
IOStreams: genericclioptions.NewTestIOStreamsDiscard(), IOStreams: genericiooptions.NewTestIOStreamsDiscard(),
} }
err := options.Complete(tf, []string{"services"}, fakecmd()) err := options.Complete(tf, []string{"services"}, fakecmd())
if err != nil { if err != nil {
@ -563,7 +563,7 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) {
} }
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
cmd.Flags().Set("all", "true") cmd.Flags().Set("all", "true")
@ -599,7 +599,7 @@ func TestDeleteMultipleObject(t *testing.T) {
} }
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
cmd.Flags().Set("filename", "../../../testdata/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../testdata/redis-master-controller.yaml")
@ -636,7 +636,7 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) {
} }
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
options := &DeleteOptions{ options := &DeleteOptions{
FilenameOptions: resource.FilenameOptions{ FilenameOptions: resource.FilenameOptions{
@ -688,7 +688,7 @@ func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) {
} }
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
@ -721,7 +721,7 @@ func TestDeleteDirectory(t *testing.T) {
} }
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
cmd.Flags().Set("filename", "../../../testdata/replace/legacy") cmd.Flags().Set("filename", "../../../testdata/replace/legacy")
@ -767,7 +767,7 @@ func TestDeleteMultipleSelector(t *testing.T) {
} }
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
cmd.Flags().Set("selector", "a=b") cmd.Flags().Set("selector", "a=b")
@ -811,7 +811,7 @@ func TestResourceErrors(t *testing.T) {
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
options := &DeleteOptions{ options := &DeleteOptions{
FilenameOptions: resource.FilenameOptions{}, FilenameOptions: resource.FilenameOptions{},
GracePeriod: -1, GracePeriod: -1,

View File

@ -26,7 +26,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/describe" "k8s.io/kubectl/pkg/describe"
@ -77,11 +77,11 @@ type DescribeFlags struct {
AllNamespaces bool AllNamespaces bool
FilenameOptions *resource.FilenameOptions FilenameOptions *resource.FilenameOptions
DescriberSettings *describe.DescriberSettings DescriberSettings *describe.DescriberSettings
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewDescribeFlags returns a default DescribeFlags // NewDescribeFlags returns a default DescribeFlags
func NewDescribeFlags(f cmdutil.Factory, streams genericclioptions.IOStreams) *DescribeFlags { func NewDescribeFlags(f cmdutil.Factory, streams genericiooptions.IOStreams) *DescribeFlags {
return &DescribeFlags{ return &DescribeFlags{
Factory: f, Factory: f,
FilenameOptions: &resource.FilenameOptions{}, FilenameOptions: &resource.FilenameOptions{},
@ -141,7 +141,7 @@ func (flags *DescribeFlags) ToOptions(parent string, args []string) (*DescribeOp
return o, nil return o, nil
} }
func NewCmdDescribe(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdDescribe(parent string, f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
flags := NewDescribeFlags(f, streams) flags := NewDescribeFlags(f, streams)
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -290,5 +290,5 @@ type DescribeOptions struct {
DescriberSettings *describe.DescriberSettings DescriberSettings *describe.DescriberSettings
FilenameOptions *resource.FilenameOptions FilenameOptions *resource.FilenameOptions
genericclioptions.IOStreams genericiooptions.IOStreams
} }

View File

@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
@ -49,7 +50,7 @@ func TestDescribeUnknownSchemaObject(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, cmdtesting.NewInternalType("", "", "foo"))}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, cmdtesting.NewInternalType("", "", "foo"))},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDescribe("kubectl", tf, streams) cmd := NewCmdDescribe("kubectl", tf, streams)
cmd.Run(cmd, []string{"type", "foo"}) cmd.Run(cmd, []string{"type", "foo"})
@ -82,7 +83,7 @@ func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) {
} }
tf.WithNamespace("non-default") tf.WithNamespace("non-default")
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDescribe("kubectl", tf, streams) cmd := NewCmdDescribe("kubectl", tf, streams)
cmd.Run(cmd, []string{"namespacedtype", "foo"}) cmd.Run(cmd, []string{"namespacedtype", "foo"})
@ -122,7 +123,7 @@ func TestDescribeObject(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDescribe("kubectl", tf, streams) cmd := NewCmdDescribe("kubectl", tf, streams)
cmd.Flags().Set("filename", "../../../testdata/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../testdata/redis-master-controller.yaml")
@ -155,7 +156,7 @@ func TestDescribeListObjects(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, pods)}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, pods)},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDescribe("kubectl", tf, streams) cmd := NewCmdDescribe("kubectl", tf, streams)
cmd.Run(cmd, []string{"pods"}) cmd.Run(cmd, []string{"pods"})
@ -182,7 +183,7 @@ func TestDescribeObjectShowEvents(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, pods)}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, pods)},
} }
cmd := NewCmdDescribe("kubectl", tf, genericclioptions.NewTestIOStreamsDiscard()) cmd := NewCmdDescribe("kubectl", tf, genericiooptions.NewTestIOStreamsDiscard())
cmd.Flags().Set("show-events", "true") cmd.Flags().Set("show-events", "true")
cmd.Run(cmd, []string{"pods"}) cmd.Run(cmd, []string{"pods"})
if d.Settings.ShowEvents != true { if d.Settings.ShowEvents != true {
@ -208,7 +209,7 @@ func TestDescribeObjectSkipEvents(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, pods)}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, pods)},
} }
cmd := NewCmdDescribe("kubectl", tf, genericclioptions.NewTestIOStreamsDiscard()) cmd := NewCmdDescribe("kubectl", tf, genericiooptions.NewTestIOStreamsDiscard())
cmd.Flags().Set("show-events", "false") cmd.Flags().Set("show-events", "false")
cmd.Run(cmd, []string{"pods"}) cmd.Run(cmd, []string{"pods"})
if d.Settings.ShowEvents != false { if d.Settings.ShowEvents != false {
@ -234,7 +235,7 @@ func TestDescribeObjectChunkSize(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, pods)}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, pods)},
} }
cmd := NewCmdDescribe("kubectl", tf, genericclioptions.NewTestIOStreamsDiscard()) cmd := NewCmdDescribe("kubectl", tf, genericiooptions.NewTestIOStreamsDiscard())
cmd.Flags().Set("chunk-size", "100") cmd.Flags().Set("chunk-size", "100")
cmd.Run(cmd, []string{"pods"}) cmd.Run(cmd, []string{"pods"})
if d.Settings.ChunkSize != 100 { if d.Settings.ChunkSize != 100 {
@ -246,7 +247,7 @@ func TestDescribeHelpMessage(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup() defer tf.Cleanup()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdDescribe("kubectl", tf, streams) cmd := NewCmdDescribe("kubectl", tf, streams)
cmd.SetArgs([]string{"-h"}) cmd.SetArgs([]string{"-h"})
@ -306,7 +307,7 @@ func TestDescribeNoResourcesFound(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, pods)}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, pods)},
} }
streams, _, buf, errbuf := genericclioptions.NewTestIOStreams() streams, _, buf, errbuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdDescribe("kubectl", tf, streams) cmd := NewCmdDescribe("kubectl", tf, streams)
for name, value := range testCase.flags { for name, value := range testCase.flags {

View File

@ -32,7 +32,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/dynamic" "k8s.io/client-go/dynamic"
"k8s.io/klog/v2" "k8s.io/klog/v2"
@ -119,7 +119,7 @@ type DiffOptions struct {
tracker *tracker tracker *tracker
} }
func NewDiffOptions(ioStreams genericclioptions.IOStreams) *DiffOptions { func NewDiffOptions(ioStreams genericiooptions.IOStreams) *DiffOptions {
return &DiffOptions{ return &DiffOptions{
Diff: &DiffProgram{ Diff: &DiffProgram{
Exec: exec.New(), Exec: exec.New(),
@ -128,7 +128,7 @@ func NewDiffOptions(ioStreams genericclioptions.IOStreams) *DiffOptions {
} }
} }
func NewCmdDiff(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdDiff(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
options := NewDiffOptions(streams) options := NewDiffOptions(streams)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "diff -f FILENAME", Use: "diff -f FILENAME",
@ -179,7 +179,7 @@ func NewCmdDiff(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.C
// program. By default, `diff(1)` will be used. // program. By default, `diff(1)` will be used.
type DiffProgram struct { type DiffProgram struct {
Exec exec.Interface Exec exec.Interface
genericclioptions.IOStreams genericiooptions.IOStreams
} }
func (d *DiffProgram) getCommand(args ...string) (string, exec.Cmd) { func (d *DiffProgram) getCommand(args ...string) (string, exec.Cmd) {
@ -326,7 +326,7 @@ type InfoObject struct {
ServerSideApply bool ServerSideApply bool
FieldManager string FieldManager string
ForceConflicts bool ForceConflicts bool
genericclioptions.IOStreams genericiooptions.IOStreams
} }
var _ Object = &InfoObject{} var _ Object = &InfoObject{}

View File

@ -29,7 +29,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/utils/exec" "k8s.io/utils/exec"
) )
@ -71,7 +71,7 @@ func TestDiffProgram(t *testing.T) {
for i, c := range externalDiffCommands { for i, c := range externalDiffCommands {
os.Setenv("KUBECTL_EXTERNAL_DIFF", c) os.Setenv("KUBECTL_EXTERNAL_DIFF", c)
streams, _, stdout, _ := genericclioptions.NewTestIOStreams() streams, _, stdout, _ := genericiooptions.NewTestIOStreams()
diff := DiffProgram{ diff := DiffProgram{
IOStreams: streams, IOStreams: streams,
Exec: exec.New(), Exec: exec.New(),

View File

@ -28,6 +28,7 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -48,7 +49,7 @@ type DrainCmdOptions struct {
drainer *drain.Helper drainer *drain.Helper
nodeInfos []*resource.Info nodeInfos []*resource.Info
genericclioptions.IOStreams genericiooptions.IOStreams
WarningPrinter *printers.WarningPrinter WarningPrinter *printers.WarningPrinter
} }
@ -61,7 +62,7 @@ var (
kubectl cordon foo`)) kubectl cordon foo`))
) )
func NewCmdCordon(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdCordon(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewDrainCmdOptions(f, ioStreams) o := NewDrainCmdOptions(f, ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -90,7 +91,7 @@ var (
kubectl uncordon foo`)) kubectl uncordon foo`))
) )
func NewCmdUncordon(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdUncordon(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewDrainCmdOptions(f, ioStreams) o := NewDrainCmdOptions(f, ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -144,7 +145,7 @@ var (
kubectl drain foo --grace-period=900`)) kubectl drain foo --grace-period=900`))
) )
func NewDrainCmdOptions(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *DrainCmdOptions { func NewDrainCmdOptions(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *DrainCmdOptions {
o := &DrainCmdOptions{ o := &DrainCmdOptions{
PrintFlags: genericclioptions.NewPrintFlags("drained").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("drained").WithTypeSetter(scheme.Scheme),
IOStreams: ioStreams, IOStreams: ioStreams,
@ -176,7 +177,7 @@ func (o *DrainCmdOptions) onPodDeletedOrEvicted(pod *corev1.Pod, usingEviction b
} }
} }
func NewCmdDrain(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdDrain(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewDrainCmdOptions(f, ioStreams) o := NewDrainCmdOptions(f, ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -29,8 +29,6 @@ import (
"time" "time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
appsv1 "k8s.io/api/apps/v1" appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1" batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
@ -38,6 +36,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/strategicpatch" "k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -75,7 +74,7 @@ func TestCordon(t *testing.T) {
description string description string
node *corev1.Node node *corev1.Node
expected *corev1.Node expected *corev1.Node
cmd func(cmdutil.Factory, genericclioptions.IOStreams) *cobra.Command cmd func(cmdutil.Factory, genericiooptions.IOStreams) *cobra.Command
arg string arg string
expectFatal bool expectFatal bool
}{ }{
@ -211,7 +210,7 @@ func TestCordon(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
cmd := test.cmd(tf, ioStreams) cmd := test.cmd(tf, ioStreams)
var recovered interface{} var recovered interface{}
@ -873,7 +872,7 @@ func TestDrain(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, outBuf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, outBuf, errBuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdDrain(tf, ioStreams) cmd := NewCmdDrain(tf, ioStreams)
var recovered interface{} var recovered interface{}

View File

@ -19,7 +19,8 @@ package edit
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/cmd/util/editor" "k8s.io/kubectl/pkg/cmd/util/editor"
"k8s.io/kubectl/pkg/util/completion" "k8s.io/kubectl/pkg/util/completion"
@ -70,7 +71,7 @@ var (
) )
// NewCmdEdit creates the `edit` command // NewCmdEdit creates the `edit` command
func NewCmdEdit(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdEdit(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := editor.NewEditOptions(editor.NormalEditMode, ioStreams) o := editor.NewEditOptions(editor.NormalEditMode, ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "edit (RESOURCE/NAME | -f FILENAME)", Use: "edit (RESOURCE/NAME | -f FILENAME)",

View File

@ -34,7 +34,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
"k8s.io/kubectl/pkg/cmd/apply" "k8s.io/kubectl/pkg/cmd/apply"
@ -227,7 +227,7 @@ func TestEdit(t *testing.T) {
} }
tf.WithNamespace(testcase.Namespace) tf.WithNamespace(testcase.Namespace)
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericiooptions.NewTestIOStreams()
var cmd *cobra.Command var cmd *cobra.Command
switch testcase.Mode { switch testcase.Mode {

View File

@ -35,6 +35,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
runtimeresource "k8s.io/cli-runtime/pkg/resource" runtimeresource "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
@ -84,11 +85,11 @@ type EventsFlags struct {
ForObject string ForObject string
FilterTypes []string FilterTypes []string
ChunkSize int64 ChunkSize int64
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewEventsFlags returns a default EventsFlags // NewEventsFlags returns a default EventsFlags
func NewEventsFlags(restClientGetter genericclioptions.RESTClientGetter, streams genericclioptions.IOStreams) *EventsFlags { func NewEventsFlags(restClientGetter genericclioptions.RESTClientGetter, streams genericiooptions.IOStreams) *EventsFlags {
return &EventsFlags{ return &EventsFlags{
RESTClientGetter: restClientGetter, RESTClientGetter: restClientGetter,
PrintFlags: genericclioptions.NewPrintFlags("events").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("events").WithTypeSetter(scheme.Scheme),
@ -112,11 +113,11 @@ type EventsOptions struct {
PrintObj printers.ResourcePrinterFunc PrintObj printers.ResourcePrinterFunc
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewCmdEvents creates a new events command // NewCmdEvents creates a new events command
func NewCmdEvents(restClientGetter genericclioptions.RESTClientGetter, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdEvents(restClientGetter genericclioptions.RESTClientGetter, streams genericiooptions.IOStreams) *cobra.Command {
flags := NewEventsFlags(restClientGetter, streams) flags := NewEventsFlags(restClientGetter, streams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -18,17 +18,17 @@ package events
import ( import (
"io" "io"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
"net/http" "net/http"
"testing" "testing"
"time" "time"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/kubernetes/scheme"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
) )
@ -108,7 +108,7 @@ func getFakeEvents() *corev1.EventList {
func TestEventIsSorted(t *testing.T) { func TestEventIsSorted(t *testing.T) {
codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
clientset, err := kubernetes.NewForConfig(cmdtesting.DefaultClientConfig()) clientset, err := kubernetes.NewForConfig(cmdtesting.DefaultClientConfig())
if err != err { if err != err {
t.Fatal(err) t.Fatal(err)
@ -146,7 +146,7 @@ otherfoo 15m (x3 over 25m) Normal ScalingReplicaSet Deployment/bar S
func TestEventNoHeaders(t *testing.T) { func TestEventNoHeaders(t *testing.T) {
codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
clientset, err := kubernetes.NewForConfig(cmdtesting.DefaultClientConfig()) clientset, err := kubernetes.NewForConfig(cmdtesting.DefaultClientConfig())
if err != err { if err != err {
t.Fatal(err) t.Fatal(err)
@ -183,7 +183,7 @@ otherfoo 15m (x3 over 25m) Normal ScalingReplicaSet Deployment/bar Sc
func TestEventFiltered(t *testing.T) { func TestEventFiltered(t *testing.T) {
codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
clientset, err := kubernetes.NewForConfig(cmdtesting.DefaultClientConfig()) clientset, err := kubernetes.NewForConfig(cmdtesting.DefaultClientConfig())
if err != err { if err != err {
t.Fatal(err) t.Fatal(err)

View File

@ -28,6 +28,7 @@ import (
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
coreclient "k8s.io/client-go/kubernetes/typed/core/v1" coreclient "k8s.io/client-go/kubernetes/typed/core/v1"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
@ -76,7 +77,7 @@ const (
defaultPodExecTimeout = 60 * time.Second defaultPodExecTimeout = 60 * time.Second
) )
func NewCmdExec(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdExec(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
options := &ExecOptions{ options := &ExecOptions{
StreamOptions: StreamOptions{ StreamOptions: StreamOptions{
IOStreams: streams, IOStreams: streams,
@ -143,7 +144,7 @@ type StreamOptions struct {
// InterruptParent, if set, is used to handle interrupts while attached // InterruptParent, if set, is used to handle interrupts while attached
InterruptParent *interrupt.Handler InterruptParent *interrupt.Handler
genericclioptions.IOStreams genericiooptions.IOStreams
// for testing // for testing
overrideStreams func() (io.ReadCloser, io.Writer, io.Writer) overrideStreams func() (io.ReadCloser, io.Writer, io.Writer)

View File

@ -29,7 +29,7 @@ import (
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
"k8s.io/client-go/tools/remotecommand" "k8s.io/client-go/tools/remotecommand"
@ -142,7 +142,7 @@ func TestPodAndContainer(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
cmd := NewCmdExec(tf, genericclioptions.NewTestIOStreamsDiscard()) cmd := NewCmdExec(tf, genericiooptions.NewTestIOStreamsDiscard())
options := test.p options := test.p
options.ErrOut = bytes.NewBuffer([]byte{}) options.ErrOut = bytes.NewBuffer([]byte{})
options.Out = bytes.NewBuffer([]byte{}) options.Out = bytes.NewBuffer([]byte{})
@ -235,11 +235,11 @@ func TestExec(t *testing.T) {
StreamOptions: StreamOptions{ StreamOptions: StreamOptions{
PodName: "foo", PodName: "foo",
ContainerName: "bar", ContainerName: "bar",
IOStreams: genericclioptions.NewTestIOStreamsDiscard(), IOStreams: genericiooptions.NewTestIOStreamsDiscard(),
}, },
Executor: ex, Executor: ex,
} }
cmd := NewCmdExec(tf, genericclioptions.NewTestIOStreamsDiscard()) cmd := NewCmdExec(tf, genericiooptions.NewTestIOStreamsDiscard())
args := []string{"pod/foo", "command"} args := []string{"pod/foo", "command"}
if err := params.Complete(tf, cmd, args, -1); err != nil { if err := params.Complete(tf, cmd, args, -1); err != nil {
t.Fatal(err) t.Fatal(err)
@ -290,7 +290,7 @@ func execPod() *corev1.Pod {
} }
func TestSetupTTY(t *testing.T) { func TestSetupTTY(t *testing.T) {
streams, _, _, stderr := genericclioptions.NewTestIOStreams() streams, _, _, stderr := genericiooptions.NewTestIOStreams()
// test 1 - don't attach stdin // test 1 - don't attach stdin
o := &StreamOptions{ o := &StreamOptions{

View File

@ -23,7 +23,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
openapiclient "k8s.io/client-go/openapi" openapiclient "k8s.io/client-go/openapi"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/explain" "k8s.io/kubectl/pkg/explain"
@ -57,7 +57,7 @@ var (
) )
type ExplainOptions struct { type ExplainOptions struct {
genericclioptions.IOStreams genericiooptions.IOStreams
CmdParent string CmdParent string
APIVersion string APIVersion string
@ -76,7 +76,7 @@ type ExplainOptions struct {
OpenAPIV3Client openapiclient.Client OpenAPIV3Client openapiclient.Client
} }
func NewExplainOptions(parent string, streams genericclioptions.IOStreams) *ExplainOptions { func NewExplainOptions(parent string, streams genericiooptions.IOStreams) *ExplainOptions {
return &ExplainOptions{ return &ExplainOptions{
IOStreams: streams, IOStreams: streams,
CmdParent: parent, CmdParent: parent,
@ -85,7 +85,7 @@ func NewExplainOptions(parent string, streams genericclioptions.IOStreams) *Expl
} }
// NewCmdExplain returns a cobra command for swagger docs // NewCmdExplain returns a cobra command for swagger docs
func NewCmdExplain(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdExplain(parent string, f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
o := NewExplainOptions(parent, streams) o := NewExplainOptions(parent, streams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -24,7 +24,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
sptest "k8s.io/apimachinery/pkg/util/strategicpatch/testing" sptest "k8s.io/apimachinery/pkg/util/strategicpatch/testing"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/discovery" "k8s.io/client-go/discovery"
openapiclient "k8s.io/client-go/openapi" openapiclient "k8s.io/client-go/openapi"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
@ -57,8 +57,8 @@ func TestExplainInvalidArgs(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup() defer tf.Cleanup()
opts := explain.NewExplainOptions("kubectl", genericclioptions.NewTestIOStreamsDiscard()) opts := explain.NewExplainOptions("kubectl", genericiooptions.NewTestIOStreamsDiscard())
cmd := explain.NewCmdExplain("kubectl", tf, genericclioptions.NewTestIOStreamsDiscard()) cmd := explain.NewCmdExplain("kubectl", tf, genericiooptions.NewTestIOStreamsDiscard())
err := opts.Complete(tf, cmd, []string{}) err := opts.Complete(tf, cmd, []string{})
if err != nil { if err != nil {
t.Fatalf("unexpected error %v", err) t.Fatalf("unexpected error %v", err)
@ -84,8 +84,8 @@ func TestExplainNotExistResource(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup() defer tf.Cleanup()
opts := explain.NewExplainOptions("kubectl", genericclioptions.NewTestIOStreamsDiscard()) opts := explain.NewExplainOptions("kubectl", genericiooptions.NewTestIOStreamsDiscard())
cmd := explain.NewCmdExplain("kubectl", tf, genericclioptions.NewTestIOStreamsDiscard()) cmd := explain.NewCmdExplain("kubectl", tf, genericiooptions.NewTestIOStreamsDiscard())
err := opts.Complete(tf, cmd, []string{"foo"}) err := opts.Complete(tf, cmd, []string{"foo"})
if err != nil { if err != nil {
t.Fatalf("unexpected error %v", err) t.Fatalf("unexpected error %v", err)
@ -208,7 +208,7 @@ func runExplainTestCases(t *testing.T, cases []explainTestCase) {
tf.OpenAPISchemaFunc = FakeOpenAPISchema.OpenAPISchemaFn tf.OpenAPISchemaFunc = FakeOpenAPISchema.OpenAPISchemaFn
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
type catchFatal error type catchFatal error

View File

@ -34,6 +34,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -131,12 +132,12 @@ type ExposeServiceOptions struct {
ClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error) ClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error)
Recorder genericclioptions.Recorder Recorder genericclioptions.Recorder
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewExposeServiceOptions creates a new ExposeServiceOptions and return a pointer to the // NewExposeServiceOptions creates a new ExposeServiceOptions and return a pointer to the
// struct // struct
func NewExposeServiceOptions(ioStreams genericclioptions.IOStreams) *ExposeServiceOptions { func NewExposeServiceOptions(ioStreams genericiooptions.IOStreams) *ExposeServiceOptions {
return &ExposeServiceOptions{ return &ExposeServiceOptions{
RecordFlags: genericclioptions.NewRecordFlags(), RecordFlags: genericclioptions.NewRecordFlags(),
PrintFlags: genericclioptions.NewPrintFlags("exposed").WithTypeSetter(scheme.Scheme), PrintFlags: genericclioptions.NewPrintFlags("exposed").WithTypeSetter(scheme.Scheme),
@ -147,7 +148,7 @@ func NewExposeServiceOptions(ioStreams genericclioptions.IOStreams) *ExposeServi
} }
// NewCmdExposeService is a command to expose the service from user's input // NewCmdExposeService is a command to expose the service from user's input
func NewCmdExposeService(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdExposeService(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
o := NewExposeServiceOptions(streams) o := NewExposeServiceOptions(streams)
validArgs := []string{} validArgs := []string{}

View File

@ -28,7 +28,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
"k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/scheme"
@ -658,7 +658,7 @@ func TestRunExposeService(t *testing.T) {
}), }),
} }
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdExposeService(tf, ioStreams) cmd := NewCmdExposeService(tf, ioStreams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -834,7 +834,7 @@ status:
}), }),
} }
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdExposeService(tf, ioStreams) cmd := NewCmdExposeService(tf, ioStreams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.Flags().Set("protocol", "UDP") cmd.Flags().Set("protocol", "UDP")

View File

@ -36,7 +36,7 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
kubernetesscheme "k8s.io/client-go/kubernetes/scheme" kubernetesscheme "k8s.io/client-go/kubernetes/scheme"
@ -82,7 +82,7 @@ type GetOptions struct {
NoHeaders bool NoHeaders bool
IgnoreNotFound bool IgnoreNotFound bool
genericclioptions.IOStreams genericiooptions.IOStreams
} }
var ( var (
@ -142,7 +142,7 @@ const (
var supportedSubresources = []string{"status", "scale"} var supportedSubresources = []string{"status", "scale"}
// NewGetOptions returns a GetOptions with default chunk size 500. // NewGetOptions returns a GetOptions with default chunk size 500.
func NewGetOptions(parent string, streams genericclioptions.IOStreams) *GetOptions { func NewGetOptions(parent string, streams genericiooptions.IOStreams) *GetOptions {
return &GetOptions{ return &GetOptions{
PrintFlags: NewGetPrintFlags(), PrintFlags: NewGetPrintFlags(),
CmdParent: parent, CmdParent: parent,
@ -155,7 +155,7 @@ func NewGetOptions(parent string, streams genericclioptions.IOStreams) *GetOptio
// 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(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdGet(parent string, f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
o := NewGetOptions(parent, streams) o := NewGetOptions(parent, streams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -38,7 +38,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/serializer/streaming" "k8s.io/apimachinery/pkg/runtime/serializer/streaming"
"k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
@ -101,7 +101,7 @@ func TestGetUnknownSchemaObject(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -145,7 +145,7 @@ func TestGetSchemaObject(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.Run(cmd, []string{"replicationcontrollers", "foo"}) cmd.Run(cmd, []string{"replicationcontrollers", "foo"})
@ -166,7 +166,7 @@ func TestGetObjects(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &pods.Items[0])}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &pods.Items[0])},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -192,7 +192,7 @@ func TestGetObjectSubresourceStatus(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &replicationcontrollers.Items[0])}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &replicationcontrollers.Items[0])},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -220,7 +220,7 @@ func TestGetObjectSubresourceScale(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: replicationControllersScaleSubresourceTableObjBody(codec, replicationcontrollers.Items[0])}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: replicationControllersScaleSubresourceTableObjBody(codec, replicationcontrollers.Items[0])},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -248,7 +248,7 @@ func TestGetTableObjects(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podTableObjBody(codec, pods.Items[0])}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podTableObjBody(codec, pods.Items[0])},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -274,7 +274,7 @@ func TestGetV1TableObjects(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podV1TableObjBody(codec, pods.Items[0])}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podV1TableObjBody(codec, pods.Items[0])},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -300,7 +300,7 @@ func TestGetObjectsShowKind(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &pods.Items[0])}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &pods.Items[0])},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -327,7 +327,7 @@ func TestGetTableObjectsShowKind(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podTableObjBody(codec, pods.Items[0])}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podTableObjBody(codec, pods.Items[0])},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -381,7 +381,7 @@ func TestGetMultipleResourceTypesShowKinds(t *testing.T) {
}), }),
} }
streams, _, buf, bufErr := genericclioptions.NewTestIOStreams() streams, _, buf, bufErr := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -443,7 +443,7 @@ func TestGetMultipleTableResourceTypesShowKinds(t *testing.T) {
}), }),
} }
streams, _, buf, bufErr := genericclioptions.NewTestIOStreams() streams, _, buf, bufErr := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -505,7 +505,7 @@ func TestNoBlankLinesForGetMultipleTableResource(t *testing.T) {
}), }),
} }
streams, _, buf, bufErr := genericclioptions.NewTestIOStreams() streams, _, buf, bufErr := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -575,7 +575,7 @@ func TestNoBlankLinesForGetAll(t *testing.T) {
}), }),
} }
streams, _, buf, errbuf := genericclioptions.NewTestIOStreams() streams, _, buf, errbuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -602,7 +602,7 @@ func TestNotFoundMessageForGetNonNamespacedResources(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: emptyTableObjBody(codec)}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: emptyTableObjBody(codec)},
} }
streams, _, buf, errbuf := genericclioptions.NewTestIOStreams() streams, _, buf, errbuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -631,7 +631,7 @@ func TestGetObjectsShowLabels(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &pods.Items[0])}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &pods.Items[0])},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -658,7 +658,7 @@ func TestGetTableObjectsShowLabels(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podTableObjBody(codec, pods.Items[0])}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podTableObjBody(codec, pods.Items[0])},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -694,7 +694,7 @@ func TestGetEmptyTable(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: emptyTable}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: emptyTable},
} }
streams, _, buf, errbuf := genericclioptions.NewTestIOStreams() streams, _, buf, errbuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -745,7 +745,7 @@ func TestGetObjectIgnoreNotFound(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -772,7 +772,7 @@ func TestEmptyResult(t *testing.T) {
}), }),
} }
streams, _, _, errbuf := genericclioptions.NewTestIOStreams() streams, _, _, errbuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
// we're assuming that an empty file is being passed from stdin // we're assuming that an empty file is being passed from stdin
cmd.Flags().Set("filename", "-") cmd.Flags().Set("filename", "-")
@ -797,7 +797,7 @@ func TestEmptyResultJSON(t *testing.T) {
}), }),
} }
streams, _, outbuf, errbuf := genericclioptions.NewTestIOStreams() streams, _, outbuf, errbuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
// we're assuming that an empty file is being passed from stdin // we're assuming that an empty file is being passed from stdin
cmd.Flags().Set("filename", "-") cmd.Flags().Set("filename", "-")
@ -861,7 +861,7 @@ func TestGetSortedObjects(t *testing.T) {
} }
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &corev1.SchemeGroupVersion}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &corev1.SchemeGroupVersion}}
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -901,7 +901,7 @@ func TestGetSortedObjectsUnstructuredTable(t *testing.T) {
} }
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &corev1.SchemeGroupVersion}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &corev1.SchemeGroupVersion}}
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1134,7 +1134,7 @@ func TestGetObjectsIdentifiedByFile(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &pods.Items[0])}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &pods.Items[0])},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1161,7 +1161,7 @@ func TestGetTableObjectsIdentifiedByFile(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podTableObjBody(codec, pods.Items[0])}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podTableObjBody(codec, pods.Items[0])},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1188,7 +1188,7 @@ func TestGetListObjects(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, pods)}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, pods)},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1215,7 +1215,7 @@ func TestGetListTableObjects(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podTableObjBody(codec, pods.Items...)}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: podTableObjBody(codec, pods.Items...)},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1242,7 +1242,7 @@ func TestGetListComponentStatus(t *testing.T) {
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: componentStatusTableObjBody(codec, (*statuses).Items...)}, Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: componentStatusTableObjBody(codec, (*statuses).Items...)},
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1292,7 +1292,7 @@ func TestGetMixedGenericObjects(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1342,7 +1342,7 @@ func TestGetMultipleTypeObjects(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1382,7 +1382,7 @@ func TestGetMultipleTypeTableObjects(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1423,7 +1423,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1526,7 +1526,7 @@ func TestGetMultipleTypeObjectsWithLabelSelector(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1571,7 +1571,7 @@ func TestGetMultipleTypeTableObjectsWithLabelSelector(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1616,7 +1616,7 @@ func TestGetMultipleTypeObjectsWithFieldSelector(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1661,7 +1661,7 @@ func TestGetMultipleTypeTableObjectsWithFieldSelector(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1708,7 +1708,7 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1753,7 +1753,7 @@ func TestGetMultipleTypeTableObjectsWithDirectReference(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1909,7 +1909,7 @@ func TestWatchLabelSelector(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -1961,7 +1961,7 @@ func TestWatchTableLabelSelector(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -2013,7 +2013,7 @@ func TestWatchFieldSelector(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -2065,7 +2065,7 @@ func TestWatchTableFieldSelector(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -2111,7 +2111,7 @@ func TestWatchResource(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -2156,7 +2156,7 @@ func TestWatchStatus(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -2203,7 +2203,7 @@ func TestWatchTableResource(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -2310,7 +2310,7 @@ func TestWatchResourceTable(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -2523,7 +2523,7 @@ pod/foo
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -2570,7 +2570,7 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -2615,7 +2615,7 @@ func TestWatchOnlyResource(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -2658,7 +2658,7 @@ func TestWatchOnlyTableResource(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -2704,7 +2704,7 @@ func TestWatchOnlyList(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)
@ -2750,7 +2750,7 @@ func TestWatchOnlyTableList(t *testing.T) {
}), }),
} }
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
cmd.SetOut(buf) cmd.SetOut(buf)
cmd.SetErr(buf) cmd.SetErr(buf)

View File

@ -18,7 +18,8 @@ package kustomize
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/kubectl/pkg/util/i18n" "k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates" "k8s.io/kubectl/pkg/util/templates"
"sigs.k8s.io/kustomize/kustomize/v5/commands/build" "sigs.k8s.io/kustomize/kustomize/v5/commands/build"
@ -26,7 +27,7 @@ import (
) )
// NewCmdKustomize returns an adapted kustomize build command. // NewCmdKustomize returns an adapted kustomize build command.
func NewCmdKustomize(streams genericclioptions.IOStreams) *cobra.Command { func NewCmdKustomize(streams genericiooptions.IOStreams) *cobra.Command {
h := build.MakeHelp("kubectl", "kustomize") h := build.MakeHelp("kubectl", "kustomize")
return build.NewCmdBuild( return build.NewCmdBuild(
filesys.MakeFsOnDisk(), filesys.MakeFsOnDisk(),

View File

@ -35,6 +35,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -85,7 +86,7 @@ type LabelOptions struct {
unstructuredClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error) unstructuredClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error)
// Common shared fields // Common shared fields
genericclioptions.IOStreams genericiooptions.IOStreams
} }
var ( var (
@ -118,7 +119,7 @@ var (
kubectl label pods foo bar-`)) kubectl label pods foo bar-`))
) )
func NewLabelOptions(ioStreams genericclioptions.IOStreams) *LabelOptions { func NewLabelOptions(ioStreams genericiooptions.IOStreams) *LabelOptions {
return &LabelOptions{ return &LabelOptions{
RecordFlags: genericclioptions.NewRecordFlags(), RecordFlags: genericclioptions.NewRecordFlags(),
Recorder: genericclioptions.NoopRecorder{}, Recorder: genericclioptions.NoopRecorder{},
@ -129,7 +130,7 @@ func NewLabelOptions(ioStreams genericclioptions.IOStreams) *LabelOptions {
} }
} }
func NewCmdLabel(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdLabel(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewLabelOptions(ioStreams) o := NewLabelOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -30,7 +30,7 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/json"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
@ -346,7 +346,7 @@ func TestLabelErrors(t *testing.T) {
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericiooptions.NewTestIOStreams()
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLabel(tf, ioStreams) cmd := NewCmdLabel(tf, ioStreams)
cmd.SetOut(buf) cmd.SetOut(buf)
@ -406,7 +406,7 @@ func TestLabelForResourceFromFile(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdLabel(tf, ioStreams) cmd := NewCmdLabel(tf, ioStreams)
opts := NewLabelOptions(ioStreams) opts := NewLabelOptions(ioStreams)
opts.Filenames = []string{"../../../testdata/controller.yaml"} opts.Filenames = []string{"../../../testdata/controller.yaml"}
@ -438,7 +438,7 @@ func TestLabelLocal(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdLabel(tf, ioStreams) cmd := NewCmdLabel(tf, ioStreams)
opts := NewLabelOptions(ioStreams) opts := NewLabelOptions(ioStreams)
opts.Filenames = []string{"../../../testdata/controller.yaml"} opts.Filenames = []string{"../../../testdata/controller.yaml"}
@ -495,7 +495,7 @@ func TestLabelMultipleObjects(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericiooptions.NewTestIOStreams()
opts := NewLabelOptions(ioStreams) opts := NewLabelOptions(ioStreams)
opts.all = true opts.all = true
cmd := NewCmdLabel(tf, ioStreams) cmd := NewCmdLabel(tf, ioStreams)
@ -564,7 +564,7 @@ func TestLabelResourceVersion(t *testing.T) {
} }
tf.ClientConfigVal = cmdtesting.DefaultClientConfig() tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
iostreams, _, bufOut, _ := genericclioptions.NewTestIOStreams() iostreams, _, bufOut, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdLabel(tf, iostreams) cmd := NewCmdLabel(tf, iostreams)
cmd.SetOut(bufOut) cmd.SetOut(bufOut)
cmd.SetErr(bufOut) cmd.SetErr(bufOut)
@ -689,7 +689,7 @@ pod/foo not labeled
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
iostreams, _, bufOut, _ := genericclioptions.NewTestIOStreams() iostreams, _, bufOut, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdLabel(tf, iostreams) cmd := NewCmdLabel(tf, iostreams)
cmd.SetOut(bufOut) cmd.SetOut(bufOut)
cmd.SetErr(bufOut) cmd.SetErr(bufOut)

View File

@ -32,6 +32,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/polymorphichelpers" "k8s.io/kubectl/pkg/polymorphichelpers"
@ -125,14 +126,14 @@ type LogsOptions struct {
RESTClientGetter genericclioptions.RESTClientGetter RESTClientGetter genericclioptions.RESTClientGetter
LogsForObject polymorphichelpers.LogsForObjectFunc LogsForObject polymorphichelpers.LogsForObjectFunc
genericclioptions.IOStreams genericiooptions.IOStreams
TailSpecified bool TailSpecified bool
containerNameFromRefSpecRegexp *regexp.Regexp containerNameFromRefSpecRegexp *regexp.Regexp
} }
func NewLogsOptions(streams genericclioptions.IOStreams, allContainers bool) *LogsOptions { func NewLogsOptions(streams genericiooptions.IOStreams, allContainers bool) *LogsOptions {
return &LogsOptions{ return &LogsOptions{
IOStreams: streams, IOStreams: streams,
AllContainers: allContainers, AllContainers: allContainers,
@ -144,7 +145,7 @@ func NewLogsOptions(streams genericclioptions.IOStreams, allContainers bool) *Lo
} }
// NewCmdLogs creates a new pod logs command // NewCmdLogs creates a new pod logs command
func NewCmdLogs(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { func NewCmdLogs(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Command {
o := NewLogsOptions(streams, false) o := NewLogsOptions(streams, false)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -33,6 +33,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
@ -42,13 +43,13 @@ import (
func TestLog(t *testing.T) { func TestLog(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
opts func(genericclioptions.IOStreams) *LogsOptions opts func(genericiooptions.IOStreams) *LogsOptions
expectedErr string expectedErr string
expectedOutSubstrings []string expectedOutSubstrings []string
}{ }{
{ {
name: "v1 - pod log", name: "v1 - pod log",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
{ {
@ -69,7 +70,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "pod logs with prefix", name: "pod logs with prefix",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
{ {
@ -91,7 +92,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "pod logs with prefix: init container", name: "pod logs with prefix: init container",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
{ {
@ -113,7 +114,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "pod logs with prefix: ephemeral container", name: "pod logs with prefix: ephemeral container",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
{ {
@ -135,7 +136,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "get logs from multiple requests sequentially", name: "get logs from multiple requests sequentially",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
{ {
@ -169,7 +170,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "follow logs from multiple requests concurrently", name: "follow logs from multiple requests concurrently",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
@ -207,7 +208,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "fail to follow logs from multiple requests when there are more logs sources then MaxFollowConcurrency allows", name: "fail to follow logs from multiple requests when there are more logs sources then MaxFollowConcurrency allows",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
@ -242,7 +243,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "fail if LogsForObject fails", name: "fail if LogsForObject fails",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
o := NewLogsOptions(streams, false) o := NewLogsOptions(streams, false)
o.LogsForObject = func(restClientGetter genericclioptions.RESTClientGetter, object, options runtime.Object, timeout time.Duration, allContainers bool) (map[corev1.ObjectReference]restclient.ResponseWrapper, error) { o.LogsForObject = func(restClientGetter genericclioptions.RESTClientGetter, object, options runtime.Object, timeout time.Duration, allContainers bool) (map[corev1.ObjectReference]restclient.ResponseWrapper, error) {
return nil, errors.New("Error from the LogsForObject") return nil, errors.New("Error from the LogsForObject")
@ -253,7 +254,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "fail to get logs, if ConsumeRequestFn fails", name: "fail to get logs, if ConsumeRequestFn fails",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
{ {
@ -280,7 +281,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "follow logs from multiple requests concurrently with prefix", name: "follow logs from multiple requests concurrently with prefix",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
@ -319,7 +320,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "fail to follow logs from multiple requests, if ConsumeRequestFn fails", name: "fail to follow logs from multiple requests, if ConsumeRequestFn fails",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
@ -355,7 +356,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "fail to follow logs, if ConsumeRequestFn fails", name: "fail to follow logs, if ConsumeRequestFn fails",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
{ {
@ -378,7 +379,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "get logs from multiple requests and ignores the error if the container fails", name: "get logs from multiple requests and ignores the error if the container fails",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
{ {
@ -413,7 +414,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "get logs from multiple requests and an container fails", name: "get logs from multiple requests and an container fails",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
{ {
@ -438,7 +439,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "follow logs from multiple requests and ignores the error if the container fails", name: "follow logs from multiple requests and ignores the error if the container fails",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
{ {
@ -474,7 +475,7 @@ func TestLog(t *testing.T) {
}, },
{ {
name: "follow logs from multiple requests and an container fails", name: "follow logs from multiple requests and an container fails",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
mock := &logTestMock{ mock := &logTestMock{
logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{ logsForObjectRequests: map[corev1.ObjectReference]restclient.ResponseWrapper{
{ {
@ -504,7 +505,7 @@ func TestLog(t *testing.T) {
tf := cmdtesting.NewTestFactory().WithNamespace("test") tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericiooptions.NewTestIOStreams()
opts := test.opts(streams) opts := test.opts(streams)
opts.Namespace = "test" opts.Namespace = "test"
@ -555,12 +556,12 @@ func TestValidateLogOptions(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
args []string args []string
opts func(genericclioptions.IOStreams) *LogsOptions opts func(genericiooptions.IOStreams) *LogsOptions
expected string expected string
}{ }{
{ {
name: "since & since-time", name: "since & since-time",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
o := NewLogsOptions(streams, false) o := NewLogsOptions(streams, false)
o.SinceSeconds = time.Hour o.SinceSeconds = time.Hour
o.SinceTime = "2006-01-02T15:04:05Z" o.SinceTime = "2006-01-02T15:04:05Z"
@ -578,7 +579,7 @@ func TestValidateLogOptions(t *testing.T) {
}, },
{ {
name: "negative since-time", name: "negative since-time",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
o := NewLogsOptions(streams, false) o := NewLogsOptions(streams, false)
o.SinceSeconds = -1 * time.Second o.SinceSeconds = -1 * time.Second
@ -595,7 +596,7 @@ func TestValidateLogOptions(t *testing.T) {
}, },
{ {
name: "negative limit-bytes", name: "negative limit-bytes",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
o := NewLogsOptions(streams, false) o := NewLogsOptions(streams, false)
o.LimitBytes = -100 o.LimitBytes = -100
@ -612,7 +613,7 @@ func TestValidateLogOptions(t *testing.T) {
}, },
{ {
name: "negative tail", name: "negative tail",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
o := NewLogsOptions(streams, false) o := NewLogsOptions(streams, false)
o.Tail = -100 o.Tail = -100
@ -629,7 +630,7 @@ func TestValidateLogOptions(t *testing.T) {
}, },
{ {
name: "container name combined with --all-containers", name: "container name combined with --all-containers",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
o := NewLogsOptions(streams, true) o := NewLogsOptions(streams, true)
o.Container = "my-container" o.Container = "my-container"
@ -646,7 +647,7 @@ func TestValidateLogOptions(t *testing.T) {
}, },
{ {
name: "container name combined with second argument", name: "container name combined with second argument",
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
o := NewLogsOptions(streams, false) o := NewLogsOptions(streams, false)
o.Container = "my-container" o.Container = "my-container"
o.ContainerNameSpecified = true o.ContainerNameSpecified = true
@ -664,7 +665,7 @@ func TestValidateLogOptions(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
streams := genericclioptions.NewTestIOStreamsDiscard() streams := genericiooptions.NewTestIOStreamsDiscard()
o := test.opts(streams) o := test.opts(streams)
o.Resources = test.args o.Resources = test.args
@ -687,13 +688,13 @@ func TestLogComplete(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
args []string args []string
opts func(genericclioptions.IOStreams) *LogsOptions opts func(genericiooptions.IOStreams) *LogsOptions
expected string expected string
}{ }{
{ {
name: "One args case", name: "One args case",
args: []string{"foo"}, args: []string{"foo"},
opts: func(streams genericclioptions.IOStreams) *LogsOptions { opts: func(streams genericiooptions.IOStreams) *LogsOptions {
o := NewLogsOptions(streams, false) o := NewLogsOptions(streams, false)
o.Selector = "foo" o.Selector = "foo"
return o return o
@ -702,12 +703,12 @@ func TestLogComplete(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
cmd := NewCmdLogs(f, genericclioptions.NewTestIOStreamsDiscard()) cmd := NewCmdLogs(f, genericiooptions.NewTestIOStreamsDiscard())
out := "" out := ""
// checkErr breaks tests in case of errors, plus we just // checkErr breaks tests in case of errors, plus we just
// need to check errors returned by the command validation // need to check errors returned by the command validation
o := test.opts(genericclioptions.NewTestIOStreamsDiscard()) o := test.opts(genericiooptions.NewTestIOStreamsDiscard())
err := o.Complete(f, cmd, test.args) err := o.Complete(f, cmd, test.args)
if err == nil { if err == nil {
t.Fatalf("expected error %q, got none", test.expected) t.Fatalf("expected error %q, got none", test.expected)
@ -811,7 +812,7 @@ func TestNoResourceFoundMessage(t *testing.T) {
}), }),
} }
streams, _, buf, errbuf := genericclioptions.NewTestIOStreams() streams, _, buf, errbuf := genericiooptions.NewTestIOStreams()
cmd := NewCmdLogs(tf, streams) cmd := NewCmdLogs(tf, streams)
o := NewLogsOptions(streams, false) o := NewLogsOptions(streams, false)
o.Selector = "foo" o.Selector = "foo"

View File

@ -37,6 +37,7 @@ import (
"k8s.io/apimachinery/pkg/util/strategicpatch" "k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/apimachinery/pkg/util/yaml" "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/printers"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -74,7 +75,7 @@ type PatchOptions struct {
unstructuredClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error) unstructuredClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error)
fieldManager string fieldManager string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
var ( var (
@ -107,7 +108,7 @@ var (
var supportedSubresources = []string{"status", "scale"} var supportedSubresources = []string{"status", "scale"}
func NewPatchOptions(ioStreams genericclioptions.IOStreams) *PatchOptions { func NewPatchOptions(ioStreams genericiooptions.IOStreams) *PatchOptions {
return &PatchOptions{ return &PatchOptions{
RecordFlags: genericclioptions.NewRecordFlags(), RecordFlags: genericclioptions.NewRecordFlags(),
Recorder: genericclioptions.NoopRecorder{}, Recorder: genericclioptions.NoopRecorder{},
@ -116,7 +117,7 @@ func NewPatchOptions(ioStreams genericclioptions.IOStreams) *PatchOptions {
} }
} }
func NewCmdPatch(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdPatch(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra.Command {
o := NewPatchOptions(ioStreams) o := NewPatchOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{

View File

@ -23,7 +23,7 @@ import (
jsonpath "github.com/exponent-io/jsonpath" jsonpath "github.com/exponent-io/jsonpath"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
@ -57,7 +57,7 @@ func TestPatchObject(t *testing.T) {
} }
}), }),
} }
stream, _, buf, _ := genericclioptions.NewTestIOStreams() stream, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdPatch(tf, stream) cmd := NewCmdPatch(tf, stream)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
@ -91,7 +91,7 @@ func TestPatchObjectFromFile(t *testing.T) {
} }
}), }),
} }
stream, _, buf, _ := genericclioptions.NewTestIOStreams() stream, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdPatch(tf, stream) cmd := NewCmdPatch(tf, stream)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
@ -138,7 +138,7 @@ func TestPatchNoop(t *testing.T) {
patchObject.Annotations = map[string]string{} patchObject.Annotations = map[string]string{}
} }
patchObject.Annotations["foo"] = "bar" patchObject.Annotations["foo"] = "bar"
stream, _, buf, _ := genericclioptions.NewTestIOStreams() stream, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdPatch(tf, stream) cmd := NewCmdPatch(tf, stream)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
cmd.Flags().Set("patch", `{"metadata":{"annotations":{"foo":"bar"}}}`) cmd.Flags().Set("patch", `{"metadata":{"annotations":{"foo":"bar"}}}`)
@ -177,7 +177,7 @@ func TestPatchObjectFromFileOutput(t *testing.T) {
} }
}), }),
} }
stream, _, buf, _ := genericclioptions.NewTestIOStreams() stream, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdPatch(tf, stream) cmd := NewCmdPatch(tf, stream)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")
@ -222,7 +222,7 @@ func TestPatchSubresource(t *testing.T) {
} }
}), }),
} }
stream, _, buf, _ := genericclioptions.NewTestIOStreams() stream, _, buf, _ := genericiooptions.NewTestIOStreams()
cmd := NewCmdPatch(tf, stream) cmd := NewCmdPatch(tf, stream)
cmd.Flags().Set("namespace", "test") cmd.Flags().Set("namespace", "test")

View File

@ -26,7 +26,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n" "k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates" "k8s.io/kubectl/pkg/util/templates"
@ -58,7 +59,7 @@ var (
ValidPluginFilenamePrefixes = []string{"kubectl"} ValidPluginFilenamePrefixes = []string{"kubectl"}
) )
func NewCmdPlugin(streams genericclioptions.IOStreams) *cobra.Command { func NewCmdPlugin(streams genericiooptions.IOStreams) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "plugin [flags]", Use: "plugin [flags]",
DisableFlagsInUseLine: true, DisableFlagsInUseLine: true,
@ -79,11 +80,11 @@ type PluginListOptions struct {
PluginPaths []string PluginPaths []string
genericclioptions.IOStreams genericiooptions.IOStreams
} }
// NewCmdPluginList provides a way to list all plugin executables visible to kubectl // NewCmdPluginList provides a way to list all plugin executables visible to kubectl
func NewCmdPluginList(streams genericclioptions.IOStreams) *cobra.Command { func NewCmdPluginList(streams genericiooptions.IOStreams) *cobra.Command {
o := &PluginListOptions{ o := &PluginListOptions{
IOStreams: streams, IOStreams: streams,
} }

View File

@ -27,7 +27,8 @@ import (
"strings" "strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
) )
// SetupPluginCompletion adds a Cobra command to the command tree for each // SetupPluginCompletion adds a Cobra command to the command tree for each
@ -81,7 +82,7 @@ func SetupPluginCompletion(cmd *cobra.Command, args []string) {
// for each plugin so that the completion logic knows about the plugins // for each plugin so that the completion logic knows about the plugins
func addPluginCommands(cmd *cobra.Command) { func addPluginCommands(cmd *cobra.Command) {
kubectl := cmd.Root() kubectl := cmd.Root()
streams := genericclioptions.IOStreams{ streams := genericiooptions.IOStreams{
In: &bytes.Buffer{}, In: &bytes.Buffer{},
Out: io.Discard, Out: io.Discard,
ErrOut: io.Discard, ErrOut: io.Discard,

Some files were not shown because too many files have changed in this diff Show More