diff --git a/pkg/kubectl/cmd/cmd_printing_test.go b/pkg/kubectl/cmd/cmd_printing_test.go index 23930e52f5..49676d480d 100644 --- a/pkg/kubectl/cmd/cmd_printing_test.go +++ b/pkg/kubectl/cmd/cmd_printing_test.go @@ -122,12 +122,12 @@ func TestIllegalPackageSourceCheckerThroughPrintFlags(t *testing.T) { } func TestIllegalPackageSourceCheckerDirectlyThroughPrinters(t *testing.T) { - jsonPathPrinter, err := printers.NewJSONPathPrinter("{ .metadata.name }") + jsonPathPrinter, err := genericprinters.NewJSONPathPrinter("{ .metadata.name }") if err != nil { t.Fatalf("unexpected error: %v", err) } - goTemplatePrinter, err := printers.NewGoTemplatePrinter([]byte("{{ .metadata.name }}")) + goTemplatePrinter, err := genericprinters.NewGoTemplatePrinter([]byte("{{ .metadata.name }}")) if err != nil { t.Fatalf("unexpected error: %v", err) } @@ -140,7 +140,7 @@ func TestIllegalPackageSourceCheckerDirectlyThroughPrinters(t *testing.T) { testCases := []struct { name string expectInternalObjErr bool - printer printers.ResourcePrinter + printer genericprinters.ResourcePrinter obj runtime.Object expectedOutput string }{ diff --git a/pkg/kubectl/cmd/config/flags.go b/pkg/kubectl/cmd/config/flags.go index 5e2f3ed806..6455bafbf5 100644 --- a/pkg/kubectl/cmd/config/flags.go +++ b/pkg/kubectl/cmd/config/flags.go @@ -31,7 +31,7 @@ import ( type kubectlConfigPrintFlags struct { JSONYamlPrintFlags *genericclioptions.JSONYamlPrintFlags NamePrintFlags *genericclioptions.NamePrintFlags - TemplateFlags *printers.KubeTemplatePrintFlags + TemplateFlags *genericclioptions.KubeTemplatePrintFlags TypeSetter *genericprinters.TypeSetterPrinter @@ -94,7 +94,7 @@ func newKubeConfigPrintFlags(scheme runtime.ObjectTyper) *kubectlConfigPrintFlag JSONYamlPrintFlags: genericclioptions.NewJSONYamlPrintFlags(), NamePrintFlags: genericclioptions.NewNamePrintFlags(""), - TemplateFlags: printers.NewKubeTemplatePrintFlags(), + TemplateFlags: genericclioptions.NewKubeTemplatePrintFlags(), TypeSetter: genericprinters.NewTypeSetter(scheme), } diff --git a/pkg/kubectl/cmd/create/flags.go b/pkg/kubectl/cmd/create/flags.go index e1bf63cf46..6e902ea122 100644 --- a/pkg/kubectl/cmd/create/flags.go +++ b/pkg/kubectl/cmd/create/flags.go @@ -31,7 +31,7 @@ import ( type PrintFlags struct { JSONYamlPrintFlags *genericclioptions.JSONYamlPrintFlags NamePrintFlags *genericclioptions.NamePrintFlags - TemplateFlags *printers.KubeTemplatePrintFlags + TemplateFlags *genericclioptions.KubeTemplatePrintFlags TypeSetter *genericprinters.TypeSetterPrinter @@ -86,7 +86,7 @@ func NewPrintFlags(operation string, scheme runtime.ObjectTyper) *PrintFlags { JSONYamlPrintFlags: genericclioptions.NewJSONYamlPrintFlags(), NamePrintFlags: genericclioptions.NewNamePrintFlags(operation), - TemplateFlags: printers.NewKubeTemplatePrintFlags(), + TemplateFlags: genericclioptions.NewKubeTemplatePrintFlags(), TypeSetter: genericprinters.NewTypeSetter(scheme), } diff --git a/pkg/kubectl/cmd/get/get_flags.go b/pkg/kubectl/cmd/get/get_flags.go index 6905f0ff4f..bc05ac05c7 100644 --- a/pkg/kubectl/cmd/get/get_flags.go +++ b/pkg/kubectl/cmd/get/get_flags.go @@ -35,7 +35,7 @@ type PrintFlags struct { NamePrintFlags *genericclioptions.NamePrintFlags CustomColumnsFlags *printers.CustomColumnsPrintFlags HumanReadableFlags *HumanPrintFlags - TemplateFlags *printers.KubeTemplatePrintFlags + TemplateFlags *genericclioptions.KubeTemplatePrintFlags NoHeaders *bool OutputFormat *string @@ -182,7 +182,7 @@ func NewGetPrintFlags() *PrintFlags { JSONYamlPrintFlags: genericclioptions.NewJSONYamlPrintFlags(), NamePrintFlags: genericclioptions.NewNamePrintFlags(""), - TemplateFlags: printers.NewKubeTemplatePrintFlags(), + TemplateFlags: genericclioptions.NewKubeTemplatePrintFlags(), HumanReadableFlags: NewHumanPrintFlags(), CustomColumnsFlags: printers.NewCustomColumnsPrintFlags(), diff --git a/pkg/printers/jsonpath_flags.go b/pkg/kubectl/genericclioptions/jsonpath_flags.go similarity index 89% rename from pkg/printers/jsonpath_flags.go rename to pkg/kubectl/genericclioptions/jsonpath_flags.go index d95f737620..c495fcd8b8 100644 --- a/pkg/printers/jsonpath_flags.go +++ b/pkg/kubectl/genericclioptions/jsonpath_flags.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package printers +package genericclioptions import ( "fmt" @@ -23,7 +23,7 @@ import ( "github.com/spf13/cobra" - "k8s.io/kubernetes/pkg/kubectl/genericclioptions" + "k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers" ) // templates are logically optional for specifying a format. @@ -55,9 +55,9 @@ func (f *JSONPathPrintFlags) AllowedFormats() []string { // ToPrinter receives an templateFormat and returns a printer capable of // handling --template format printing. // Returns false if the specified templateFormat does not match a template format. -func (f *JSONPathPrintFlags) ToPrinter(templateFormat string) (ResourcePrinter, error) { +func (f *JSONPathPrintFlags) ToPrinter(templateFormat string) (printers.ResourcePrinter, error) { if (f.TemplateArgument == nil || len(*f.TemplateArgument) == 0) && len(templateFormat) == 0 { - return nil, genericclioptions.NoCompatiblePrinterError{Options: f, OutputFormat: &templateFormat} + return nil, NoCompatiblePrinterError{Options: f, OutputFormat: &templateFormat} } templateValue := "" @@ -76,7 +76,7 @@ func (f *JSONPathPrintFlags) ToPrinter(templateFormat string) (ResourcePrinter, } if _, supportedFormat := jsonFormats[templateFormat]; !supportedFormat { - return nil, genericclioptions.NoCompatiblePrinterError{OutputFormat: &templateFormat, AllowedFormats: f.AllowedFormats()} + return nil, NoCompatiblePrinterError{OutputFormat: &templateFormat, AllowedFormats: f.AllowedFormats()} } if len(templateValue) == 0 { @@ -92,7 +92,7 @@ func (f *JSONPathPrintFlags) ToPrinter(templateFormat string) (ResourcePrinter, templateValue = string(data) } - p, err := NewJSONPathPrinter(templateValue) + p, err := printers.NewJSONPathPrinter(templateValue) if err != nil { return nil, fmt.Errorf("error parsing jsonpath %s, %v\n", templateValue, err) } diff --git a/pkg/printers/jsonpath_flags_test.go b/pkg/kubectl/genericclioptions/jsonpath_flags_test.go similarity index 96% rename from pkg/printers/jsonpath_flags_test.go rename to pkg/kubectl/genericclioptions/jsonpath_flags_test.go index 2f5b6c4c7c..bf0c087bc1 100644 --- a/pkg/printers/jsonpath_flags_test.go +++ b/pkg/kubectl/genericclioptions/jsonpath_flags_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package printers +package genericclioptions import ( "bytes" @@ -26,7 +26,6 @@ import ( "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/kubernetes/pkg/kubectl/genericclioptions" ) func TestPrinterSupportsExpectedJSONPathFormats(t *testing.T) { @@ -105,12 +104,12 @@ func TestPrinterSupportsExpectedJSONPathFormats(t *testing.T) { p, err := printFlags.ToPrinter(tc.outputFormat) if tc.expectNoMatch { - if !genericclioptions.IsNoCompatiblePrinterError(err) { + if !IsNoCompatiblePrinterError(err) { t.Fatalf("expected no printer matches for output format %q", tc.outputFormat) } return } - if genericclioptions.IsNoCompatiblePrinterError(err) { + if IsNoCompatiblePrinterError(err) { t.Fatalf("expected to match template printer for output format %q", tc.outputFormat) } @@ -184,7 +183,7 @@ func TestJSONPathPrinterDefaultsAllowMissingKeysToTrue(t *testing.T) { outputFormat := "jsonpath" p, err := printFlags.ToPrinter(outputFormat) - if genericclioptions.IsNoCompatiblePrinterError(err) { + if IsNoCompatiblePrinterError(err) { t.Fatalf("expected to match template printer for output format %q", outputFormat) } if err != nil { diff --git a/pkg/printers/kube_template_flags.go b/pkg/kubectl/genericclioptions/kube_template_flags.go similarity index 92% rename from pkg/printers/kube_template_flags.go rename to pkg/kubectl/genericclioptions/kube_template_flags.go index 8b53e60cdc..345ca418d8 100644 --- a/pkg/printers/kube_template_flags.go +++ b/pkg/kubectl/genericclioptions/kube_template_flags.go @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -package printers +package genericclioptions import ( "github.com/spf13/cobra" - "k8s.io/kubernetes/pkg/kubectl/genericclioptions" + "k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers" ) // KubeTemplatePrintFlags composes print flags that provide both a JSONPath and a go-template printer. @@ -37,8 +37,8 @@ func (f *KubeTemplatePrintFlags) AllowedFormats() []string { return append(f.GoTemplatePrintFlags.AllowedFormats(), f.JSONPathPrintFlags.AllowedFormats()...) } -func (f *KubeTemplatePrintFlags) ToPrinter(outputFormat string) (ResourcePrinter, error) { - if p, err := f.JSONPathPrintFlags.ToPrinter(outputFormat); !genericclioptions.IsNoCompatiblePrinterError(err) { +func (f *KubeTemplatePrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrinter, error) { + if p, err := f.JSONPathPrintFlags.ToPrinter(outputFormat); !IsNoCompatiblePrinterError(err) { return p, err } return f.GoTemplatePrintFlags.ToPrinter(outputFormat) diff --git a/pkg/printers/jsonpath.go b/pkg/kubectl/genericclioptions/printers/jsonpath.go similarity index 94% rename from pkg/printers/jsonpath.go rename to pkg/kubectl/genericclioptions/printers/jsonpath.go index 1e2e7b303c..0bdb3511f1 100644 --- a/pkg/printers/jsonpath.go +++ b/pkg/kubectl/genericclioptions/printers/jsonpath.go @@ -24,7 +24,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/util/jsonpath" - "k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers" ) // exists returns true if it would be possible to call the index function @@ -118,8 +117,8 @@ func (j *JSONPathPrinter) PrintObj(obj runtime.Object, w io.Writer) error { // we use reflect.Indirect here in order to obtain the actual value from a pointer. // we need an actual value in order to retrieve the package path for an object. // using reflect.Indirect indiscriminately is valid here, as all runtime.Objects are supposed to be pointers. - if printers.InternalObjectPreventer.IsForbidden(reflect.Indirect(reflect.ValueOf(obj)).Type().PkgPath()) { - return fmt.Errorf(printers.InternalObjectPrinterErr) + if InternalObjectPreventer.IsForbidden(reflect.Indirect(reflect.ValueOf(obj)).Type().PkgPath()) { + return fmt.Errorf(InternalObjectPrinterErr) } var queryObj interface{} = obj diff --git a/pkg/printers/template.go b/pkg/kubectl/genericclioptions/printers/template.go similarity index 93% rename from pkg/printers/template.go rename to pkg/kubectl/genericclioptions/printers/template.go index 678b46e3ba..5dd807dad9 100644 --- a/pkg/printers/template.go +++ b/pkg/kubectl/genericclioptions/printers/template.go @@ -25,7 +25,6 @@ import ( "text/template" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers" ) // GoTemplatePrinter is an implementation of ResourcePrinter which formats data with a Go Template. @@ -61,8 +60,8 @@ func (p *GoTemplatePrinter) AllowMissingKeys(allow bool) { // PrintObj formats the obj with the Go Template. func (p *GoTemplatePrinter) PrintObj(obj runtime.Object, w io.Writer) error { - if printers.InternalObjectPreventer.IsForbidden(reflect.Indirect(reflect.ValueOf(obj)).Type().PkgPath()) { - return fmt.Errorf(printers.InternalObjectPrinterErr) + if InternalObjectPreventer.IsForbidden(reflect.Indirect(reflect.ValueOf(obj)).Type().PkgPath()) { + return fmt.Errorf(InternalObjectPrinterErr) } var data []byte diff --git a/pkg/printers/template_test.go b/pkg/kubectl/genericclioptions/printers/template_test.go similarity index 100% rename from pkg/printers/template_test.go rename to pkg/kubectl/genericclioptions/printers/template_test.go diff --git a/pkg/printers/template_flags.go b/pkg/kubectl/genericclioptions/template_flags.go similarity index 91% rename from pkg/printers/template_flags.go rename to pkg/kubectl/genericclioptions/template_flags.go index ffd7a24dca..ac835a0643 100644 --- a/pkg/printers/template_flags.go +++ b/pkg/kubectl/genericclioptions/template_flags.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package printers +package genericclioptions import ( "fmt" @@ -23,7 +23,7 @@ import ( "github.com/spf13/cobra" - "k8s.io/kubernetes/pkg/kubectl/genericclioptions" + "k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers" ) // templates are logically optional for specifying a format. @@ -57,9 +57,9 @@ func (f *GoTemplatePrintFlags) AllowedFormats() []string { // ToPrinter receives an templateFormat and returns a printer capable of // handling --template format printing. // Returns false if the specified templateFormat does not match a template format. -func (f *GoTemplatePrintFlags) ToPrinter(templateFormat string) (ResourcePrinter, error) { +func (f *GoTemplatePrintFlags) ToPrinter(templateFormat string) (printers.ResourcePrinter, error) { if (f.TemplateArgument == nil || len(*f.TemplateArgument) == 0) && len(templateFormat) == 0 { - return nil, genericclioptions.NoCompatiblePrinterError{Options: f, OutputFormat: &templateFormat} + return nil, NoCompatiblePrinterError{Options: f, OutputFormat: &templateFormat} } templateValue := "" @@ -78,7 +78,7 @@ func (f *GoTemplatePrintFlags) ToPrinter(templateFormat string) (ResourcePrinter } if _, supportedFormat := templateFormats[templateFormat]; !supportedFormat { - return nil, genericclioptions.NoCompatiblePrinterError{OutputFormat: &templateFormat, AllowedFormats: f.AllowedFormats()} + return nil, NoCompatiblePrinterError{OutputFormat: &templateFormat, AllowedFormats: f.AllowedFormats()} } if len(templateValue) == 0 { @@ -94,7 +94,7 @@ func (f *GoTemplatePrintFlags) ToPrinter(templateFormat string) (ResourcePrinter templateValue = string(data) } - p, err := NewGoTemplatePrinter([]byte(templateValue)) + p, err := printers.NewGoTemplatePrinter([]byte(templateValue)) if err != nil { return nil, fmt.Errorf("error parsing template %s, %v\n", templateValue, err) } diff --git a/pkg/printers/template_flags_test.go b/pkg/kubectl/genericclioptions/template_flags_test.go similarity index 95% rename from pkg/printers/template_flags_test.go rename to pkg/kubectl/genericclioptions/template_flags_test.go index 3a2400ca87..e1f5ae60e5 100644 --- a/pkg/printers/template_flags_test.go +++ b/pkg/kubectl/genericclioptions/template_flags_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package printers +package genericclioptions import ( "bytes" @@ -26,7 +26,6 @@ import ( "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/kubernetes/pkg/kubectl/genericclioptions" ) func TestPrinterSupportsExpectedTemplateFormats(t *testing.T) { @@ -105,12 +104,12 @@ func TestPrinterSupportsExpectedTemplateFormats(t *testing.T) { p, err := printFlags.ToPrinter(tc.outputFormat) if tc.expectNoMatch { - if !genericclioptions.IsNoCompatiblePrinterError(err) { + if !IsNoCompatiblePrinterError(err) { t.Fatalf("expected no printer matches for output format %q", tc.outputFormat) } return } - if genericclioptions.IsNoCompatiblePrinterError(err) { + if IsNoCompatiblePrinterError(err) { t.Fatalf("expected to match template printer for output format %q", tc.outputFormat) } @@ -178,7 +177,7 @@ func TestTemplatePrinterDefaultsAllowMissingKeysToTrue(t *testing.T) { outputFormat := "template" p, err := printFlags.ToPrinter(outputFormat) - if genericclioptions.IsNoCompatiblePrinterError(err) { + if IsNoCompatiblePrinterError(err) { t.Fatalf("expected to match template printer for output format %q", outputFormat) } if err != nil { diff --git a/pkg/printers/internalversion/printers_test.go b/pkg/printers/internalversion/printers_test.go index 82569ec1b2..318734d6c4 100644 --- a/pkg/printers/internalversion/printers_test.go +++ b/pkg/printers/internalversion/printers_test.go @@ -338,7 +338,7 @@ func TestUnknownTypePrinting(t *testing.T) { func TestTemplatePanic(t *testing.T) { tmpl := `{{and ((index .currentState.info "foo").state.running.startedAt) .currentState.info.net.state.running.startedAt}}` - printer, err := printers.NewGoTemplatePrinter([]byte(tmpl)) + printer, err := genericprinters.NewGoTemplatePrinter([]byte(tmpl)) if err != nil { t.Fatalf("tmpl fail: %v", err) } @@ -503,7 +503,7 @@ func TestTemplateStrings(t *testing.T) { } // The point of this test is to verify that the below template works. tmpl := `{{if (exists . "status" "containerStatuses")}}{{range .status.containerStatuses}}{{if (and (eq .name "foo") (exists . "state" "running"))}}true{{end}}{{end}}{{end}}` - printer, err := printers.NewGoTemplatePrinter([]byte(tmpl)) + printer, err := genericprinters.NewGoTemplatePrinter([]byte(tmpl)) if err != nil { t.Fatalf("tmpl fail: %v", err) } @@ -535,17 +535,17 @@ func TestPrinters(t *testing.T) { jsonpathPrinter printers.ResourcePrinter ) - templatePrinter, err = printers.NewGoTemplatePrinter([]byte("{{.name}}")) + templatePrinter, err = genericprinters.NewGoTemplatePrinter([]byte("{{.name}}")) if err != nil { t.Fatal(err) } - templatePrinter2, err = printers.NewGoTemplatePrinter([]byte("{{len .items}}")) + templatePrinter2, err = genericprinters.NewGoTemplatePrinter([]byte("{{len .items}}")) if err != nil { t.Fatal(err) } - jsonpathPrinter, err = printers.NewJSONPathPrinter("{.metadata.name}") + jsonpathPrinter, err = genericprinters.NewJSONPathPrinter("{.metadata.name}") if err != nil { t.Fatal(err) }