mirror of https://github.com/k3s-io/k3s
kubectl: move custom columns printers and flags
parent
3bcbc5da79
commit
e0b712d428
|
@ -14,7 +14,6 @@ go_test(
|
||||||
"rolling_updater_test.go",
|
"rolling_updater_test.go",
|
||||||
"rollout_status_test.go",
|
"rollout_status_test.go",
|
||||||
"scale_test.go",
|
"scale_test.go",
|
||||||
"sorter_test.go",
|
|
||||||
],
|
],
|
||||||
embed = [":go_default_library"],
|
embed = [":go_default_library"],
|
||||||
deps = [
|
deps = [
|
||||||
|
@ -25,7 +24,6 @@ go_test(
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
|
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/testapigroup/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/testapigroup/v1:go_default_library",
|
||||||
|
@ -57,7 +55,6 @@ go_library(
|
||||||
"rolling_updater.go",
|
"rolling_updater.go",
|
||||||
"rollout_status.go",
|
"rollout_status.go",
|
||||||
"scale.go",
|
"scale.go",
|
||||||
"sorter.go",
|
|
||||||
],
|
],
|
||||||
importpath = "k8s.io/kubernetes/pkg/kubectl",
|
importpath = "k8s.io/kubernetes/pkg/kubectl",
|
||||||
deps = [
|
deps = [
|
||||||
|
@ -69,7 +66,6 @@ go_library(
|
||||||
"//pkg/kubectl/util/deployment:go_default_library",
|
"//pkg/kubectl/util/deployment:go_default_library",
|
||||||
"//pkg/kubectl/util/podutils:go_default_library",
|
"//pkg/kubectl/util/podutils:go_default_library",
|
||||||
"//pkg/kubectl/util/slice:go_default_library",
|
"//pkg/kubectl/util/slice:go_default_library",
|
||||||
"//pkg/printers:go_default_library",
|
|
||||||
"//pkg/printers/internalversion:go_default_library",
|
"//pkg/printers/internalversion:go_default_library",
|
||||||
"//staging/src/k8s.io/api/apps/v1:go_default_library",
|
"//staging/src/k8s.io/api/apps/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/api/autoscaling/v1:go_default_library",
|
"//staging/src/k8s.io/api/autoscaling/v1:go_default_library",
|
||||||
|
@ -79,8 +75,6 @@ go_library(
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1:go_default_library",
|
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||||
|
@ -96,10 +90,7 @@ go_library(
|
||||||
"//staging/src/k8s.io/client-go/rest:go_default_library",
|
"//staging/src/k8s.io/client-go/rest:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/scale:go_default_library",
|
"//staging/src/k8s.io/client-go/scale:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/util/integer:go_default_library",
|
"//staging/src/k8s.io/client-go/util/integer:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/util/jsonpath:go_default_library",
|
|
||||||
"//staging/src/k8s.io/client-go/util/retry:go_default_library",
|
"//staging/src/k8s.io/client-go/util/retry:go_default_library",
|
||||||
"//vendor/k8s.io/klog:go_default_library",
|
|
||||||
"//vendor/vbom.ml/util/sortorder:go_default_library",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,19 +17,22 @@ filegroup(
|
||||||
go_library(
|
go_library(
|
||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = [
|
srcs = [
|
||||||
|
"customcolumn.go",
|
||||||
|
"customcolumn_flags.go",
|
||||||
"get.go",
|
"get.go",
|
||||||
"get_flags.go",
|
"get_flags.go",
|
||||||
"humanreadable_flags.go",
|
"humanreadable_flags.go",
|
||||||
|
"sorter.go",
|
||||||
],
|
],
|
||||||
importpath = "k8s.io/kubernetes/pkg/kubectl/cmd/get",
|
importpath = "k8s.io/kubernetes/pkg/kubectl/cmd/get",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/api/legacyscheme:go_default_library",
|
"//pkg/api/legacyscheme:go_default_library",
|
||||||
"//pkg/kubectl:go_default_library",
|
|
||||||
"//pkg/kubectl/cmd/util:go_default_library",
|
"//pkg/kubectl/cmd/util:go_default_library",
|
||||||
"//pkg/kubectl/cmd/util/openapi:go_default_library",
|
"//pkg/kubectl/cmd/util/openapi:go_default_library",
|
||||||
"//pkg/kubectl/scheme:go_default_library",
|
"//pkg/kubectl/scheme:go_default_library",
|
||||||
"//pkg/kubectl/util/i18n:go_default_library",
|
"//pkg/kubectl/util/i18n:go_default_library",
|
||||||
|
"//pkg/kubectl/util/printers:go_default_library",
|
||||||
"//pkg/kubectl/util/templates:go_default_library",
|
"//pkg/kubectl/util/templates:go_default_library",
|
||||||
"//pkg/printers:go_default_library",
|
"//pkg/printers:go_default_library",
|
||||||
"//pkg/printers/internalversion:go_default_library",
|
"//pkg/printers/internalversion:go_default_library",
|
||||||
|
@ -46,19 +49,26 @@ go_library(
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
|
||||||
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
|
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
|
||||||
|
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions/printers:go_default_library",
|
||||||
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions/resource:go_default_library",
|
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions/resource:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/rest:go_default_library",
|
"//staging/src/k8s.io/client-go/rest:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/tools/watch:go_default_library",
|
"//staging/src/k8s.io/client-go/tools/watch:go_default_library",
|
||||||
|
"//staging/src/k8s.io/client-go/util/integer:go_default_library",
|
||||||
|
"//staging/src/k8s.io/client-go/util/jsonpath:go_default_library",
|
||||||
"//vendor/github.com/spf13/cobra:go_default_library",
|
"//vendor/github.com/spf13/cobra:go_default_library",
|
||||||
"//vendor/k8s.io/klog:go_default_library",
|
"//vendor/k8s.io/klog:go_default_library",
|
||||||
|
"//vendor/vbom.ml/util/sortorder:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
go_test(
|
go_test(
|
||||||
name = "go_default_test",
|
name = "go_default_test",
|
||||||
srcs = [
|
srcs = [
|
||||||
|
"customcolumn_flags_test.go",
|
||||||
|
"customcolumn_test.go",
|
||||||
"get_test.go",
|
"get_test.go",
|
||||||
"humanreadable_flags_test.go",
|
"humanreadable_flags_test.go",
|
||||||
|
"sorter_test.go",
|
||||||
],
|
],
|
||||||
data = [
|
data = [
|
||||||
"//api/openapi-spec:swagger-spec",
|
"//api/openapi-spec:swagger-spec",
|
||||||
|
@ -72,13 +82,16 @@ go_test(
|
||||||
"//pkg/kubectl/cmd/util/openapi:go_default_library",
|
"//pkg/kubectl/cmd/util/openapi:go_default_library",
|
||||||
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
|
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
|
||||||
"//pkg/kubectl/scheme:go_default_library",
|
"//pkg/kubectl/scheme:go_default_library",
|
||||||
|
"//pkg/kubectl/util/printers:go_default_library",
|
||||||
"//staging/src/k8s.io/api/apps/v1:go_default_library",
|
"//staging/src/k8s.io/api/apps/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/api/autoscaling/v1:go_default_library",
|
"//staging/src/k8s.io/api/autoscaling/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/api/batch/v1:go_default_library",
|
"//staging/src/k8s.io/api/batch/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/api/batch/v1beta1:go_default_library",
|
"//staging/src/k8s.io/api/batch/v1beta1:go_default_library",
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/api/extensions/v1beta1:go_default_library",
|
"//staging/src/k8s.io/api/extensions/v1beta1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package printers
|
package get
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
@ -30,6 +30,7 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions/printers"
|
"k8s.io/cli-runtime/pkg/genericclioptions/printers"
|
||||||
"k8s.io/client-go/util/jsonpath"
|
"k8s.io/client-go/util/jsonpath"
|
||||||
|
utilprinters "k8s.io/kubernetes/pkg/kubectl/util/printers"
|
||||||
)
|
)
|
||||||
|
|
||||||
var jsonRegexp = regexp.MustCompile("^\\{\\.?([^{}]+)\\}$|^\\.?([^{}]+)$")
|
var jsonRegexp = regexp.MustCompile("^\\{\\.?([^{}]+)\\}$|^\\.?([^{}]+)$")
|
||||||
|
@ -160,7 +161,7 @@ func (s *CustomColumnsPrinter) PrintObj(obj runtime.Object, out io.Writer) error
|
||||||
}
|
}
|
||||||
|
|
||||||
if w, found := out.(*tabwriter.Writer); !found {
|
if w, found := out.(*tabwriter.Writer); !found {
|
||||||
w = GetNewTabWriter(out)
|
w = utilprinters.GetNewTabWriter(out)
|
||||||
out = w
|
out = w
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package printers
|
package get
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
|
"k8s.io/cli-runtime/pkg/genericclioptions/printers"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ func (f *CustomColumnsPrintFlags) AllowedFormats() []string {
|
||||||
// handling custom-column printing.
|
// handling custom-column printing.
|
||||||
// Returns false if the specified templateFormat does not match a supported format.
|
// Returns false if the specified templateFormat does not match a supported format.
|
||||||
// Supported format types can be found in pkg/printers/printers.go
|
// Supported format types can be found in pkg/printers/printers.go
|
||||||
func (f *CustomColumnsPrintFlags) ToPrinter(templateFormat string) (ResourcePrinter, error) {
|
func (f *CustomColumnsPrintFlags) ToPrinter(templateFormat string) (printers.ResourcePrinter, error) {
|
||||||
if len(templateFormat) == 0 {
|
if len(templateFormat) == 0 {
|
||||||
return nil, genericclioptions.NoCompatiblePrinterError{}
|
return nil, genericclioptions.NoCompatiblePrinterError{}
|
||||||
}
|
}
|
||||||
|
@ -79,7 +80,8 @@ func (f *CustomColumnsPrintFlags) ToPrinter(templateFormat string) (ResourcePrin
|
||||||
return nil, fmt.Errorf("custom-columns format specified but no custom columns given")
|
return nil, fmt.Errorf("custom-columns format specified but no custom columns given")
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder := scheme.Codecs.UniversalDecoder()
|
// UniversalDecoder call must specify parameter versions; otherwise it will decode to internal versions.
|
||||||
|
decoder := scheme.Codecs.UniversalDecoder(scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
||||||
|
|
||||||
if templateFormat == "custom-columns-file" {
|
if templateFormat == "custom-columns-file" {
|
||||||
file, err := os.Open(templateValue)
|
file, err := os.Open(templateValue)
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package printers
|
package get
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -24,13 +24,13 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPrinterSupportsExpectedCustomColumnFormats(t *testing.T) {
|
func TestPrinterSupportsExpectedCustomColumnFormats(t *testing.T) {
|
||||||
testObject := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
testObject := &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
||||||
|
|
||||||
customColumnsFile, err := ioutil.TempFile("", "printers_jsonpath_flags")
|
customColumnsFile, err := ioutil.TempFile("", "printers_jsonpath_flags")
|
||||||
if err != nil {
|
if err != nil {
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package printers
|
package get
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -22,13 +22,16 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
"k8s.io/kubernetes/pkg/kubectl/util/printers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// UniversalDecoder call must specify parameter versions; otherwise it will decode to internal versions.
|
||||||
|
var decoder = scheme.Codecs.UniversalDecoder(scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
||||||
|
|
||||||
func TestMassageJSONPath(t *testing.T) {
|
func TestMassageJSONPath(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
input string
|
input string
|
||||||
|
@ -115,7 +118,7 @@ func TestNewColumnPrinterFromSpec(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) {
|
||||||
printer, err := NewCustomColumnsPrinterFromSpec(test.spec, legacyscheme.Codecs.UniversalDecoder(), test.noHeaders)
|
printer, err := NewCustomColumnsPrinterFromSpec(test.spec, decoder, test.noHeaders)
|
||||||
if test.expectErr {
|
if test.expectErr {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("[%s] unexpected non-error", test.name)
|
t.Errorf("[%s] unexpected non-error", test.name)
|
||||||
|
@ -129,7 +132,7 @@ func TestNewColumnPrinterFromSpec(t *testing.T) {
|
||||||
if test.noHeaders {
|
if test.noHeaders {
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
|
|
||||||
printer.PrintObj(&api.Pod{}, buffer)
|
printer.PrintObj(&corev1.Pod{}, buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("An error occurred printing Pod: %#v", err)
|
t.Fatalf("An error occurred printing Pod: %#v", err)
|
||||||
}
|
}
|
||||||
|
@ -219,7 +222,7 @@ func TestNewColumnPrinterFromTemplate(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) {
|
||||||
reader := bytes.NewBufferString(test.spec)
|
reader := bytes.NewBufferString(test.spec)
|
||||||
printer, err := NewCustomColumnsPrinterFromTemplate(reader, legacyscheme.Codecs.UniversalDecoder())
|
printer, err := NewCustomColumnsPrinterFromTemplate(reader, decoder)
|
||||||
if test.expectErr {
|
if test.expectErr {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("[%s] unexpected non-error", test.name)
|
t.Errorf("[%s] unexpected non-error", test.name)
|
||||||
|
@ -251,7 +254,7 @@ func TestColumnPrint(t *testing.T) {
|
||||||
FieldSpec: "{.metadata.name}",
|
FieldSpec: "{.metadata.name}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
obj: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
obj: &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||||
expectedOutput: `NAME
|
expectedOutput: `NAME
|
||||||
foo
|
foo
|
||||||
`,
|
`,
|
||||||
|
@ -263,8 +266,8 @@ foo
|
||||||
FieldSpec: "{.metadata.name}",
|
FieldSpec: "{.metadata.name}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
obj: &v1.PodList{
|
obj: &corev1.PodList{
|
||||||
Items: []v1.Pod{
|
Items: []corev1.Pod{
|
||||||
{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||||
{ObjectMeta: metav1.ObjectMeta{Name: "bar"}},
|
{ObjectMeta: metav1.ObjectMeta{Name: "bar"}},
|
||||||
},
|
},
|
||||||
|
@ -285,7 +288,7 @@ bar
|
||||||
FieldSpec: "{.apiVersion}",
|
FieldSpec: "{.apiVersion}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
obj: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}, TypeMeta: metav1.TypeMeta{APIVersion: "baz"}},
|
obj: &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}, TypeMeta: metav1.TypeMeta{APIVersion: "baz"}},
|
||||||
expectedOutput: `NAME API_VERSION
|
expectedOutput: `NAME API_VERSION
|
||||||
foo baz
|
foo baz
|
||||||
`,
|
`,
|
||||||
|
@ -305,7 +308,7 @@ foo baz
|
||||||
FieldSpec: "{.notFound}",
|
FieldSpec: "{.notFound}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
obj: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}, TypeMeta: metav1.TypeMeta{APIVersion: "baz"}},
|
obj: &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}, TypeMeta: metav1.TypeMeta{APIVersion: "baz"}},
|
||||||
expectedOutput: `NAME API_VERSION NOT_FOUND
|
expectedOutput: `NAME API_VERSION NOT_FOUND
|
||||||
foo baz <none>
|
foo baz <none>
|
||||||
`,
|
`,
|
||||||
|
@ -316,7 +319,7 @@ foo baz <none>
|
||||||
t.Run(test.expectedOutput, func(t *testing.T) {
|
t.Run(test.expectedOutput, func(t *testing.T) {
|
||||||
printer := &CustomColumnsPrinter{
|
printer := &CustomColumnsPrinter{
|
||||||
Columns: test.columns,
|
Columns: test.columns,
|
||||||
Decoder: legacyscheme.Codecs.UniversalDecoder(),
|
Decoder: decoder,
|
||||||
}
|
}
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
if err := printer.PrintObj(test.obj, buffer); err != nil {
|
if err := printer.PrintObj(test.obj, buffer); err != nil {
|
||||||
|
@ -345,7 +348,7 @@ func TestIndividualPrintObjOnExistingTabWriter(t *testing.T) {
|
||||||
FieldSpec: "{.metadata.labels.label2}",
|
FieldSpec: "{.metadata.labels.label2}",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
objects := []*v1.Pod{
|
objects := []*corev1.Pod{
|
||||||
{ObjectMeta: metav1.ObjectMeta{Name: "foo", Labels: map[string]string{"label1": "foo", "label2": "foo"}}},
|
{ObjectMeta: metav1.ObjectMeta{Name: "foo", Labels: map[string]string{"label1": "foo", "label2": "foo"}}},
|
||||||
{ObjectMeta: metav1.ObjectMeta{Name: "bar", Labels: map[string]string{"label1": "bar", "label2": "bar"}}},
|
{ObjectMeta: metav1.ObjectMeta{Name: "bar", Labels: map[string]string{"label1": "bar", "label2": "bar"}}},
|
||||||
}
|
}
|
||||||
|
@ -355,10 +358,10 @@ bar bar bar
|
||||||
`
|
`
|
||||||
|
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
tabWriter := GetNewTabWriter(buffer)
|
tabWriter := printers.GetNewTabWriter(buffer)
|
||||||
printer := &CustomColumnsPrinter{
|
printer := &CustomColumnsPrinter{
|
||||||
Columns: columns,
|
Columns: columns,
|
||||||
Decoder: legacyscheme.Codecs.UniversalDecoder(),
|
Decoder: decoder,
|
||||||
}
|
}
|
||||||
for _, obj := range objects {
|
for _, obj := range objects {
|
||||||
if err := printer.PrintObj(obj, tabWriter); err != nil {
|
if err := printer.PrintObj(obj, tabWriter); err != nil {
|
|
@ -38,15 +38,15 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
|
"k8s.io/cli-runtime/pkg/genericclioptions/printers"
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions/resource"
|
"k8s.io/cli-runtime/pkg/genericclioptions/resource"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
watchtools "k8s.io/client-go/tools/watch"
|
watchtools "k8s.io/client-go/tools/watch"
|
||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||||
"k8s.io/kubernetes/pkg/kubectl"
|
|
||||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
||||||
|
utilprinters "k8s.io/kubernetes/pkg/kubectl/util/printers"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/util/templates"
|
"k8s.io/kubernetes/pkg/kubectl/util/templates"
|
||||||
"k8s.io/kubernetes/pkg/printers"
|
|
||||||
"k8s.io/kubernetes/pkg/util/interrupt"
|
"k8s.io/kubernetes/pkg/util/interrupt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -331,7 +331,7 @@ func (r *RuntimeSorter) Sort() error {
|
||||||
case *metav1beta1.Table:
|
case *metav1beta1.Table:
|
||||||
includesTable = true
|
includesTable = true
|
||||||
|
|
||||||
if err := kubectl.NewTableSorter(t, r.field).Sort(); err != nil {
|
if err := NewTableSorter(t, r.field).Sort(); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -354,7 +354,7 @@ func (r *RuntimeSorter) Sort() error {
|
||||||
// if not dealing with a Table response from the server, assume
|
// if not dealing with a Table response from the server, assume
|
||||||
// all objects are runtime.Object as usual, and sort using old method.
|
// all objects are runtime.Object as usual, and sort using old method.
|
||||||
var err error
|
var err error
|
||||||
if r.positioner, err = kubectl.SortObjects(r.decoder, r.objects, r.field); err != nil {
|
if r.positioner, err = SortObjects(r.decoder, r.objects, r.field); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -374,7 +374,7 @@ func (r *RuntimeSorter) WithDecoder(decoder runtime.Decoder) *RuntimeSorter {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRuntimeSorter(objects []runtime.Object, sortBy string) *RuntimeSorter {
|
func NewRuntimeSorter(objects []runtime.Object, sortBy string) *RuntimeSorter {
|
||||||
parsedField, err := printers.RelaxedJSONPathExpression(sortBy)
|
parsedField, err := RelaxedJSONPathExpression(sortBy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
parsedField = sortBy
|
parsedField = sortBy
|
||||||
}
|
}
|
||||||
|
@ -495,7 +495,7 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
|
||||||
var printer printers.ResourcePrinter
|
var printer printers.ResourcePrinter
|
||||||
var lastMapping *meta.RESTMapping
|
var lastMapping *meta.RESTMapping
|
||||||
nonEmptyObjCount := 0
|
nonEmptyObjCount := 0
|
||||||
w := printers.GetNewTabWriter(o.Out)
|
w := utilprinters.GetNewTabWriter(o.Out)
|
||||||
for ix := range objs {
|
for ix := range objs {
|
||||||
var mapping *meta.RESTMapping
|
var mapping *meta.RESTMapping
|
||||||
var info *resource.Info
|
var info *resource.Info
|
||||||
|
@ -645,7 +645,7 @@ func (o *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []string)
|
||||||
// print the current object
|
// print the current object
|
||||||
if !o.WatchOnly {
|
if !o.WatchOnly {
|
||||||
var objsToPrint []runtime.Object
|
var objsToPrint []runtime.Object
|
||||||
writer := printers.GetNewTabWriter(o.Out)
|
writer := utilprinters.GetNewTabWriter(o.Out)
|
||||||
|
|
||||||
if isList {
|
if isList {
|
||||||
objsToPrint, _ = meta.ExtractList(obj)
|
objsToPrint, _ = meta.ExtractList(obj)
|
||||||
|
@ -852,7 +852,7 @@ func cmdSpecifiesOutputFmt(cmd *cobra.Command) bool {
|
||||||
|
|
||||||
func maybeWrapSortingPrinter(printer printers.ResourcePrinter, sortBy string) printers.ResourcePrinter {
|
func maybeWrapSortingPrinter(printer printers.ResourcePrinter, sortBy string) printers.ResourcePrinter {
|
||||||
if len(sortBy) != 0 {
|
if len(sortBy) != 0 {
|
||||||
return &kubectl.SortingPrinter{
|
return &SortingPrinter{
|
||||||
Delegate: printer,
|
Delegate: printer,
|
||||||
SortField: fmt.Sprintf("%s", sortBy),
|
SortField: fmt.Sprintf("%s", sortBy),
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
|
"k8s.io/cli-runtime/pkg/genericclioptions/printers"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
|
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
|
||||||
"k8s.io/kubernetes/pkg/printers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// PrintFlags composes common printer flag structs
|
// PrintFlags composes common printer flag structs
|
||||||
|
@ -33,7 +33,7 @@ import (
|
||||||
type PrintFlags struct {
|
type PrintFlags struct {
|
||||||
JSONYamlPrintFlags *genericclioptions.JSONYamlPrintFlags
|
JSONYamlPrintFlags *genericclioptions.JSONYamlPrintFlags
|
||||||
NamePrintFlags *genericclioptions.NamePrintFlags
|
NamePrintFlags *genericclioptions.NamePrintFlags
|
||||||
CustomColumnsFlags *printers.CustomColumnsPrintFlags
|
CustomColumnsFlags *CustomColumnsPrintFlags
|
||||||
HumanReadableFlags *HumanPrintFlags
|
HumanReadableFlags *HumanPrintFlags
|
||||||
TemplateFlags *genericclioptions.KubeTemplatePrintFlags
|
TemplateFlags *genericclioptions.KubeTemplatePrintFlags
|
||||||
|
|
||||||
|
@ -185,6 +185,6 @@ func NewGetPrintFlags() *PrintFlags {
|
||||||
TemplateFlags: genericclioptions.NewKubeTemplatePrintFlags(),
|
TemplateFlags: genericclioptions.NewKubeTemplatePrintFlags(),
|
||||||
|
|
||||||
HumanReadableFlags: NewHumanPrintFlags(),
|
HumanReadableFlags: NewHumanPrintFlags(),
|
||||||
CustomColumnsFlags: printers.NewCustomColumnsPrintFlags(),
|
CustomColumnsFlags: NewCustomColumnsPrintFlags(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package kubectl
|
package get
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -24,15 +24,15 @@ import (
|
||||||
|
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
|
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/cli-runtime/pkg/genericclioptions/printers"
|
||||||
"k8s.io/client-go/util/integer"
|
"k8s.io/client-go/util/integer"
|
||||||
"k8s.io/client-go/util/jsonpath"
|
"k8s.io/client-go/util/jsonpath"
|
||||||
"k8s.io/kubernetes/pkg/printers"
|
|
||||||
|
|
||||||
"vbom.ml/util/sortorder"
|
"vbom.ml/util/sortorder"
|
||||||
)
|
)
|
||||||
|
@ -71,7 +71,7 @@ func (s *SortingPrinter) sortObj(obj runtime.Object) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch list := obj.(type) {
|
switch list := obj.(type) {
|
||||||
case *v1.List:
|
case *corev1.List:
|
||||||
outputList := make([]runtime.RawExtension, len(objs))
|
outputList := make([]runtime.RawExtension, len(objs))
|
||||||
for ix := range objs {
|
for ix := range objs {
|
||||||
outputList[ix] = list.Items[sorter.OriginalPosition(ix)]
|
outputList[ix] = list.Items[sorter.OriginalPosition(ix)]
|
||||||
|
@ -96,7 +96,7 @@ func SortObjects(decoder runtime.Decoder, objs []runtime.Object, fieldInput stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
field, err := printers.RelaxedJSONPathExpression(fieldInput)
|
field, err := RelaxedJSONPathExpression(fieldInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package kubectl
|
package get
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
|
@ -9,15 +9,12 @@ load(
|
||||||
go_library(
|
go_library(
|
||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = [
|
srcs = [
|
||||||
"customcolumn.go",
|
|
||||||
"customcolumn_flags.go",
|
|
||||||
"humanreadable.go",
|
"humanreadable.go",
|
||||||
"interface.go",
|
"interface.go",
|
||||||
"tabwriter.go",
|
"tabwriter.go",
|
||||||
],
|
],
|
||||||
importpath = "k8s.io/kubernetes/pkg/printers",
|
importpath = "k8s.io/kubernetes/pkg/printers",
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/kubectl/scheme:go_default_library",
|
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
|
||||||
|
@ -26,10 +23,6 @@ go_library(
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
|
|
||||||
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions/printers:go_default_library",
|
|
||||||
"//staging/src/k8s.io/client-go/util/jsonpath:go_default_library",
|
|
||||||
"//vendor/github.com/spf13/cobra:go_default_library",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -52,19 +45,12 @@ filegroup(
|
||||||
|
|
||||||
go_test(
|
go_test(
|
||||||
name = "go_default_test",
|
name = "go_default_test",
|
||||||
srcs = [
|
srcs = ["humanreadable_test.go"],
|
||||||
"customcolumn_flags_test.go",
|
|
||||||
"customcolumn_test.go",
|
|
||||||
"humanreadable_test.go",
|
|
||||||
],
|
|
||||||
embed = [":go_default_library"],
|
embed = [":go_default_library"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/api/legacyscheme:go_default_library",
|
|
||||||
"//pkg/apis/core:go_default_library",
|
"//pkg/apis/core:go_default_library",
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue