Unverified Commit c85e69ae authored by David Eads's avatar David Eads Committed by Maciej Szulik

remove unnecessary factory delegation for RESTClientGetter method

parent 4da73a5f
...@@ -177,7 +177,7 @@ func (o *AnnotateOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [ ...@@ -177,7 +177,7 @@ func (o *AnnotateOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
return printer.PrintObj(obj, out) return printer.PrintObj(obj, out)
} }
o.namespace, o.enforceNamespace, err = f.DefaultNamespace() o.namespace, o.enforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -418,10 +418,9 @@ func TestAnnotateErrors(t *testing.T) { ...@@ -418,10 +418,9 @@ func TestAnnotateErrors(t *testing.T) {
for k, testCase := range testCases { for k, testCase := range testCases {
t.Run(k, func(t *testing.T) { t.Run(k, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
iostreams, _, bufOut, bufErr := genericclioptions.NewTestIOStreams() iostreams, _, bufOut, bufErr := genericclioptions.NewTestIOStreams()
...@@ -453,7 +452,7 @@ func TestAnnotateErrors(t *testing.T) { ...@@ -453,7 +452,7 @@ func TestAnnotateErrors(t *testing.T) {
func TestAnnotateObject(t *testing.T) { func TestAnnotateObject(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -485,7 +484,6 @@ func TestAnnotateObject(t *testing.T) { ...@@ -485,7 +484,6 @@ func TestAnnotateObject(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
iostreams, _, bufOut, _ := genericclioptions.NewTestIOStreams() iostreams, _, bufOut, _ := genericclioptions.NewTestIOStreams()
...@@ -507,7 +505,7 @@ func TestAnnotateObject(t *testing.T) { ...@@ -507,7 +505,7 @@ func TestAnnotateObject(t *testing.T) {
func TestAnnotateObjectFromFile(t *testing.T) { func TestAnnotateObjectFromFile(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -539,7 +537,6 @@ func TestAnnotateObjectFromFile(t *testing.T) { ...@@ -539,7 +537,6 @@ func TestAnnotateObjectFromFile(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
iostreams, _, bufOut, _ := genericclioptions.NewTestIOStreams() iostreams, _, bufOut, _ := genericclioptions.NewTestIOStreams()
...@@ -560,7 +557,7 @@ func TestAnnotateObjectFromFile(t *testing.T) { ...@@ -560,7 +557,7 @@ func TestAnnotateObjectFromFile(t *testing.T) {
} }
func TestAnnotateLocal(t *testing.T) { func TestAnnotateLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -571,7 +568,6 @@ func TestAnnotateLocal(t *testing.T) { ...@@ -571,7 +568,6 @@ func TestAnnotateLocal(t *testing.T) {
return nil, nil return nil, nil
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
iostreams, _, _, _ := genericclioptions.NewTestIOStreams() iostreams, _, _, _ := genericclioptions.NewTestIOStreams()
...@@ -594,7 +590,7 @@ func TestAnnotateLocal(t *testing.T) { ...@@ -594,7 +590,7 @@ func TestAnnotateLocal(t *testing.T) {
func TestAnnotateMultipleObjects(t *testing.T) { func TestAnnotateMultipleObjects(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -627,7 +623,6 @@ func TestAnnotateMultipleObjects(t *testing.T) { ...@@ -627,7 +623,6 @@ func TestAnnotateMultipleObjects(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
iostreams, _, _, _ := genericclioptions.NewTestIOStreams() iostreams, _, _, _ := genericclioptions.NewTestIOStreams()
......
...@@ -230,7 +230,7 @@ func (o *ApplyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error { ...@@ -230,7 +230,7 @@ func (o *ApplyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
return err return err
} }
o.Namespace, o.EnforceNamespace, err = f.DefaultNamespace() o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -118,7 +118,7 @@ func (o *SetLastAppliedOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) ...@@ -118,7 +118,7 @@ func (o *SetLastAppliedOptions) Complete(f cmdutil.Factory, cmd *cobra.Command)
o.shortOutput = o.output == "name" o.shortOutput = o.output == "name"
var err error var err error
o.namespace, o.enforceNamespace, err = f.DefaultNamespace() o.namespace, o.enforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -273,7 +273,7 @@ func TestRunApplyPrintsValidObjectList(t *testing.T) { ...@@ -273,7 +273,7 @@ func TestRunApplyPrintsValidObjectList(t *testing.T) {
cmBytes := readConfigMapList(t, filenameCM) cmBytes := readConfigMapList(t, filenameCM)
pathCM := "/namespaces/test/configmaps" pathCM := "/namespaces/test/configmaps"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -292,7 +292,6 @@ func TestRunApplyPrintsValidObjectList(t *testing.T) { ...@@ -292,7 +292,6 @@ func TestRunApplyPrintsValidObjectList(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -393,7 +392,7 @@ func TestRunApplyViewLastApplied(t *testing.T) { ...@@ -393,7 +392,7 @@ func TestRunApplyViewLastApplied(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -419,7 +418,6 @@ func TestRunApplyViewLastApplied(t *testing.T) { ...@@ -419,7 +418,6 @@ func TestRunApplyViewLastApplied(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
cmdutil.BehaviorOnFatal(func(str string, code int) { cmdutil.BehaviorOnFatal(func(str string, code int) {
...@@ -453,7 +451,7 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) { ...@@ -453,7 +451,7 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) {
nameRC, rcBytes := readReplicationController(t, filenameRC) nameRC, rcBytes := readReplicationController(t, filenameRC)
pathRC := "/namespaces/test/replicationcontrollers/" + nameRC pathRC := "/namespaces/test/replicationcontrollers/" + nameRC
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -472,7 +470,6 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) { ...@@ -472,7 +470,6 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams()
...@@ -499,7 +496,7 @@ func TestApplyObject(t *testing.T) { ...@@ -499,7 +496,7 @@ func TestApplyObject(t *testing.T) {
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test apply when a local object is specified", func(t *testing.T) { t.Run("test apply when a local object is specified", func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -520,7 +517,6 @@ func TestApplyObject(t *testing.T) { ...@@ -520,7 +517,6 @@ func TestApplyObject(t *testing.T) {
}), }),
} }
tf.OpenAPISchemaFunc = fn tf.OpenAPISchemaFunc = fn
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams()
...@@ -564,7 +560,7 @@ func TestApplyObjectOutput(t *testing.T) { ...@@ -564,7 +560,7 @@ func TestApplyObjectOutput(t *testing.T) {
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test apply returns correct output", func(t *testing.T) { t.Run("test apply returns correct output", func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -585,7 +581,6 @@ func TestApplyObjectOutput(t *testing.T) { ...@@ -585,7 +581,6 @@ func TestApplyObjectOutput(t *testing.T) {
}), }),
} }
tf.OpenAPISchemaFunc = fn tf.OpenAPISchemaFunc = fn
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams()
...@@ -617,7 +612,7 @@ func TestApplyRetry(t *testing.T) { ...@@ -617,7 +612,7 @@ func TestApplyRetry(t *testing.T) {
firstPatch := true firstPatch := true
retry := false retry := false
getCount := 0 getCount := 0
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -647,7 +642,6 @@ func TestApplyRetry(t *testing.T) { ...@@ -647,7 +642,6 @@ func TestApplyRetry(t *testing.T) {
}), }),
} }
tf.OpenAPISchemaFunc = fn tf.OpenAPISchemaFunc = fn
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams()
...@@ -677,7 +671,7 @@ func TestApplyNonExistObject(t *testing.T) { ...@@ -677,7 +671,7 @@ func TestApplyNonExistObject(t *testing.T) {
pathRC := "/namespaces/test/replicationcontrollers" pathRC := "/namespaces/test/replicationcontrollers"
pathNameRC := pathRC + "/" + nameRC pathNameRC := pathRC + "/" + nameRC
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -697,7 +691,6 @@ func TestApplyNonExistObject(t *testing.T) { ...@@ -697,7 +691,6 @@ func TestApplyNonExistObject(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -723,7 +716,7 @@ func TestApplyEmptyPatch(t *testing.T) { ...@@ -723,7 +716,7 @@ func TestApplyEmptyPatch(t *testing.T) {
var body []byte var body []byte
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -750,7 +743,6 @@ func TestApplyEmptyPatch(t *testing.T) { ...@@ -750,7 +743,6 @@ func TestApplyEmptyPatch(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
// 1. apply non exist object // 1. apply non exist object
...@@ -797,7 +789,7 @@ func testApplyMultipleObjects(t *testing.T, asList bool) { ...@@ -797,7 +789,7 @@ func testApplyMultipleObjects(t *testing.T, asList bool) {
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test apply on multiple objects", func(t *testing.T) { t.Run("test apply on multiple objects", func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -825,7 +817,6 @@ func testApplyMultipleObjects(t *testing.T, asList bool) { ...@@ -825,7 +817,6 @@ func testApplyMultipleObjects(t *testing.T, asList bool) {
}), }),
} }
tf.OpenAPISchemaFunc = fn tf.OpenAPISchemaFunc = fn
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams()
...@@ -884,7 +875,7 @@ func TestApplyNULLPreservation(t *testing.T) { ...@@ -884,7 +875,7 @@ func TestApplyNULLPreservation(t *testing.T) {
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test apply preserves NULL fields", func(t *testing.T) { t.Run("test apply preserves NULL fields", func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -926,7 +917,6 @@ func TestApplyNULLPreservation(t *testing.T) { ...@@ -926,7 +917,6 @@ func TestApplyNULLPreservation(t *testing.T) {
}), }),
} }
tf.OpenAPISchemaFunc = fn tf.OpenAPISchemaFunc = fn
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams()
...@@ -960,7 +950,7 @@ func TestUnstructuredApply(t *testing.T) { ...@@ -960,7 +950,7 @@ func TestUnstructuredApply(t *testing.T) {
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test apply works correctly with unstructured objects", func(t *testing.T) { t.Run("test apply works correctly with unstructured objects", func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -993,7 +983,6 @@ func TestUnstructuredApply(t *testing.T) { ...@@ -993,7 +983,6 @@ func TestUnstructuredApply(t *testing.T) {
}), }),
} }
tf.OpenAPISchemaFunc = fn tf.OpenAPISchemaFunc = fn
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams()
...@@ -1029,7 +1018,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) { ...@@ -1029,7 +1018,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) {
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test repeated apply operations on an unstructured object", func(t *testing.T) { t.Run("test repeated apply operations on an unstructured object", func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -1059,7 +1048,6 @@ func TestUnstructuredIdempotentApply(t *testing.T) { ...@@ -1059,7 +1048,6 @@ func TestUnstructuredIdempotentApply(t *testing.T) {
}), }),
} }
tf.OpenAPISchemaFunc = fn tf.OpenAPISchemaFunc = fn
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams()
...@@ -1131,7 +1119,7 @@ func TestRunApplySetLastApplied(t *testing.T) { ...@@ -1131,7 +1119,7 @@ func TestRunApplySetLastApplied(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -1161,7 +1149,6 @@ func TestRunApplySetLastApplied(t *testing.T) { ...@@ -1161,7 +1149,6 @@ func TestRunApplySetLastApplied(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
cmdutil.BehaviorOnFatal(func(str string, code int) { cmdutil.BehaviorOnFatal(func(str string, code int) {
...@@ -1227,7 +1214,7 @@ func TestForceApply(t *testing.T) { ...@@ -1227,7 +1214,7 @@ func TestForceApply(t *testing.T) {
deleted := false deleted := false
isScaledDownToZero := false isScaledDownToZero := false
counts := map[string]int{} counts := map[string]int{}
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
...@@ -1312,7 +1299,6 @@ func TestForceApply(t *testing.T) { ...@@ -1312,7 +1299,6 @@ func TestForceApply(t *testing.T) {
tf.OpenAPISchemaFunc = fn tf.OpenAPISchemaFunc = fn
tf.Client = tf.UnstructuredClient tf.Client = tf.UnstructuredClient
tf.ClientConfigVal = &restclient.Config{} tf.ClientConfigVal = &restclient.Config{}
tf.Namespace = "test"
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams) cmd := NewCmdApply("kubectl", tf, ioStreams)
......
...@@ -91,7 +91,7 @@ func NewCmdApplyViewLastApplied(f cmdutil.Factory, ioStreams genericclioptions.I ...@@ -91,7 +91,7 @@ func NewCmdApplyViewLastApplied(f cmdutil.Factory, ioStreams genericclioptions.I
} }
func (o *ViewLastAppliedOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args []string) error { func (o *ViewLastAppliedOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args []string) error {
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -135,7 +135,7 @@ func (p *AttachOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, argsIn [ ...@@ -135,7 +135,7 @@ func (p *AttachOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, argsIn [
return cmdutil.UsageErrorf(cmd, "expected POD, TYPE/NAME, or TYPE NAME, (at most 2 arguments) saw %d: %v", len(argsIn), argsIn) return cmdutil.UsageErrorf(cmd, "expected POD, TYPE/NAME, or TYPE NAME, (at most 2 arguments) saw %d: %v", len(argsIn), argsIn)
} }
namespace, _, err := f.DefaultNamespace() namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -140,7 +140,7 @@ func TestPodAndContainerAttach(t *testing.T) { ...@@ -140,7 +140,7 @@ func TestPodAndContainerAttach(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -156,7 +156,6 @@ func TestPodAndContainerAttach(t *testing.T) { ...@@ -156,7 +156,6 @@ func TestPodAndContainerAttach(t *testing.T) {
return nil, nil return nil, nil
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
cmd := &cobra.Command{} cmd := &cobra.Command{}
...@@ -224,7 +223,7 @@ func TestAttach(t *testing.T) { ...@@ -224,7 +223,7 @@ func TestAttach(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -247,7 +246,6 @@ func TestAttach(t *testing.T) { ...@@ -247,7 +246,6 @@ func TestAttach(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: legacyscheme.Codecs, GroupVersion: &schema.GroupVersion{Version: test.version}}} tf.ClientConfigVal = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: legacyscheme.Codecs, GroupVersion: &schema.GroupVersion{Version: test.version}}}
remoteAttach := &fakeRemoteAttach{} remoteAttach := &fakeRemoteAttach{}
if test.remoteAttachErr { if test.remoteAttachErr {
...@@ -312,7 +310,7 @@ func TestAttachWarnings(t *testing.T) { ...@@ -312,7 +310,7 @@ func TestAttachWarnings(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -335,7 +333,6 @@ func TestAttachWarnings(t *testing.T) { ...@@ -335,7 +333,6 @@ func TestAttachWarnings(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: legacyscheme.Codecs, GroupVersion: &schema.GroupVersion{Version: test.version}}} tf.ClientConfigVal = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: legacyscheme.Codecs, GroupVersion: &schema.GroupVersion{Version: test.version}}}
streams, _, _, bufErr := genericclioptions.NewTestIOStreams() streams, _, _, bufErr := genericclioptions.NewTestIOStreams()
ex := &fakeRemoteAttach{} ex := &fakeRemoteAttach{}
......
...@@ -146,7 +146,7 @@ func (o *CanIOptions) Complete(f cmdutil.Factory, args []string) error { ...@@ -146,7 +146,7 @@ func (o *CanIOptions) Complete(f cmdutil.Factory, args []string) error {
o.Namespace = "" o.Namespace = ""
if !o.AllNamespaces { if !o.AllNamespaces {
o.Namespace, _, err = f.DefaultNamespace() o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -121,7 +121,7 @@ func TestRunAccessCheck(t *testing.T) { ...@@ -121,7 +121,7 @@ func TestRunAccessCheck(t *testing.T) {
test.o.Out = ioutil.Discard test.o.Out = ioutil.Discard
test.o.ErrOut = ioutil.Discard test.o.ErrOut = ioutil.Discard
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -157,7 +157,6 @@ func TestRunAccessCheck(t *testing.T) { ...@@ -157,7 +157,6 @@ func TestRunAccessCheck(t *testing.T) {
test.serverErr test.serverErr
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}}
if err := test.o.Complete(tf, test.args); err != nil { if err := test.o.Complete(tf, test.args); err != nil {
......
...@@ -97,7 +97,7 @@ func (o *ReconcileOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args ...@@ -97,7 +97,7 @@ func (o *ReconcileOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args
return errors.New("no arguments are allowed") return errors.New("no arguments are allowed")
} }
namespace, enforceNamespace, err := f.DefaultNamespace() namespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -165,7 +165,7 @@ func (o *AutoscaleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args ...@@ -165,7 +165,7 @@ func (o *AutoscaleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
} }
} }
o.namespace, o.enforceNamespace, err = f.DefaultNamespace() o.namespace, o.enforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -134,7 +134,7 @@ func (o *ClusterInfoDumpOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) ...@@ -134,7 +134,7 @@ func (o *ClusterInfoDumpOptions) Complete(f cmdutil.Factory, cmd *cobra.Command)
if err != nil { if err != nil {
return err return err
} }
o.Namespace, _, err = f.DefaultNamespace() o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -139,7 +139,7 @@ func (o *ConvertOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) (err er ...@@ -139,7 +139,7 @@ func (o *ConvertOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) (err er
o.builder.Schema(schema) o.builder.Schema(schema)
} }
cmdNamespace, _, err := f.DefaultNamespace() cmdNamespace, _, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -95,7 +95,7 @@ func TestConvertObject(t *testing.T) { ...@@ -95,7 +95,7 @@ func TestConvertObject(t *testing.T) {
for _, tc := range testcases { for _, tc := range testcases {
for _, field := range tc.fields { for _, field := range tc.fields {
t.Run(fmt.Sprintf("%s %s", tc.name, field), func(t *testing.T) { t.Run(fmt.Sprintf("%s %s", tc.name, field), func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -104,7 +104,6 @@ func TestConvertObject(t *testing.T) { ...@@ -104,7 +104,6 @@ func TestConvertObject(t *testing.T) {
return nil, nil return nil, nil
}), }),
} }
tf.Namespace = "test"
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdConvert(tf, genericclioptions.IOStreams{Out: buf, ErrOut: buf}) cmd := NewCmdConvert(tf, genericclioptions.IOStreams{Out: buf, ErrOut: buf})
......
...@@ -144,7 +144,7 @@ func extractFileSpec(arg string) (fileSpec, error) { ...@@ -144,7 +144,7 @@ func extractFileSpec(arg string) (fileSpec, error) {
func (o *CopyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error { func (o *CopyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
var err error var err error
o.Namespace, _, err = f.DefaultNamespace() o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -514,8 +514,7 @@ func TestClean(t *testing.T) { ...@@ -514,8 +514,7 @@ func TestClean(t *testing.T) {
} }
func TestCopyToPod(t *testing.T) { func TestCopyToPod(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
tf.Namespace = "test"
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
......
...@@ -216,7 +216,7 @@ func (o *CreateOptions) RunCreate(f cmdutil.Factory, cmd *cobra.Command) error { ...@@ -216,7 +216,7 @@ func (o *CreateOptions) RunCreate(f cmdutil.Factory, cmd *cobra.Command) error {
return err return err
} }
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
...@@ -386,7 +386,7 @@ func (o *CreateSubcommandOptions) Complete(f cmdutil.Factory, cmd *cobra.Command ...@@ -386,7 +386,7 @@ func (o *CreateSubcommandOptions) Complete(f cmdutil.Factory, cmd *cobra.Command
return printer.PrintObj(obj, out) return printer.PrintObj(obj, out)
} }
o.Namespace, o.EnforceNamespace, err = f.DefaultNamespace() o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -36,10 +36,9 @@ import ( ...@@ -36,10 +36,9 @@ import (
func TestCreateClusterRole(t *testing.T) { func TestCreateClusterRole(t *testing.T) {
clusterRoleName := "my-cluster-role" clusterRoleName := "my-cluster-role"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tf.Client = &fake.RESTClient{} tf.Client = &fake.RESTClient{}
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
...@@ -178,11 +177,9 @@ func TestCreateClusterRole(t *testing.T) { ...@@ -178,11 +177,9 @@ func TestCreateClusterRole(t *testing.T) {
} }
func TestClusterRoleValidate(t *testing.T) { func TestClusterRoleValidate(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tests := map[string]struct { tests := map[string]struct {
clusterRoleOptions *CreateClusterRoleOptions clusterRoleOptions *CreateClusterRoleOptions
expectErr bool expectErr bool
......
...@@ -68,7 +68,7 @@ func TestCreateClusterRoleBinding(t *testing.T) { ...@@ -68,7 +68,7 @@ func TestCreateClusterRoleBinding(t *testing.T) {
}, },
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -77,7 +77,6 @@ func TestCreateClusterRoleBinding(t *testing.T) { ...@@ -77,7 +77,6 @@ func TestCreateClusterRoleBinding(t *testing.T) {
encoder := ns.EncoderForVersion(info.Serializer, groupVersion) encoder := ns.EncoderForVersion(info.Serializer, groupVersion)
decoder := ns.DecoderToVersion(info.Serializer, groupVersion) decoder := ns.DecoderToVersion(info.Serializer, groupVersion)
tf.Namespace = "test"
tf.Client = &ClusterRoleBindingRESTClient{ tf.Client = &ClusterRoleBindingRESTClient{
RESTClient: &fake.RESTClient{ RESTClient: &fake.RESTClient{
NegotiatedSerializer: ns, NegotiatedSerializer: ns,
......
...@@ -36,7 +36,7 @@ import ( ...@@ -36,7 +36,7 @@ import (
func TestCreateConfigMap(t *testing.T) { func TestCreateConfigMap(t *testing.T) {
configMap := &v1.ConfigMap{} configMap := &v1.ConfigMap{}
configMap.Name = "my-configmap" configMap.Name = "my-configmap"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -55,7 +55,6 @@ func TestCreateConfigMap(t *testing.T) { ...@@ -55,7 +55,6 @@ func TestCreateConfigMap(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdCreateConfigMap(tf, ioStreams) cmd := NewCmdCreateConfigMap(tf, ioStreams)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
......
...@@ -89,7 +89,7 @@ func Test_generatorFromName(t *testing.T) { ...@@ -89,7 +89,7 @@ func Test_generatorFromName(t *testing.T) {
func TestCreateDeployment(t *testing.T) { func TestCreateDeployment(t *testing.T) {
depName := "jonny-dep" depName := "jonny-dep"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -104,7 +104,6 @@ func TestCreateDeployment(t *testing.T) { ...@@ -104,7 +104,6 @@ func TestCreateDeployment(t *testing.T) {
}), }),
} }
tf.ClientConfigVal = &restclient.Config{} tf.ClientConfigVal = &restclient.Config{}
tf.Namespace = "test"
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdCreateDeployment(tf, ioStreams) cmd := NewCmdCreateDeployment(tf, ioStreams)
...@@ -120,7 +119,7 @@ func TestCreateDeployment(t *testing.T) { ...@@ -120,7 +119,7 @@ func TestCreateDeployment(t *testing.T) {
func TestCreateDeploymentNoImage(t *testing.T) { func TestCreateDeploymentNoImage(t *testing.T) {
depName := "jonny-dep" depName := "jonny-dep"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -135,7 +134,6 @@ func TestCreateDeploymentNoImage(t *testing.T) { ...@@ -135,7 +134,6 @@ func TestCreateDeploymentNoImage(t *testing.T) {
}), }),
} }
tf.ClientConfigVal = &restclient.Config{} tf.ClientConfigVal = &restclient.Config{}
tf.Namespace = "test"
ioStreams := genericclioptions.NewTestIOStreamsDiscard() ioStreams := genericclioptions.NewTestIOStreamsDiscard()
cmd := NewCmdCreateDeployment(tf, ioStreams) cmd := NewCmdCreateDeployment(tf, ioStreams)
......
...@@ -100,7 +100,7 @@ func (o *CreateJobOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args ...@@ -100,7 +100,7 @@ func (o *CreateJobOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
} }
o.Name = args[0] o.Name = args[0]
o.Namespace, _, err = f.DefaultNamespace() o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -32,7 +32,7 @@ import ( ...@@ -32,7 +32,7 @@ import (
func TestCreatePdb(t *testing.T) { func TestCreatePdb(t *testing.T) {
pdbName := "my-pdb" pdbName := "my-pdb"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -48,7 +48,6 @@ func TestCreatePdb(t *testing.T) { ...@@ -48,7 +48,6 @@ func TestCreatePdb(t *testing.T) {
}), }),
} }
tf.ClientConfigVal = &restclient.Config{} tf.ClientConfigVal = &restclient.Config{}
tf.Namespace = "test"
outputFormat := "name" outputFormat := "name"
......
...@@ -51,11 +51,9 @@ func TestCreateQuota(t *testing.T) { ...@@ -51,11 +51,9 @@ func TestCreateQuota(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) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdCreateQuota(tf, ioStreams) cmd := NewCmdCreateQuota(tf, ioStreams)
cmd.Flags().Parse(test.flags) cmd.Flags().Parse(test.flags)
......
...@@ -226,7 +226,7 @@ func (o *CreateRoleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args ...@@ -226,7 +226,7 @@ func (o *CreateRoleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
return printer.PrintObj(obj, o.Out) return printer.PrintObj(obj, o.Out)
} }
o.Namespace, _, err = f.DefaultNamespace() o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -34,10 +34,9 @@ import ( ...@@ -34,10 +34,9 @@ import (
func TestCreateRole(t *testing.T) { func TestCreateRole(t *testing.T) {
roleName := "my-role" roleName := "my-role"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tf.Client = &fake.RESTClient{} tf.Client = &fake.RESTClient{}
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
...@@ -152,11 +151,9 @@ func TestCreateRole(t *testing.T) { ...@@ -152,11 +151,9 @@ func TestCreateRole(t *testing.T) {
} }
func TestValidate(t *testing.T) { func TestValidate(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tests := map[string]struct { tests := map[string]struct {
roleOptions *CreateRoleOptions roleOptions *CreateRoleOptions
expectErr bool expectErr bool
...@@ -357,10 +354,9 @@ func TestValidate(t *testing.T) { ...@@ -357,10 +354,9 @@ func TestValidate(t *testing.T) {
func TestComplete(t *testing.T) { func TestComplete(t *testing.T) {
roleName := "my-role" roleName := "my-role"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tf.Client = &fake.RESTClient{} tf.Client = &fake.RESTClient{}
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
......
...@@ -70,7 +70,7 @@ func TestCreateRoleBinding(t *testing.T) { ...@@ -70,7 +70,7 @@ func TestCreateRoleBinding(t *testing.T) {
}, },
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -79,7 +79,6 @@ func TestCreateRoleBinding(t *testing.T) { ...@@ -79,7 +79,6 @@ func TestCreateRoleBinding(t *testing.T) {
encoder := ns.EncoderForVersion(info.Serializer, groupVersion) encoder := ns.EncoderForVersion(info.Serializer, groupVersion)
decoder := ns.DecoderToVersion(info.Serializer, groupVersion) decoder := ns.DecoderToVersion(info.Serializer, groupVersion)
tf.Namespace = "test"
tf.Client = &RoleBindingRESTClient{ tf.Client = &RoleBindingRESTClient{
RESTClient: &fake.RESTClient{ RESTClient: &fake.RESTClient{
NegotiatedSerializer: ns, NegotiatedSerializer: ns,
......
...@@ -37,7 +37,7 @@ func TestCreateSecretGeneric(t *testing.T) { ...@@ -37,7 +37,7 @@ func TestCreateSecretGeneric(t *testing.T) {
}, },
} }
secretObject.Name = "my-secret" secretObject.Name = "my-secret"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -56,7 +56,6 @@ func TestCreateSecretGeneric(t *testing.T) { ...@@ -56,7 +56,6 @@ func TestCreateSecretGeneric(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdCreateSecretGeneric(tf, ioStreams) cmd := NewCmdCreateSecretGeneric(tf, ioStreams)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
...@@ -72,7 +71,7 @@ func TestCreateSecretGeneric(t *testing.T) { ...@@ -72,7 +71,7 @@ func TestCreateSecretGeneric(t *testing.T) {
func TestCreateSecretDockerRegistry(t *testing.T) { func TestCreateSecretDockerRegistry(t *testing.T) {
secretObject := &v1.Secret{} secretObject := &v1.Secret{}
secretObject.Name = "my-secret" secretObject.Name = "my-secret"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -89,7 +88,6 @@ func TestCreateSecretDockerRegistry(t *testing.T) { ...@@ -89,7 +88,6 @@ func TestCreateSecretDockerRegistry(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdCreateSecretDockerRegistry(tf, ioStreams) cmd := NewCmdCreateSecretDockerRegistry(tf, ioStreams)
cmd.Flags().Set("docker-username", "test-user") cmd.Flags().Set("docker-username", "test-user")
......
...@@ -32,7 +32,7 @@ import ( ...@@ -32,7 +32,7 @@ import (
func TestCreateService(t *testing.T) { func TestCreateService(t *testing.T) {
service := &v1.Service{} service := &v1.Service{}
service.Name = "my-service" service.Name = "my-service"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -51,7 +51,6 @@ func TestCreateService(t *testing.T) { ...@@ -51,7 +51,6 @@ func TestCreateService(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdCreateServiceClusterIP(tf, ioStreams) cmd := NewCmdCreateServiceClusterIP(tf, ioStreams)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
...@@ -66,7 +65,7 @@ func TestCreateService(t *testing.T) { ...@@ -66,7 +65,7 @@ func TestCreateService(t *testing.T) {
func TestCreateServiceNodePort(t *testing.T) { func TestCreateServiceNodePort(t *testing.T) {
service := &v1.Service{} service := &v1.Service{}
service.Name = "my-node-port-service" service.Name = "my-node-port-service"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -85,7 +84,6 @@ func TestCreateServiceNodePort(t *testing.T) { ...@@ -85,7 +84,6 @@ func TestCreateServiceNodePort(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdCreateServiceNodePort(tf, ioStreams) cmd := NewCmdCreateServiceNodePort(tf, ioStreams)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
...@@ -100,7 +98,7 @@ func TestCreateServiceNodePort(t *testing.T) { ...@@ -100,7 +98,7 @@ func TestCreateServiceNodePort(t *testing.T) {
func TestCreateServiceExternalName(t *testing.T) { func TestCreateServiceExternalName(t *testing.T) {
service := &v1.Service{} service := &v1.Service{}
service.Name = "my-external-name-service" service.Name = "my-external-name-service"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -119,7 +117,6 @@ func TestCreateServiceExternalName(t *testing.T) { ...@@ -119,7 +117,6 @@ func TestCreateServiceExternalName(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdCreateServiceExternalName(tf, ioStreams) cmd := NewCmdCreateServiceExternalName(tf, ioStreams)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
......
...@@ -32,7 +32,7 @@ import ( ...@@ -32,7 +32,7 @@ import (
func TestCreateServiceAccount(t *testing.T) { func TestCreateServiceAccount(t *testing.T) {
serviceAccountObject := &v1.ServiceAccount{} serviceAccountObject := &v1.ServiceAccount{}
serviceAccountObject.Name = "my-service-account" serviceAccountObject.Name = "my-service-account"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -51,7 +51,6 @@ func TestCreateServiceAccount(t *testing.T) { ...@@ -51,7 +51,6 @@ func TestCreateServiceAccount(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdCreateServiceAccount(tf, ioStreams) cmd := NewCmdCreateServiceAccount(tf, ioStreams)
cmd.Flags().Set("output", "name") cmd.Flags().Set("output", "name")
......
...@@ -51,7 +51,7 @@ func TestCreateObject(t *testing.T) { ...@@ -51,7 +51,7 @@ func TestCreateObject(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
rc.Items[0].Name = "redis-master-controller" rc.Items[0].Name = "redis-master-controller"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -69,7 +69,6 @@ func TestCreateObject(t *testing.T) { ...@@ -69,7 +69,6 @@ func TestCreateObject(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdCreate(tf, ioStreams) cmd := NewCmdCreate(tf, ioStreams)
...@@ -87,7 +86,7 @@ func TestCreateMultipleObject(t *testing.T) { ...@@ -87,7 +86,7 @@ func TestCreateMultipleObject(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
_, svc, rc := testData() _, svc, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -107,7 +106,6 @@ func TestCreateMultipleObject(t *testing.T) { ...@@ -107,7 +106,6 @@ func TestCreateMultipleObject(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdCreate(tf, ioStreams) cmd := NewCmdCreate(tf, ioStreams)
...@@ -127,7 +125,7 @@ func TestCreateDirectory(t *testing.T) { ...@@ -127,7 +125,7 @@ func TestCreateDirectory(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
rc.Items[0].Name = "name" rc.Items[0].Name = "name"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -145,7 +143,6 @@ func TestCreateDirectory(t *testing.T) { ...@@ -145,7 +143,6 @@ func TestCreateDirectory(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdCreate(tf, ioStreams) cmd := NewCmdCreate(tf, ioStreams)
......
...@@ -146,7 +146,7 @@ func NewCmdDelete(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra ...@@ -146,7 +146,7 @@ func NewCmdDelete(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra
} }
func (o *DeleteOptions) Complete(f cmdutil.Factory, args []string, cmd *cobra.Command) error { func (o *DeleteOptions) Complete(f cmdutil.Factory, args []string, cmd *cobra.Command) error {
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -52,7 +52,7 @@ func TestDeleteObjectByTuple(t *testing.T) { ...@@ -52,7 +52,7 @@ func TestDeleteObjectByTuple(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -77,7 +77,6 @@ func TestDeleteObjectByTuple(t *testing.T) { ...@@ -77,7 +77,6 @@ func TestDeleteObjectByTuple(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
...@@ -118,7 +117,7 @@ func TestOrphanDependentsInDeleteObject(t *testing.T) { ...@@ -118,7 +117,7 @@ func TestOrphanDependentsInDeleteObject(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -137,7 +136,6 @@ func TestOrphanDependentsInDeleteObject(t *testing.T) { ...@@ -137,7 +136,6 @@ func TestOrphanDependentsInDeleteObject(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
// DeleteOptions.PropagationPolicy should be Foreground, when cascade is true (default). // DeleteOptions.PropagationPolicy should be Foreground, when cascade is true (default).
foregroundPolicy := metav1.DeletePropagationForeground foregroundPolicy := metav1.DeletePropagationForeground
...@@ -170,7 +168,7 @@ func TestDeleteNamedObject(t *testing.T) { ...@@ -170,7 +168,7 @@ func TestDeleteNamedObject(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -195,7 +193,6 @@ func TestDeleteNamedObject(t *testing.T) { ...@@ -195,7 +193,6 @@ func TestDeleteNamedObject(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
...@@ -223,7 +220,7 @@ func TestDeleteObject(t *testing.T) { ...@@ -223,7 +220,7 @@ func TestDeleteObject(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -240,7 +237,6 @@ func TestDeleteObject(t *testing.T) { ...@@ -240,7 +237,6 @@ func TestDeleteObject(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
...@@ -260,7 +256,7 @@ func TestDeleteObjectGraceZero(t *testing.T) { ...@@ -260,7 +256,7 @@ func TestDeleteObjectGraceZero(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
count := 0 count := 0
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -288,7 +284,6 @@ func TestDeleteObjectGraceZero(t *testing.T) { ...@@ -288,7 +284,6 @@ func TestDeleteObjectGraceZero(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, errBuf := genericclioptions.NewTestIOStreams() streams, _, buf, errBuf := genericclioptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
...@@ -307,7 +302,7 @@ func TestDeleteObjectGraceZero(t *testing.T) { ...@@ -307,7 +302,7 @@ func TestDeleteObjectGraceZero(t *testing.T) {
func TestDeleteObjectNotFound(t *testing.T) { func TestDeleteObjectNotFound(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -322,7 +317,6 @@ func TestDeleteObjectNotFound(t *testing.T) { ...@@ -322,7 +317,6 @@ func TestDeleteObjectNotFound(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
options := &DeleteOptions{ options := &DeleteOptions{
FilenameOptions: resource.FilenameOptions{ FilenameOptions: resource.FilenameOptions{
...@@ -345,7 +339,7 @@ func TestDeleteObjectNotFound(t *testing.T) { ...@@ -345,7 +339,7 @@ func TestDeleteObjectNotFound(t *testing.T) {
func TestDeleteObjectIgnoreNotFound(t *testing.T) { func TestDeleteObjectIgnoreNotFound(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -360,7 +354,6 @@ func TestDeleteObjectIgnoreNotFound(t *testing.T) { ...@@ -360,7 +354,6 @@ func TestDeleteObjectIgnoreNotFound(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
...@@ -382,7 +375,7 @@ func TestDeleteAllNotFound(t *testing.T) { ...@@ -382,7 +375,7 @@ func TestDeleteAllNotFound(t *testing.T) {
svc.Items = append(svc.Items, api.Service{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}) svc.Items = append(svc.Items, api.Service{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})
notFoundError := &errors.NewNotFound(api.Resource("services"), "foo").ErrStatus notFoundError := &errors.NewNotFound(api.Resource("services"), "foo").ErrStatus
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -403,7 +396,6 @@ func TestDeleteAllNotFound(t *testing.T) { ...@@ -403,7 +396,6 @@ func TestDeleteAllNotFound(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
// Make sure we can explicitly choose to fail on NotFound errors, even with --all // Make sure we can explicitly choose to fail on NotFound errors, even with --all
options := &DeleteOptions{ options := &DeleteOptions{
...@@ -429,7 +421,7 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) { ...@@ -429,7 +421,7 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
_, svc, _ := testData() _, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -454,7 +446,6 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) { ...@@ -454,7 +446,6 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
...@@ -472,7 +463,7 @@ func TestDeleteMultipleObject(t *testing.T) { ...@@ -472,7 +463,7 @@ func TestDeleteMultipleObject(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
_, svc, rc := testData() _, svc, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -491,7 +482,6 @@ func TestDeleteMultipleObject(t *testing.T) { ...@@ -491,7 +482,6 @@ func TestDeleteMultipleObject(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
...@@ -510,7 +500,7 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) { ...@@ -510,7 +500,7 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
_, svc, _ := testData() _, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -529,7 +519,6 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) { ...@@ -529,7 +519,6 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
options := &DeleteOptions{ options := &DeleteOptions{
...@@ -558,7 +547,7 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) { ...@@ -558,7 +547,7 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) {
func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) { func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
_, svc, rc := testData() _, svc, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -582,7 +571,6 @@ func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) { ...@@ -582,7 +571,6 @@ func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
...@@ -599,7 +587,7 @@ func TestDeleteDirectory(t *testing.T) { ...@@ -599,7 +587,7 @@ func TestDeleteDirectory(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -616,7 +604,6 @@ func TestDeleteDirectory(t *testing.T) { ...@@ -616,7 +604,6 @@ func TestDeleteDirectory(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
...@@ -634,7 +621,7 @@ func TestDeleteMultipleSelector(t *testing.T) { ...@@ -634,7 +621,7 @@ func TestDeleteMultipleSelector(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
pods, svc, _ := testData() pods, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -663,7 +650,6 @@ func TestDeleteMultipleSelector(t *testing.T) { ...@@ -663,7 +650,6 @@ func TestDeleteMultipleSelector(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdDelete(tf, streams) cmd := NewCmdDelete(tf, streams)
...@@ -703,10 +689,9 @@ func TestResourceErrors(t *testing.T) { ...@@ -703,10 +689,9 @@ func TestResourceErrors(t *testing.T) {
for k, testCase := range testCases { for k, testCase := range testCases {
t.Run(k, func(t *testing.T) { t.Run(k, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
......
...@@ -122,7 +122,7 @@ func NewCmdDescribe(parent string, f cmdutil.Factory, streams genericclioptions. ...@@ -122,7 +122,7 @@ func NewCmdDescribe(parent string, f cmdutil.Factory, streams genericclioptions.
func (o *DescribeOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error { func (o *DescribeOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
var err error var err error
o.Namespace, o.EnforceNamespace, err = f.DefaultNamespace() o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -41,7 +41,7 @@ func TestDescribeUnknownSchemaObject(t *testing.T) { ...@@ -41,7 +41,7 @@ func TestDescribeUnknownSchemaObject(t *testing.T) {
}() }()
cmdutil.DescriberFn = d.describerFor cmdutil.DescriberFn = d.describerFor
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("non-default")
defer tf.Cleanup() defer tf.Cleanup()
_, _, codec := cmdtesting.NewExternalScheme() _, _, codec := cmdtesting.NewExternalScheme()
...@@ -52,7 +52,6 @@ func TestDescribeUnknownSchemaObject(t *testing.T) { ...@@ -52,7 +52,6 @@ func TestDescribeUnknownSchemaObject(t *testing.T) {
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
tf.Namespace = "non-default"
cmd := NewCmdDescribe("kubectl", tf, streams) cmd := NewCmdDescribe("kubectl", tf, streams)
cmd.Run(cmd, []string{"type", "foo"}) cmd.Run(cmd, []string{"type", "foo"})
...@@ -82,7 +81,7 @@ func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) { ...@@ -82,7 +81,7 @@ func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) {
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, cmdtesting.NewInternalNamespacedType("", "", "foo", "non-default"))}, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, cmdtesting.NewInternalNamespacedType("", "", "foo", "non-default"))},
} }
tf.Namespace = "non-default" tf.WithNamespace("non-default")
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -107,7 +106,7 @@ func TestDescribeObject(t *testing.T) { ...@@ -107,7 +106,7 @@ func TestDescribeObject(t *testing.T) {
cmdutil.DescriberFn = d.describerFor cmdutil.DescriberFn = d.describerFor
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -123,7 +122,6 @@ func TestDescribeObject(t *testing.T) { ...@@ -123,7 +122,6 @@ func TestDescribeObject(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -149,7 +147,7 @@ func TestDescribeListObjects(t *testing.T) { ...@@ -149,7 +147,7 @@ func TestDescribeListObjects(t *testing.T) {
cmdutil.DescriberFn = d.describerFor cmdutil.DescriberFn = d.describerFor
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -160,7 +158,6 @@ func TestDescribeListObjects(t *testing.T) { ...@@ -160,7 +158,6 @@ func TestDescribeListObjects(t *testing.T) {
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
tf.Namespace = "test"
cmd := NewCmdDescribe("kubectl", tf, streams) cmd := NewCmdDescribe("kubectl", tf, streams)
cmd.Run(cmd, []string{"pods"}) cmd.Run(cmd, []string{"pods"})
if buf.String() != fmt.Sprintf("%s\n\n%s", d.Output, d.Output) { if buf.String() != fmt.Sprintf("%s\n\n%s", d.Output, d.Output) {
...@@ -177,7 +174,7 @@ func TestDescribeObjectShowEvents(t *testing.T) { ...@@ -177,7 +174,7 @@ func TestDescribeObjectShowEvents(t *testing.T) {
cmdutil.DescriberFn = d.describerFor cmdutil.DescriberFn = d.describerFor
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -186,7 +183,6 @@ func TestDescribeObjectShowEvents(t *testing.T) { ...@@ -186,7 +183,6 @@ func TestDescribeObjectShowEvents(t *testing.T) {
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)}, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)},
} }
tf.Namespace = "test"
cmd := NewCmdDescribe("kubectl", tf, genericclioptions.NewTestIOStreamsDiscard()) cmd := NewCmdDescribe("kubectl", tf, genericclioptions.NewTestIOStreamsDiscard())
cmd.Flags().Set("show-events", "true") cmd.Flags().Set("show-events", "true")
cmd.Run(cmd, []string{"pods"}) cmd.Run(cmd, []string{"pods"})
...@@ -204,7 +200,7 @@ func TestDescribeObjectSkipEvents(t *testing.T) { ...@@ -204,7 +200,7 @@ func TestDescribeObjectSkipEvents(t *testing.T) {
cmdutil.DescriberFn = d.describerFor cmdutil.DescriberFn = d.describerFor
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -213,7 +209,6 @@ func TestDescribeObjectSkipEvents(t *testing.T) { ...@@ -213,7 +209,6 @@ func TestDescribeObjectSkipEvents(t *testing.T) {
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)}, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)},
} }
tf.Namespace = "test"
cmd := NewCmdDescribe("kubectl", tf, genericclioptions.NewTestIOStreamsDiscard()) cmd := NewCmdDescribe("kubectl", tf, genericclioptions.NewTestIOStreamsDiscard())
cmd.Flags().Set("show-events", "false") cmd.Flags().Set("show-events", "false")
cmd.Run(cmd, []string{"pods"}) cmd.Run(cmd, []string{"pods"})
......
...@@ -407,7 +407,7 @@ func NewDownloader(f cmdutil.Factory) (*Downloader, error) { ...@@ -407,7 +407,7 @@ func NewDownloader(f cmdutil.Factory) (*Downloader, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
d.ns, _, _ = f.DefaultNamespace() d.ns, _, _ = f.ToRawKubeConfigLoader().Namespace()
return &d, nil return &d, nil
} }
...@@ -451,7 +451,7 @@ func RunDiff(f cmdutil.Factory, diff *DiffProgram, options *DiffOptions, from, t ...@@ -451,7 +451,7 @@ func RunDiff(f cmdutil.Factory, diff *DiffProgram, options *DiffOptions, from, t
printer := Printer{} printer := Printer{}
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -263,7 +263,7 @@ func (o *DrainOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st ...@@ -263,7 +263,7 @@ func (o *DrainOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
o.nodeInfos = []*resource.Info{} o.nodeInfos = []*resource.Info{}
o.Namespace, _, err = f.DefaultNamespace() o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -224,12 +224,8 @@ func TestEdit(t *testing.T) { ...@@ -224,12 +224,8 @@ func TestEdit(t *testing.T) {
Client: fake.CreateHTTPClient(reqResp), Client: fake.CreateHTTPClient(reqResp),
}, nil }, nil
} }
tf.WithNamespace(testcase.Namespace)
if len(testcase.Namespace) > 0 {
tf.Namespace = testcase.Namespace
}
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
tf.CommandVal = "edit test cmd invocation"
ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams() ioStreams, _, buf, errBuf := genericclioptions.NewTestIOStreams()
var cmd *cobra.Command var cmd *cobra.Command
......
...@@ -166,7 +166,7 @@ func (p *ExecOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, argsIn []s ...@@ -166,7 +166,7 @@ func (p *ExecOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, argsIn []s
} }
} }
namespace, _, err := f.DefaultNamespace() namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -132,7 +132,7 @@ func TestPodAndContainer(t *testing.T) { ...@@ -132,7 +132,7 @@ func TestPodAndContainer(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -141,7 +141,6 @@ func TestPodAndContainer(t *testing.T) { ...@@ -141,7 +141,6 @@ func TestPodAndContainer(t *testing.T) {
NegotiatedSerializer: ns, NegotiatedSerializer: ns,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { return nil, nil }), Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { return nil, nil }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
cmd := &cobra.Command{} cmd := &cobra.Command{}
...@@ -193,7 +192,7 @@ func TestExec(t *testing.T) { ...@@ -193,7 +192,7 @@ func TestExec(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -212,7 +211,6 @@ func TestExec(t *testing.T) { ...@@ -212,7 +211,6 @@ func TestExec(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ex := &fakeRemoteExecutor{} ex := &fakeRemoteExecutor{}
if test.execErr { if test.execErr {
......
...@@ -201,7 +201,7 @@ func (o *ExposeServiceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) e ...@@ -201,7 +201,7 @@ func (o *ExposeServiceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) e
return err return err
} }
o.Namespace, o.EnforceNamespace, err = f.DefaultNamespace() o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -467,7 +467,7 @@ func TestRunExposeService(t *testing.T) { ...@@ -467,7 +467,7 @@ func TestRunExposeService(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace(test.ns)
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -486,7 +486,6 @@ func TestRunExposeService(t *testing.T) { ...@@ -486,7 +486,6 @@ func TestRunExposeService(t *testing.T) {
} }
}), }),
} }
tf.Namespace = test.ns
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdExposeService(tf, ioStreams) cmd := NewCmdExposeService(tf, ioStreams)
......
...@@ -189,7 +189,7 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri ...@@ -189,7 +189,7 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
} }
var err error var err error
o.Namespace, o.ExplicitNamespace, err = f.DefaultNamespace() o.Namespace, o.ExplicitNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -172,7 +172,7 @@ func testComponentStatusData() *api.ComponentStatusList { ...@@ -172,7 +172,7 @@ func testComponentStatusData() *api.ComponentStatusList {
// Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get. // Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get.
func TestGetUnknownSchemaObject(t *testing.T) { func TestGetUnknownSchemaObject(t *testing.T) {
t.Skip("This test is completely broken. The first thing it does is add the object to the scheme!") t.Skip("This test is completely broken. The first thing it does is add the object to the scheme!")
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
_, _, codec := cmdtesting.NewExternalScheme() _, _, codec := cmdtesting.NewExternalScheme()
tf.OpenAPISchemaFunc = openapitesting.CreateOpenAPISchemaFunc(openapiSchemaPath) tf.OpenAPISchemaFunc = openapitesting.CreateOpenAPISchemaFunc(openapiSchemaPath)
...@@ -190,7 +190,6 @@ func TestGetUnknownSchemaObject(t *testing.T) { ...@@ -190,7 +190,6 @@ func TestGetUnknownSchemaObject(t *testing.T) {
Body: objBody(codec, obj), Body: objBody(codec, obj),
}, },
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -225,7 +224,7 @@ func TestGetUnknownSchemaObject(t *testing.T) { ...@@ -225,7 +224,7 @@ func TestGetUnknownSchemaObject(t *testing.T) {
// Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get. // Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get.
func TestGetSchemaObject(t *testing.T) { func TestGetSchemaObject(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(schema.GroupVersion{Version: "v1"}) codec := legacyscheme.Codecs.LegacyCodec(schema.GroupVersion{Version: "v1"})
t.Logf("%v", string(runtime.EncodeOrDie(codec, &api.ReplicationController{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}))) t.Logf("%v", string(runtime.EncodeOrDie(codec, &api.ReplicationController{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})))
...@@ -234,7 +233,6 @@ func TestGetSchemaObject(t *testing.T) { ...@@ -234,7 +233,6 @@ func TestGetSchemaObject(t *testing.T) {
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &api.ReplicationController{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})}, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &api.ReplicationController{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})},
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -249,7 +247,7 @@ func TestGetSchemaObject(t *testing.T) { ...@@ -249,7 +247,7 @@ func TestGetSchemaObject(t *testing.T) {
func TestGetObjectsWithOpenAPIOutputFormatPresent(t *testing.T) { func TestGetObjectsWithOpenAPIOutputFormatPresent(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -260,7 +258,6 @@ func TestGetObjectsWithOpenAPIOutputFormatPresent(t *testing.T) { ...@@ -260,7 +258,6 @@ func TestGetObjectsWithOpenAPIOutputFormatPresent(t *testing.T) {
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])}, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -306,7 +303,7 @@ func testOpenAPISchemaData() (openapi.Resources, error) { ...@@ -306,7 +303,7 @@ func testOpenAPISchemaData() (openapi.Resources, error) {
func TestGetObjects(t *testing.T) { func TestGetObjects(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -314,7 +311,6 @@ func TestGetObjects(t *testing.T) { ...@@ -314,7 +311,6 @@ func TestGetObjects(t *testing.T) {
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])}, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -332,7 +328,7 @@ foo 0/0 0 <unknown> ...@@ -332,7 +328,7 @@ foo 0/0 0 <unknown>
func TestGetObjectsShowKind(t *testing.T) { func TestGetObjectsShowKind(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -340,7 +336,6 @@ func TestGetObjectsShowKind(t *testing.T) { ...@@ -340,7 +336,6 @@ func TestGetObjectsShowKind(t *testing.T) {
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])}, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -359,7 +354,7 @@ pod/foo 0/0 0 <unknown> ...@@ -359,7 +354,7 @@ pod/foo 0/0 0 <unknown>
func TestGetObjectsShowLabels(t *testing.T) { func TestGetObjectsShowLabels(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -367,7 +362,6 @@ func TestGetObjectsShowLabels(t *testing.T) { ...@@ -367,7 +362,6 @@ func TestGetObjectsShowLabels(t *testing.T) {
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])}, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -398,7 +392,7 @@ func TestGetObjectIgnoreNotFound(t *testing.T) { ...@@ -398,7 +392,7 @@ func TestGetObjectIgnoreNotFound(t *testing.T) {
}, },
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -416,7 +410,6 @@ func TestGetObjectIgnoreNotFound(t *testing.T) { ...@@ -416,7 +410,6 @@ func TestGetObjectIgnoreNotFound(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -451,7 +444,7 @@ func TestGetSortedObjects(t *testing.T) { ...@@ -451,7 +444,7 @@ func TestGetSortedObjects(t *testing.T) {
}, },
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -459,7 +452,6 @@ func TestGetSortedObjects(t *testing.T) { ...@@ -459,7 +452,6 @@ func TestGetSortedObjects(t *testing.T) {
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)}, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)},
} }
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: "v1"}}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: "v1"}}}
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -483,7 +475,7 @@ c 0/0 0 <unknown> ...@@ -483,7 +475,7 @@ c 0/0 0 <unknown>
func TestGetObjectsIdentifiedByFile(t *testing.T) { func TestGetObjectsIdentifiedByFile(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -491,7 +483,6 @@ func TestGetObjectsIdentifiedByFile(t *testing.T) { ...@@ -491,7 +483,6 @@ func TestGetObjectsIdentifiedByFile(t *testing.T) {
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])}, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -510,7 +501,7 @@ foo 0/0 0 <unknown> ...@@ -510,7 +501,7 @@ foo 0/0 0 <unknown>
func TestGetListObjects(t *testing.T) { func TestGetListObjects(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -518,7 +509,6 @@ func TestGetListObjects(t *testing.T) { ...@@ -518,7 +509,6 @@ func TestGetListObjects(t *testing.T) {
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)}, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)},
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -537,7 +527,7 @@ bar 0/0 0 <unknown> ...@@ -537,7 +527,7 @@ bar 0/0 0 <unknown>
func TestGetListComponentStatus(t *testing.T) { func TestGetListComponentStatus(t *testing.T) {
statuses := testComponentStatusData() statuses := testComponentStatusData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -545,7 +535,6 @@ func TestGetListComponentStatus(t *testing.T) { ...@@ -545,7 +535,6 @@ func TestGetListComponentStatus(t *testing.T) {
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, statuses)}, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, statuses)},
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -578,7 +567,7 @@ func TestGetMixedGenericObjects(t *testing.T) { ...@@ -578,7 +567,7 @@ func TestGetMixedGenericObjects(t *testing.T) {
Code: 0, Code: 0,
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -594,7 +583,6 @@ func TestGetMixedGenericObjects(t *testing.T) { ...@@ -594,7 +583,6 @@ func TestGetMixedGenericObjects(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -628,7 +616,7 @@ func TestGetMixedGenericObjects(t *testing.T) { ...@@ -628,7 +616,7 @@ func TestGetMixedGenericObjects(t *testing.T) {
func TestGetMultipleTypeObjects(t *testing.T) { func TestGetMultipleTypeObjects(t *testing.T) {
pods, svc, _ := testData() pods, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -646,7 +634,6 @@ func TestGetMultipleTypeObjects(t *testing.T) { ...@@ -646,7 +634,6 @@ func TestGetMultipleTypeObjects(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -667,7 +654,7 @@ service/baz ClusterIP <none> <none> <none> <unknown> ...@@ -667,7 +654,7 @@ service/baz ClusterIP <none> <none> <none> <unknown>
func TestGetMultipleTypeObjectsAsList(t *testing.T) { func TestGetMultipleTypeObjectsAsList(t *testing.T) {
pods, svc, _ := testData() pods, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -685,7 +672,6 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) { ...@@ -685,7 +672,6 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -767,7 +753,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) { ...@@ -767,7 +753,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
func TestGetMultipleTypeObjectsWithLabelSelector(t *testing.T) { func TestGetMultipleTypeObjectsWithLabelSelector(t *testing.T) {
pods, svc, _ := testData() pods, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -788,7 +774,6 @@ func TestGetMultipleTypeObjectsWithLabelSelector(t *testing.T) { ...@@ -788,7 +774,6 @@ func TestGetMultipleTypeObjectsWithLabelSelector(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -811,7 +796,7 @@ service/baz ClusterIP <none> <none> <none> <unknown> ...@@ -811,7 +796,7 @@ service/baz ClusterIP <none> <none> <none> <unknown>
func TestGetMultipleTypeObjectsWithFieldSelector(t *testing.T) { func TestGetMultipleTypeObjectsWithFieldSelector(t *testing.T) {
pods, svc, _ := testData() pods, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -832,7 +817,6 @@ func TestGetMultipleTypeObjectsWithFieldSelector(t *testing.T) { ...@@ -832,7 +817,6 @@ func TestGetMultipleTypeObjectsWithFieldSelector(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -860,7 +844,7 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) { ...@@ -860,7 +844,7 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) {
}, },
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -878,7 +862,6 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) { ...@@ -878,7 +862,6 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -969,7 +952,7 @@ func watchTestData() ([]api.Pod, []watch.Event) { ...@@ -969,7 +952,7 @@ func watchTestData() ([]api.Pod, []watch.Event) {
func TestWatchLabelSelector(t *testing.T) { func TestWatchLabelSelector(t *testing.T) {
pods, events := watchTestData() pods, events := watchTestData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -997,7 +980,6 @@ func TestWatchLabelSelector(t *testing.T) { ...@@ -997,7 +980,6 @@ func TestWatchLabelSelector(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -1021,7 +1003,7 @@ foo 0/0 0 <unknown> ...@@ -1021,7 +1003,7 @@ foo 0/0 0 <unknown>
func TestWatchFieldSelector(t *testing.T) { func TestWatchFieldSelector(t *testing.T) {
pods, events := watchTestData() pods, events := watchTestData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -1049,7 +1031,6 @@ func TestWatchFieldSelector(t *testing.T) { ...@@ -1049,7 +1031,6 @@ func TestWatchFieldSelector(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -1073,7 +1054,7 @@ foo 0/0 0 <unknown> ...@@ -1073,7 +1054,7 @@ foo 0/0 0 <unknown>
func TestWatchResource(t *testing.T) { func TestWatchResource(t *testing.T) {
pods, events := watchTestData() pods, events := watchTestData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -1095,7 +1076,6 @@ func TestWatchResource(t *testing.T) { ...@@ -1095,7 +1076,6 @@ func TestWatchResource(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -1117,7 +1097,7 @@ foo 0/0 0 <unknown> ...@@ -1117,7 +1097,7 @@ foo 0/0 0 <unknown>
func TestWatchResourceIdentifiedByFile(t *testing.T) { func TestWatchResourceIdentifiedByFile(t *testing.T) {
pods, events := watchTestData() pods, events := watchTestData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -1139,7 +1119,6 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) { ...@@ -1139,7 +1119,6 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -1162,7 +1141,7 @@ foo 0/0 0 <unknown> ...@@ -1162,7 +1141,7 @@ foo 0/0 0 <unknown>
func TestWatchOnlyResource(t *testing.T) { func TestWatchOnlyResource(t *testing.T) {
pods, events := watchTestData() pods, events := watchTestData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -1184,7 +1163,6 @@ func TestWatchOnlyResource(t *testing.T) { ...@@ -1184,7 +1163,6 @@ func TestWatchOnlyResource(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
...@@ -1205,7 +1183,7 @@ foo 0/0 0 <unknown> ...@@ -1205,7 +1183,7 @@ foo 0/0 0 <unknown>
func TestWatchOnlyList(t *testing.T) { func TestWatchOnlyList(t *testing.T) {
pods, events := watchTestData() pods, events := watchTestData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -1230,7 +1208,6 @@ func TestWatchOnlyList(t *testing.T) { ...@@ -1230,7 +1208,6 @@ func TestWatchOnlyList(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdGet("kubectl", tf, streams) cmd := NewCmdGet("kubectl", tf, streams)
......
...@@ -188,7 +188,7 @@ func (o *LabelOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st ...@@ -188,7 +188,7 @@ func (o *LabelOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
return fmt.Errorf("--list and --output may not be specified together") return fmt.Errorf("--list and --output may not be specified together")
} }
o.namespace, o.enforceNamespace, err = f.DefaultNamespace() o.namespace, o.enforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -322,10 +322,9 @@ func TestLabelErrors(t *testing.T) { ...@@ -322,10 +322,9 @@ func TestLabelErrors(t *testing.T) {
for k, testCase := range testCases { for k, testCase := range testCases {
t.Run(k, func(t *testing.T) { t.Run(k, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() ioStreams, _, _, _ := genericclioptions.NewTestIOStreams()
...@@ -357,7 +356,7 @@ func TestLabelErrors(t *testing.T) { ...@@ -357,7 +356,7 @@ func TestLabelErrors(t *testing.T) {
func TestLabelForResourceFromFile(t *testing.T) { func TestLabelForResourceFromFile(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -388,7 +387,6 @@ func TestLabelForResourceFromFile(t *testing.T) { ...@@ -388,7 +387,6 @@ func TestLabelForResourceFromFile(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -411,7 +409,7 @@ func TestLabelForResourceFromFile(t *testing.T) { ...@@ -411,7 +409,7 @@ func TestLabelForResourceFromFile(t *testing.T) {
} }
func TestLabelLocal(t *testing.T) { func TestLabelLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -421,7 +419,6 @@ func TestLabelLocal(t *testing.T) { ...@@ -421,7 +419,6 @@ func TestLabelLocal(t *testing.T) {
return nil, nil return nil, nil
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -446,7 +443,7 @@ func TestLabelLocal(t *testing.T) { ...@@ -446,7 +443,7 @@ func TestLabelLocal(t *testing.T) {
func TestLabelMultipleObjects(t *testing.T) { func TestLabelMultipleObjects(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -479,7 +476,6 @@ func TestLabelMultipleObjects(t *testing.T) { ...@@ -479,7 +476,6 @@ func TestLabelMultipleObjects(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams()
......
...@@ -156,7 +156,7 @@ func (o *LogsOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []str ...@@ -156,7 +156,7 @@ func (o *LogsOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []str
return cmdutil.UsageErrorf(cmd, "%s", logsUsageStr) return cmdutil.UsageErrorf(cmd, "%s", logsUsageStr)
} }
var err error var err error
o.Namespace, _, err = f.DefaultNamespace() o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -58,7 +58,7 @@ func TestLog(t *testing.T) { ...@@ -58,7 +58,7 @@ func TestLog(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
logContent := "test log content" logContent := "test log content"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -80,7 +80,6 @@ func TestLog(t *testing.T) { ...@@ -80,7 +80,6 @@ func TestLog(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
oldLogFn := polymorphichelpers.LogsForObjectFn oldLogFn := polymorphichelpers.LogsForObjectFn
defer func() { defer func() {
...@@ -123,6 +122,7 @@ func testPod() *api.Pod { ...@@ -123,6 +122,7 @@ func testPod() *api.Pod {
func TestValidateLogFlags(t *testing.T) { func TestValidateLogFlags(t *testing.T) {
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup() defer f.Cleanup()
f.WithNamespace("")
tests := []struct { tests := []struct {
name string name string
......
...@@ -152,7 +152,7 @@ func (o *PatchOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st ...@@ -152,7 +152,7 @@ func (o *PatchOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
return o.PrintFlags.ToPrinter() return o.PrintFlags.ToPrinter()
} }
o.namespace, o.enforceNamespace, err = f.DefaultNamespace() o.namespace, o.enforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -31,7 +31,7 @@ import ( ...@@ -31,7 +31,7 @@ import (
func TestPatchObject(t *testing.T) { func TestPatchObject(t *testing.T) {
_, svc, _ := testData() _, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -55,7 +55,6 @@ func TestPatchObject(t *testing.T) { ...@@ -55,7 +55,6 @@ func TestPatchObject(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
stream, _, buf, _ := genericclioptions.NewTestIOStreams() stream, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdPatch(tf, stream) cmd := NewCmdPatch(tf, stream)
...@@ -73,7 +72,7 @@ func TestPatchObject(t *testing.T) { ...@@ -73,7 +72,7 @@ func TestPatchObject(t *testing.T) {
func TestPatchObjectFromFile(t *testing.T) { func TestPatchObjectFromFile(t *testing.T) {
_, svc, _ := testData() _, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -90,7 +89,6 @@ func TestPatchObjectFromFile(t *testing.T) { ...@@ -90,7 +89,6 @@ func TestPatchObjectFromFile(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
stream, _, buf, _ := genericclioptions.NewTestIOStreams() stream, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdPatch(tf, stream) cmd := NewCmdPatch(tf, stream)
...@@ -111,7 +109,7 @@ func TestPatchNoop(t *testing.T) { ...@@ -111,7 +109,7 @@ func TestPatchNoop(t *testing.T) {
getObject := &svc.Items[0] getObject := &svc.Items[0]
patchObject := &svc.Items[0] patchObject := &svc.Items[0]
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -130,7 +128,6 @@ func TestPatchNoop(t *testing.T) { ...@@ -130,7 +128,6 @@ func TestPatchNoop(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
// Patched // Patched
{ {
...@@ -159,7 +156,7 @@ func TestPatchObjectFromFileOutput(t *testing.T) { ...@@ -159,7 +156,7 @@ func TestPatchObjectFromFileOutput(t *testing.T) {
} }
svcCopy.Labels["post-patch"] = "post-patch-value" svcCopy.Labels["post-patch"] = "post-patch-value"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -178,7 +175,6 @@ func TestPatchObjectFromFileOutput(t *testing.T) { ...@@ -178,7 +175,6 @@ func TestPatchObjectFromFileOutput(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
stream, _, buf, _ := genericclioptions.NewTestIOStreams() stream, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdPatch(tf, stream) cmd := NewCmdPatch(tf, stream)
......
...@@ -158,7 +158,7 @@ type factoryAttrsPluginEnvProvider struct { ...@@ -158,7 +158,7 @@ type factoryAttrsPluginEnvProvider struct {
} }
func (p *factoryAttrsPluginEnvProvider) Env() (plugins.EnvList, error) { func (p *factoryAttrsPluginEnvProvider) Env() (plugins.EnvList, error) {
cmdNamespace, _, err := p.factory.DefaultNamespace() cmdNamespace, _, err := p.factory.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return plugins.EnvList{}, err return plugins.EnvList{}, err
} }
......
...@@ -174,7 +174,7 @@ func (o *PortForwardOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, arg ...@@ -174,7 +174,7 @@ func (o *PortForwardOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, arg
return cmdutil.UsageErrorf(cmd, "TYPE/NAME and list of ports are required for port-forward") return cmdutil.UsageErrorf(cmd, "TYPE/NAME and list of ports are required for port-forward")
} }
o.Namespace, _, err = f.DefaultNamespace() o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -73,7 +73,7 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) { ...@@ -73,7 +73,7 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
var err error var err error
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -94,7 +94,6 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) { ...@@ -94,7 +94,6 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
ff := &fakePortForwarder{} ff := &fakePortForwarder{}
if test.pfErr { if test.pfErr {
......
...@@ -179,7 +179,7 @@ func (o *ReplaceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [] ...@@ -179,7 +179,7 @@ func (o *ReplaceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
o.Builder = f.NewBuilder o.Builder = f.NewBuilder
o.BuilderArgs = args o.BuilderArgs = args
o.Namespace, o.EnforceNamespace, err = f.DefaultNamespace() o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -32,7 +32,7 @@ import ( ...@@ -32,7 +32,7 @@ import (
func TestReplaceObject(t *testing.T) { func TestReplaceObject(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -62,7 +62,6 @@ func TestReplaceObject(t *testing.T) { ...@@ -62,7 +62,6 @@ func TestReplaceObject(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdReplace(tf, streams) cmd := NewCmdReplace(tf, streams)
...@@ -89,7 +88,7 @@ func TestReplaceObject(t *testing.T) { ...@@ -89,7 +88,7 @@ func TestReplaceObject(t *testing.T) {
func TestReplaceMultipleObject(t *testing.T) { func TestReplaceMultipleObject(t *testing.T) {
_, svc, rc := testData() _, svc, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -133,7 +132,6 @@ func TestReplaceMultipleObject(t *testing.T) { ...@@ -133,7 +132,6 @@ func TestReplaceMultipleObject(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdReplace(tf, streams) cmd := NewCmdReplace(tf, streams)
...@@ -160,7 +158,7 @@ func TestReplaceMultipleObject(t *testing.T) { ...@@ -160,7 +158,7 @@ func TestReplaceMultipleObject(t *testing.T) {
func TestReplaceDirectory(t *testing.T) { func TestReplaceDirectory(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -191,7 +189,6 @@ func TestReplaceDirectory(t *testing.T) { ...@@ -191,7 +189,6 @@ func TestReplaceDirectory(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdReplace(tf, streams) cmd := NewCmdReplace(tf, streams)
...@@ -218,7 +215,7 @@ func TestReplaceDirectory(t *testing.T) { ...@@ -218,7 +215,7 @@ func TestReplaceDirectory(t *testing.T) {
func TestForceReplaceObjectNotFound(t *testing.T) { func TestForceReplaceObjectNotFound(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -238,7 +235,6 @@ func TestForceReplaceObjectNotFound(t *testing.T) { ...@@ -238,7 +235,6 @@ func TestForceReplaceObjectNotFound(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdReplace(tf, streams) cmd := NewCmdReplace(tf, streams)
......
...@@ -209,7 +209,7 @@ func (o *RollingUpdateOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, a ...@@ -209,7 +209,7 @@ func (o *RollingUpdateOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, a
} }
var err error var err error
o.Namespace, o.EnforceNamespace, err = f.DefaultNamespace() o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -74,7 +74,7 @@ func RunHistory(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, args []str ...@@ -74,7 +74,7 @@ func RunHistory(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, args []str
return fmt.Errorf("revision must be a positive integer: %v", revision) return fmt.Errorf("revision must be a positive integer: %v", revision)
} }
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -104,7 +104,7 @@ func (o *PauseConfig) CompletePause(f cmdutil.Factory, cmd *cobra.Command, args ...@@ -104,7 +104,7 @@ func (o *PauseConfig) CompletePause(f cmdutil.Factory, cmd *cobra.Command, args
o.Pauser = polymorphichelpers.ObjectPauserFn o.Pauser = polymorphichelpers.ObjectPauserFn
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -40,7 +40,7 @@ var rolloutPauseGroupVersionDecoder = schema.GroupVersion{Group: "extensions", V ...@@ -40,7 +40,7 @@ var rolloutPauseGroupVersionDecoder = schema.GroupVersion{Group: "extensions", V
func TestRolloutPause(t *testing.T) { func TestRolloutPause(t *testing.T) {
deploymentName := "deployment/nginx-deployment" deploymentName := "deployment/nginx-deployment"
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
info, _ := runtime.SerializerInfoForMediaType(ns.SupportedMediaTypes(), runtime.ContentTypeJSON) info, _ := runtime.SerializerInfoForMediaType(ns.SupportedMediaTypes(), runtime.ContentTypeJSON)
encoder := ns.EncoderForVersion(info.Serializer, rolloutPauseGroupVersionEncoder) encoder := ns.EncoderForVersion(info.Serializer, rolloutPauseGroupVersionEncoder)
...@@ -62,7 +62,6 @@ func TestRolloutPause(t *testing.T) { ...@@ -62,7 +62,6 @@ func TestRolloutPause(t *testing.T) {
}, },
} }
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdRolloutPause(tf, streams) cmd := NewCmdRolloutPause(tf, streams)
......
...@@ -102,7 +102,7 @@ func (o *ResumeConfig) CompleteResume(f cmdutil.Factory, cmd *cobra.Command, arg ...@@ -102,7 +102,7 @@ func (o *ResumeConfig) CompleteResume(f cmdutil.Factory, cmd *cobra.Command, arg
o.Resumer = polymorphichelpers.ObjectResumerFn o.Resumer = polymorphichelpers.ObjectResumerFn
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -104,7 +104,7 @@ func (o *RolloutStatusOptions) Complete(f cmdutil.Factory, args []string) error ...@@ -104,7 +104,7 @@ func (o *RolloutStatusOptions) Complete(f cmdutil.Factory, args []string) error
o.Builder = f.NewBuilder() o.Builder = f.NewBuilder()
var err error var err error
o.Namespace, o.EnforceNamespace, err = f.DefaultNamespace() o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -109,7 +109,7 @@ func (o *UndoOptions) CompleteUndo(f cmdutil.Factory, cmd *cobra.Command, out io ...@@ -109,7 +109,7 @@ func (o *UndoOptions) CompleteUndo(f cmdutil.Factory, cmd *cobra.Command, out io
o.Out = out o.Out = out
o.DryRun = cmdutil.GetDryRunFlag(cmd) o.DryRun = cmdutil.GetDryRunFlag(cmd)
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -265,7 +265,7 @@ func (o *RunOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e ...@@ -265,7 +265,7 @@ func (o *RunOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
return cmdutil.UsageErrorf(cmd, "--port must be set when exposing a service") return cmdutil.UsageErrorf(cmd, "--port must be set when exposing a service")
} }
namespace, _, err := f.DefaultNamespace() namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -170,7 +170,7 @@ func TestRunArgsFollowDashRules(t *testing.T) { ...@@ -170,7 +170,7 @@ func TestRunArgsFollowDashRules(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -190,7 +190,6 @@ func TestRunArgsFollowDashRules(t *testing.T) { ...@@ -190,7 +190,6 @@ func TestRunArgsFollowDashRules(t *testing.T) {
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{} tf.ClientConfigVal = &restclient.Config{}
cmd := NewCmdRun(tf, genericclioptions.NewTestIOStreamsDiscard()) cmd := NewCmdRun(tf, genericclioptions.NewTestIOStreamsDiscard())
...@@ -505,7 +504,7 @@ func TestRunValidations(t *testing.T) { ...@@ -505,7 +504,7 @@ func TestRunValidations(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
_, _, codec := cmdtesting.NewExternalScheme() _, _, codec := cmdtesting.NewExternalScheme()
...@@ -513,7 +512,6 @@ func TestRunValidations(t *testing.T) { ...@@ -513,7 +512,6 @@ func TestRunValidations(t *testing.T) {
NegotiatedSerializer: scheme.Codecs, NegotiatedSerializer: scheme.Codecs,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, cmdtesting.NewInternalType("", "", ""))}, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, cmdtesting.NewInternalType("", "", ""))},
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, _, bufErr := genericclioptions.NewTestIOStreams() streams, _, _, bufErr := genericclioptions.NewTestIOStreams()
......
...@@ -156,7 +156,7 @@ func (o *ScaleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st ...@@ -156,7 +156,7 @@ func (o *ScaleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
} }
o.PrintObj = printer.PrintObj o.PrintObj = printer.PrintObj
o.namespace, o.enforceNamespace, err = f.DefaultNamespace() o.namespace, o.enforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -233,7 +233,7 @@ func (o *EnvOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri ...@@ -233,7 +233,7 @@ func (o *EnvOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
if err != nil { if err != nil {
return err return err
} }
o.namespace, o.enforceNamespace, err = f.DefaultNamespace() o.namespace, o.enforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -45,7 +45,7 @@ import ( ...@@ -45,7 +45,7 @@ import (
) )
func TestSetEnvLocal(t *testing.T) { func TestSetEnvLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -56,7 +56,6 @@ func TestSetEnvLocal(t *testing.T) { ...@@ -56,7 +56,6 @@ func TestSetEnvLocal(t *testing.T) {
return nil, nil return nil, nil
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}}
outputFormat := "name" outputFormat := "name"
...@@ -83,7 +82,7 @@ func TestSetEnvLocal(t *testing.T) { ...@@ -83,7 +82,7 @@ func TestSetEnvLocal(t *testing.T) {
} }
func TestSetMultiResourcesEnvLocal(t *testing.T) { func TestSetMultiResourcesEnvLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -94,7 +93,6 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) { ...@@ -94,7 +93,6 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
return nil, nil return nil, nil
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}}
outputFormat := "name" outputFormat := "name"
...@@ -447,16 +445,15 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -447,16 +445,15 @@ func TestSetEnvRemote(t *testing.T) {
t.Run(input.name, func(t *testing.T) { t.Run(input.name, func(t *testing.T) {
groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion} groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion}
testapi.Default = testapi.Groups[input.testAPIGroup] testapi.Default = testapi.Groups[input.testAPIGroup]
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}}
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
GroupVersion: groupVersion, GroupVersion: groupVersion,
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs}, NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
resourcePath := testapi.Default.ResourcePath(input.args[0]+"s", tf.Namespace, input.args[1]) resourcePath := testapi.Default.ResourcePath(input.args[0]+"s", "test", input.args[1])
switch p, m := req.URL.Path, req.Method; { switch p, m := req.URL.Path, req.Method; {
case p == resourcePath && m == http.MethodGet: case p == resourcePath && m == http.MethodGet:
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(input.object)}, nil return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(input.object)}, nil
...@@ -585,10 +582,9 @@ func TestSetEnvFromResource(t *testing.T) { ...@@ -585,10 +582,9 @@ func TestSetEnvFromResource(t *testing.T) {
}, },
} }
t.Run(input.name, func(t *testing.T) { t.Run(input.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}}
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Group: "", Version: "v1"}, GroupVersion: schema.GroupVersion{Group: "", Version: "v1"},
......
...@@ -150,7 +150,7 @@ func (o *SetImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [ ...@@ -150,7 +150,7 @@ func (o *SetImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
o.PrintObj = printer.PrintObj o.PrintObj = printer.PrintObj
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -46,7 +46,7 @@ import ( ...@@ -46,7 +46,7 @@ import (
) )
func TestImageLocal(t *testing.T) { func TestImageLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -57,7 +57,6 @@ func TestImageLocal(t *testing.T) { ...@@ -57,7 +57,6 @@ func TestImageLocal(t *testing.T) {
return nil, nil return nil, nil
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}}
outputFormat := "name" outputFormat := "name"
...@@ -159,7 +158,7 @@ func TestSetImageValidation(t *testing.T) { ...@@ -159,7 +158,7 @@ func TestSetImageValidation(t *testing.T) {
} }
func TestSetMultiResourcesImageLocal(t *testing.T) { func TestSetMultiResourcesImageLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -170,7 +169,6 @@ func TestSetMultiResourcesImageLocal(t *testing.T) { ...@@ -170,7 +169,6 @@ func TestSetMultiResourcesImageLocal(t *testing.T) {
return nil, nil return nil, nil
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}}
outputFormat := "name" outputFormat := "name"
...@@ -532,15 +530,14 @@ func TestSetImageRemote(t *testing.T) { ...@@ -532,15 +530,14 @@ func TestSetImageRemote(t *testing.T) {
t.Run(input.name, func(t *testing.T) { t.Run(input.name, func(t *testing.T) {
groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion} groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion}
testapi.Default = testapi.Groups[input.testAPIGroup] testapi.Default = testapi.Groups[input.testAPIGroup]
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
GroupVersion: groupVersion, GroupVersion: groupVersion,
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs}, NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
resourcePath := testapi.Default.ResourcePath(input.args[0]+"s", tf.Namespace, input.args[1]) resourcePath := testapi.Default.ResourcePath(input.args[0]+"s", "test", input.args[1])
switch p, m := req.URL.Path, req.Method; { switch p, m := req.URL.Path, req.Method; {
case p == resourcePath && m == http.MethodGet: case p == resourcePath && m == http.MethodGet:
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(input.object)}, nil return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(input.object)}, nil
......
...@@ -160,7 +160,7 @@ func (o *SetResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, ar ...@@ -160,7 +160,7 @@ func (o *SetResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, ar
} }
o.PrintObj = printer.PrintObj o.PrintObj = printer.PrintObj
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -45,7 +45,7 @@ import ( ...@@ -45,7 +45,7 @@ import (
) )
func TestResourcesLocal(t *testing.T) { func TestResourcesLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -56,7 +56,6 @@ func TestResourcesLocal(t *testing.T) { ...@@ -56,7 +56,6 @@ func TestResourcesLocal(t *testing.T) {
return nil, nil return nil, nil
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}}
outputFormat := "name" outputFormat := "name"
...@@ -94,7 +93,7 @@ func TestResourcesLocal(t *testing.T) { ...@@ -94,7 +93,7 @@ func TestResourcesLocal(t *testing.T) {
} }
func TestSetMultiResourcesLimitsLocal(t *testing.T) { func TestSetMultiResourcesLimitsLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -105,7 +104,6 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) { ...@@ -105,7 +104,6 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) {
return nil, nil return nil, nil
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}}
outputFormat := "name" outputFormat := "name"
...@@ -455,15 +453,14 @@ func TestSetResourcesRemote(t *testing.T) { ...@@ -455,15 +453,14 @@ func TestSetResourcesRemote(t *testing.T) {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion} groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion}
testapi.Default = testapi.Groups[input.testAPIGroup] testapi.Default = testapi.Groups[input.testAPIGroup]
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
GroupVersion: groupVersion, GroupVersion: groupVersion,
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs}, NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
resourcePath := testapi.Default.ResourcePath(input.args[0]+"s", tf.Namespace, input.args[1]) resourcePath := testapi.Default.ResourcePath(input.args[0]+"s", "test", input.args[1])
switch p, m := req.URL.Path, req.Method; { switch p, m := req.URL.Path, req.Method; {
case p == resourcePath && m == http.MethodGet: case p == resourcePath && m == http.MethodGet:
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(input.object)}, nil return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(input.object)}, nil
......
...@@ -132,7 +132,7 @@ func (o *SetSelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, arg ...@@ -132,7 +132,7 @@ func (o *SetSelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, arg
o.dryrun = cmdutil.GetDryRunFlag(cmd) o.dryrun = cmdutil.GetDryRunFlag(cmd)
o.output = cmdutil.GetFlagString(cmd, "output") o.output = cmdutil.GetFlagString(cmd, "output")
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -317,7 +317,7 @@ func TestGetResourcesAndSelector(t *testing.T) { ...@@ -317,7 +317,7 @@ func TestGetResourcesAndSelector(t *testing.T) {
} }
func TestSelectorTest(t *testing.T) { func TestSelectorTest(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -328,7 +328,6 @@ func TestSelectorTest(t *testing.T) { ...@@ -328,7 +328,6 @@ func TestSelectorTest(t *testing.T) {
return nil, nil return nil, nil
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}}
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
......
...@@ -141,7 +141,7 @@ func (o *SetServiceAccountOptions) Complete(f cmdutil.Factory, cmd *cobra.Comman ...@@ -141,7 +141,7 @@ func (o *SetServiceAccountOptions) Complete(f cmdutil.Factory, cmd *cobra.Comman
} }
o.PrintObj = printer.PrintObj o.PrintObj = printer.PrintObj
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -68,7 +68,7 @@ func TestSetServiceAccountLocal(t *testing.T) { ...@@ -68,7 +68,7 @@ func TestSetServiceAccountLocal(t *testing.T) {
for i, input := range inputs { for i, input := range inputs {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -81,7 +81,6 @@ func TestSetServiceAccountLocal(t *testing.T) { ...@@ -81,7 +81,6 @@ func TestSetServiceAccountLocal(t *testing.T) {
outputFormat := "yaml" outputFormat := "yaml"
tf.Namespace = "test"
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdServiceAccount(tf, streams) cmd := NewCmdServiceAccount(tf, streams)
cmd.Flags().Set("output", outputFormat) cmd.Flags().Set("output", outputFormat)
...@@ -105,7 +104,7 @@ func TestSetServiceAccountLocal(t *testing.T) { ...@@ -105,7 +104,7 @@ func TestSetServiceAccountLocal(t *testing.T) {
func TestSetServiceAccountMultiLocal(t *testing.T) { func TestSetServiceAccountMultiLocal(t *testing.T) {
testapi.Default = testapi.Groups[""] testapi.Default = testapi.Groups[""]
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -116,7 +115,6 @@ func TestSetServiceAccountMultiLocal(t *testing.T) { ...@@ -116,7 +115,6 @@ func TestSetServiceAccountMultiLocal(t *testing.T) {
return nil, nil return nil, nil
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}}
outputFormat := "name" outputFormat := "name"
...@@ -326,15 +324,14 @@ func TestSetServiceAccountRemote(t *testing.T) { ...@@ -326,15 +324,14 @@ func TestSetServiceAccountRemote(t *testing.T) {
t.Run(input.apiPrefix, func(t *testing.T) { t.Run(input.apiPrefix, func(t *testing.T) {
groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion} groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion}
testapi.Default = testapi.Groups[input.testAPIGroup] testapi.Default = testapi.Groups[input.testAPIGroup]
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
GroupVersion: groupVersion, GroupVersion: groupVersion,
NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs}, NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
resourcePath := testapi.Default.ResourcePath(input.args[0]+"s", tf.Namespace, input.args[1]) resourcePath := testapi.Default.ResourcePath(input.args[0]+"s", "test", input.args[1])
switch p, m := req.URL.Path, req.Method; { switch p, m := req.URL.Path, req.Method; {
case p == resourcePath && m == http.MethodGet: case p == resourcePath && m == http.MethodGet:
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(input.object)}, nil return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(input.object)}, nil
...@@ -387,7 +384,7 @@ func TestServiceAccountValidation(t *testing.T) { ...@@ -387,7 +384,7 @@ func TestServiceAccountValidation(t *testing.T) {
} }
for _, input := range inputs { for _, input := range inputs {
t.Run(input.name, func(t *testing.T) { t.Run(input.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -400,7 +397,6 @@ func TestServiceAccountValidation(t *testing.T) { ...@@ -400,7 +397,6 @@ func TestServiceAccountValidation(t *testing.T) {
outputFormat := "" outputFormat := ""
tf.Namespace = "test"
streams := genericclioptions.NewTestIOStreamsDiscard() streams := genericclioptions.NewTestIOStreamsDiscard()
cmd := NewCmdServiceAccount(tf, streams) cmd := NewCmdServiceAccount(tf, streams)
......
...@@ -131,7 +131,7 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [] ...@@ -131,7 +131,7 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
o.PrintObj = printer.PrintObj o.PrintObj = printer.PrintObj
var enforceNamespace bool var enforceNamespace bool
o.namespace, enforceNamespace, err = f.DefaultNamespace() o.namespace, enforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -28,11 +28,9 @@ import ( ...@@ -28,11 +28,9 @@ import (
) )
func TestValidate(t *testing.T) { func TestValidate(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
tf.Namespace = "test"
tests := map[string]struct { tests := map[string]struct {
options *SubjectOptions options *SubjectOptions
expectErr bool expectErr bool
......
...@@ -124,7 +124,7 @@ func NewCmdTaint(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra. ...@@ -124,7 +124,7 @@ func NewCmdTaint(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.
// Complete adapts from the command line args and factory to the data required. // Complete adapts from the command line args and factory to the data required.
func (o *TaintOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) (err error) { func (o *TaintOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) (err error) {
namespace, _, err := f.DefaultNamespace() namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -18,7 +18,6 @@ go_library( ...@@ -18,7 +18,6 @@ go_library(
"//pkg/kubectl/genericclioptions:go_default_library", "//pkg/kubectl/genericclioptions:go_default_library",
"//pkg/kubectl/genericclioptions/resource:go_default_library", "//pkg/kubectl/genericclioptions/resource:go_default_library",
"//pkg/kubectl/validation:go_default_library", "//pkg/kubectl/validation:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library", "//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta/testrestmapper:go_default_library", "//vendor/k8s.io/apimachinery/pkg/api/meta/testrestmapper:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
......
...@@ -25,8 +25,6 @@ import ( ...@@ -25,8 +25,6 @@ import (
"path/filepath" "path/filepath"
"time" "time"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta/testrestmapper" "k8s.io/apimachinery/pkg/api/meta/testrestmapper"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
...@@ -234,12 +232,12 @@ func (d *fakeCachedDiscoveryClient) ServerResources() ([]*metav1.APIResourceList ...@@ -234,12 +232,12 @@ func (d *fakeCachedDiscoveryClient) ServerResources() ([]*metav1.APIResourceList
type TestFactory struct { type TestFactory struct {
cmdutil.Factory cmdutil.Factory
kubeConfigFlags *genericclioptions.TestConfigFlags
Client kubectl.RESTClient Client kubectl.RESTClient
ScaleGetter scaleclient.ScalesGetter ScaleGetter scaleclient.ScalesGetter
UnstructuredClient kubectl.RESTClient UnstructuredClient kubectl.RESTClient
Namespace string
ClientConfigVal *restclient.Config ClientConfigVal *restclient.Config
CommandVal string
FakeDynamicClient *fakedynamic.FakeDynamicClient FakeDynamicClient *fakedynamic.FakeDynamicClient
tempConfigFile *os.File tempConfigFile *os.File
...@@ -276,6 +274,7 @@ func NewTestFactory() *TestFactory { ...@@ -276,6 +274,7 @@ func NewTestFactory() *TestFactory {
return &TestFactory{ return &TestFactory{
Factory: cmdutil.NewFactory(configFlags), Factory: cmdutil.NewFactory(configFlags),
kubeConfigFlags: configFlags,
FakeDynamicClient: fakedynamic.NewSimpleDynamicClient(legacyscheme.Scheme), FakeDynamicClient: fakedynamic.NewSimpleDynamicClient(legacyscheme.Scheme),
tempConfigFile: tmpFile, tempConfigFile: tmpFile,
...@@ -283,6 +282,11 @@ func NewTestFactory() *TestFactory { ...@@ -283,6 +282,11 @@ func NewTestFactory() *TestFactory {
} }
} }
func (f *TestFactory) WithNamespace(ns string) *TestFactory {
f.kubeConfigFlags.WithNamespace(ns)
return f
}
func (f *TestFactory) Cleanup() { func (f *TestFactory) Cleanup() {
if f.tempConfigFile == nil { if f.tempConfigFile == nil {
return return
...@@ -295,10 +299,6 @@ func (f *TestFactory) ToRESTConfig() (*restclient.Config, error) { ...@@ -295,10 +299,6 @@ func (f *TestFactory) ToRESTConfig() (*restclient.Config, error) {
return f.ClientConfigVal, nil return f.ClientConfigVal, nil
} }
func (f *TestFactory) BareClientConfig() (*restclient.Config, error) {
return f.ClientConfigVal, nil
}
func (f *TestFactory) ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) { func (f *TestFactory) ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) {
return f.Client, nil return f.Client, nil
} }
...@@ -314,10 +314,6 @@ func (f *TestFactory) Validator(validate bool) (validation.Schema, error) { ...@@ -314,10 +314,6 @@ func (f *TestFactory) Validator(validate bool) (validation.Schema, error) {
return validation.NullSchema{}, nil return validation.NullSchema{}, nil
} }
func (f *TestFactory) DefaultNamespace() (string, bool, error) {
return f.Namespace, false, nil
}
func (f *TestFactory) OpenAPISchema() (openapi.Resources, error) { func (f *TestFactory) OpenAPISchema() (openapi.Resources, error) {
if f.OpenAPISchemaFunc != nil { if f.OpenAPISchemaFunc != nil {
return f.OpenAPISchemaFunc() return f.OpenAPISchemaFunc()
...@@ -325,10 +321,6 @@ func (f *TestFactory) OpenAPISchema() (openapi.Resources, error) { ...@@ -325,10 +321,6 @@ func (f *TestFactory) OpenAPISchema() (openapi.Resources, error) {
return openapitesting.EmptyResources{}, nil return openapitesting.EmptyResources{}, nil
} }
func (f *TestFactory) Command(*cobra.Command, bool) string {
return f.CommandVal
}
func (f *TestFactory) NewBuilder() *resource.Builder { func (f *TestFactory) NewBuilder() *resource.Builder {
mapper, err := f.ToRESTMapper() mapper, err := f.ToRESTMapper()
...@@ -425,10 +417,6 @@ func (f *TestFactory) DiscoveryClient() (discovery.CachedDiscoveryInterface, err ...@@ -425,10 +417,6 @@ func (f *TestFactory) DiscoveryClient() (discovery.CachedDiscoveryInterface, err
return cachedClient, nil return cachedClient, nil
} }
func (f *TestFactory) ClientSetForVersion(requiredVersion *schema.GroupVersion) (internalclientset.Interface, error) {
return f.ClientSet()
}
func testRESTMapper() meta.RESTMapper { func testRESTMapper() meta.RESTMapper {
groupResources := testDynamicResources() groupResources := testDynamicResources()
mapper := restmapper.NewDiscoveryRESTMapper(groupResources) mapper := restmapper.NewDiscoveryRESTMapper(groupResources)
......
...@@ -50,7 +50,7 @@ func TestTopNodeAllMetrics(t *testing.T) { ...@@ -50,7 +50,7 @@ func TestTopNodeAllMetrics(t *testing.T) {
expectedMetricsPath := fmt.Sprintf("%s/%s/nodes", baseMetricsAddress, metricsApiVersion) expectedMetricsPath := fmt.Sprintf("%s/%s/nodes", baseMetricsAddress, metricsApiVersion)
expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -78,7 +78,6 @@ func TestTopNodeAllMetrics(t *testing.T) { ...@@ -78,7 +78,6 @@ func TestTopNodeAllMetrics(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -103,7 +102,7 @@ func TestTopNodeAllMetricsCustomDefaults(t *testing.T) { ...@@ -103,7 +102,7 @@ func TestTopNodeAllMetricsCustomDefaults(t *testing.T) {
expectedMetricsPath := fmt.Sprintf("%s/%s/nodes", customBaseMetricsAddress, metricsApiVersion) expectedMetricsPath := fmt.Sprintf("%s/%s/nodes", customBaseMetricsAddress, metricsApiVersion)
expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -131,7 +130,6 @@ func TestTopNodeAllMetricsCustomDefaults(t *testing.T) { ...@@ -131,7 +130,6 @@ func TestTopNodeAllMetricsCustomDefaults(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -167,7 +165,7 @@ func TestTopNodeWithNameMetrics(t *testing.T) { ...@@ -167,7 +165,7 @@ func TestTopNodeWithNameMetrics(t *testing.T) {
expectedPath := fmt.Sprintf("%s/%s/nodes/%s", baseMetricsAddress, metricsApiVersion, expectedMetrics.Name) expectedPath := fmt.Sprintf("%s/%s/nodes/%s", baseMetricsAddress, metricsApiVersion, expectedMetrics.Name)
expectedNodePath := fmt.Sprintf("/%s/%s/nodes/%s", apiPrefix, apiVersion, expectedMetrics.Name) expectedNodePath := fmt.Sprintf("/%s/%s/nodes/%s", apiPrefix, apiVersion, expectedMetrics.Name)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -195,7 +193,6 @@ func TestTopNodeWithNameMetrics(t *testing.T) { ...@@ -195,7 +193,6 @@ func TestTopNodeWithNameMetrics(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -234,7 +231,7 @@ func TestTopNodeWithLabelSelectorMetrics(t *testing.T) { ...@@ -234,7 +231,7 @@ func TestTopNodeWithLabelSelectorMetrics(t *testing.T) {
expectedQuery := fmt.Sprintf("labelSelector=%s", url.QueryEscape(label)) expectedQuery := fmt.Sprintf("labelSelector=%s", url.QueryEscape(label))
expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -262,7 +259,6 @@ func TestTopNodeWithLabelSelectorMetrics(t *testing.T) { ...@@ -262,7 +259,6 @@ func TestTopNodeWithLabelSelectorMetrics(t *testing.T) {
} }
}), }),
} }
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -289,7 +285,7 @@ func TestTopNodeAllMetricsFromMetricsServer(t *testing.T) { ...@@ -289,7 +285,7 @@ func TestTopNodeAllMetricsFromMetricsServer(t *testing.T) {
expectedMetrics, nodes := testNodeV1beta1MetricsData() expectedMetrics, nodes := testNodeV1beta1MetricsData()
expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -315,7 +311,6 @@ func TestTopNodeAllMetricsFromMetricsServer(t *testing.T) { ...@@ -315,7 +311,6 @@ func TestTopNodeAllMetricsFromMetricsServer(t *testing.T) {
fakemetricsClientset.AddReactor("list", "nodes", func(action core.Action) (handled bool, ret runtime.Object, err error) { fakemetricsClientset.AddReactor("list", "nodes", func(action core.Action) (handled bool, ret runtime.Object, err error) {
return true, expectedMetrics, nil return true, expectedMetrics, nil
}) })
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -357,7 +352,7 @@ func TestTopNodeWithNameMetricsFromMetricsServer(t *testing.T) { ...@@ -357,7 +352,7 @@ func TestTopNodeWithNameMetricsFromMetricsServer(t *testing.T) {
} }
expectedNodePath := fmt.Sprintf("/%s/%s/nodes/%s", apiPrefix, apiVersion, expectedMetrics.Name) expectedNodePath := fmt.Sprintf("/%s/%s/nodes/%s", apiPrefix, apiVersion, expectedMetrics.Name)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -383,7 +378,6 @@ func TestTopNodeWithNameMetricsFromMetricsServer(t *testing.T) { ...@@ -383,7 +378,6 @@ func TestTopNodeWithNameMetricsFromMetricsServer(t *testing.T) {
fakemetricsClientset.AddReactor("get", "nodes", func(action core.Action) (handled bool, ret runtime.Object, err error) { fakemetricsClientset.AddReactor("get", "nodes", func(action core.Action) (handled bool, ret runtime.Object, err error) {
return true, &expectedMetrics, nil return true, &expectedMetrics, nil
}) })
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -435,7 +429,7 @@ func TestTopNodeWithLabelSelectorMetricsFromMetricsServer(t *testing.T) { ...@@ -435,7 +429,7 @@ func TestTopNodeWithLabelSelectorMetricsFromMetricsServer(t *testing.T) {
label := "key=value" label := "key=value"
expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup() defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
...@@ -462,7 +456,6 @@ func TestTopNodeWithLabelSelectorMetricsFromMetricsServer(t *testing.T) { ...@@ -462,7 +456,6 @@ func TestTopNodeWithLabelSelectorMetricsFromMetricsServer(t *testing.T) {
fakemetricsClientset.AddReactor("list", "nodes", func(action core.Action) (handled bool, ret runtime.Object, err error) { fakemetricsClientset.AddReactor("list", "nodes", func(action core.Action) (handled bool, ret runtime.Object, err error) {
return true, expectedMetrics, nil return true, expectedMetrics, nil
}) })
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
......
...@@ -121,7 +121,7 @@ func (o *TopPodOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []s ...@@ -121,7 +121,7 @@ func (o *TopPodOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []s
return cmdutil.UsageErrorf(cmd, "%s", cmd.Use) return cmdutil.UsageErrorf(cmd, "%s", cmd.Use)
} }
o.Namespace, _, err = f.DefaultNamespace() o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -164,7 +164,7 @@ func TestTopPod(t *testing.T) { ...@@ -164,7 +164,7 @@ func TestTopPod(t *testing.T) {
} }
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace(testNS)
defer tf.Cleanup() defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -190,7 +190,6 @@ func TestTopPod(t *testing.T) { ...@@ -190,7 +190,6 @@ func TestTopPod(t *testing.T) {
} }
}), }),
} }
tf.Namespace = testNS
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -309,7 +308,7 @@ func TestTopPodWithMetricsServer(t *testing.T) { ...@@ -309,7 +308,7 @@ func TestTopPodWithMetricsServer(t *testing.T) {
}) })
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace(testNS)
defer tf.Cleanup() defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -329,7 +328,6 @@ func TestTopPodWithMetricsServer(t *testing.T) { ...@@ -329,7 +328,6 @@ func TestTopPodWithMetricsServer(t *testing.T) {
} }
}), }),
} }
tf.Namespace = testNS
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
...@@ -508,7 +506,7 @@ func TestTopPodCustomDefaults(t *testing.T) { ...@@ -508,7 +506,7 @@ func TestTopPodCustomDefaults(t *testing.T) {
} }
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory().WithNamespace(testNS)
defer tf.Cleanup() defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -534,7 +532,6 @@ func TestTopPodCustomDefaults(t *testing.T) { ...@@ -534,7 +532,6 @@ func TestTopPodCustomDefaults(t *testing.T) {
} }
}), }),
} }
tf.Namespace = testNS
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
streams, _, buf, _ := genericclioptions.NewTestIOStreams() streams, _, buf, _ := genericclioptions.NewTestIOStreams()
......
...@@ -129,7 +129,7 @@ func (o *EditOptions) Complete(f cmdutil.Factory, args []string, cmd *cobra.Comm ...@@ -129,7 +129,7 @@ func (o *EditOptions) Complete(f cmdutil.Factory, args []string, cmd *cobra.Comm
return fmt.Errorf("the edit mode doesn't support output the patch") return fmt.Errorf("the edit mode doesn't support output the patch")
} }
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -62,11 +62,6 @@ type Factory interface { ...@@ -62,11 +62,6 @@ type Factory interface {
// and which implements the common patterns for CLI interactions with generic resources. // and which implements the common patterns for CLI interactions with generic resources.
NewBuilder() *resource.Builder NewBuilder() *resource.Builder
// Returns the default namespace to use in cases where no
// other namespace is specified and whether the namespace was
// overridden.
DefaultNamespace() (string, bool, error)
// Returns a RESTClient for working with the specified RESTMapping or an error. This is intended // Returns a RESTClient for working with the specified RESTMapping or an error. This is intended
// for working with arbitrary resources and is not guaranteed to point to a Kubernetes APIServer. // for working with arbitrary resources and is not guaranteed to point to a Kubernetes APIServer.
ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error)
......
...@@ -118,10 +118,6 @@ func (f *factoryImpl) RESTClient() (*restclient.RESTClient, error) { ...@@ -118,10 +118,6 @@ func (f *factoryImpl) RESTClient() (*restclient.RESTClient, error) {
return restclient.RESTClientFor(clientConfig) return restclient.RESTClientFor(clientConfig)
} }
func (f *factoryImpl) DefaultNamespace() (string, bool, error) {
return f.clientGetter.ToRawKubeConfigLoader().Namespace()
}
func (f *factoryImpl) ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) { func (f *factoryImpl) ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) {
cfg, err := f.clientGetter.ToRESTConfig() cfg, err := f.clientGetter.ToRESTConfig()
if err != nil { if err != nil {
......
...@@ -30,6 +30,7 @@ go_library( ...@@ -30,6 +30,7 @@ go_library(
"//vendor/k8s.io/client-go/rest:go_default_library", "//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/restmapper:go_default_library", "//vendor/k8s.io/client-go/restmapper:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library", "//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library",
"//vendor/k8s.io/client-go/util/homedir:go_default_library", "//vendor/k8s.io/client-go/util/homedir:go_default_library",
], ],
) )
......
...@@ -24,6 +24,7 @@ import ( ...@@ -24,6 +24,7 @@ import (
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
"k8s.io/client-go/restmapper" "k8s.io/client-go/restmapper"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
) )
type TestConfigFlags struct { type TestConfigFlags struct {
...@@ -74,6 +75,36 @@ func (f *TestConfigFlags) WithDiscoveryClient(c discovery.CachedDiscoveryInterfa ...@@ -74,6 +75,36 @@ func (f *TestConfigFlags) WithDiscoveryClient(c discovery.CachedDiscoveryInterfa
return f return f
} }
func (f *TestConfigFlags) WithNamespace(ns string) *TestConfigFlags {
if f.clientConfig == nil {
panic("attempt to obtain a test RawKubeConfigLoader with no clientConfig specified")
}
f.clientConfig = &namespacedClientConfig{
delegate: f.clientConfig,
namespace: ns,
}
return f
}
func NewTestConfigFlags() *TestConfigFlags { func NewTestConfigFlags() *TestConfigFlags {
return &TestConfigFlags{} return &TestConfigFlags{}
} }
type namespacedClientConfig struct {
delegate clientcmd.ClientConfig
namespace string
}
func (c *namespacedClientConfig) Namespace() (string, bool, error) {
return c.namespace, false, nil
}
func (c *namespacedClientConfig) RawConfig() (clientcmdapi.Config, error) {
return c.delegate.RawConfig()
}
func (c *namespacedClientConfig) ClientConfig() (*rest.Config, error) {
return c.delegate.ClientConfig()
}
func (c *namespacedClientConfig) ConfigAccess() clientcmd.ConfigAccess {
return c.delegate.ConfigAccess()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment