From 2bc9993cbdd3a80ab1e2e7f111c98b8c0f63c0fe Mon Sep 17 00:00:00 2001 From: luolibin Date: Fri, 23 Aug 2019 21:01:02 +0800 Subject: [PATCH 1/6] format code --- pkg/tkctl/cmd/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/tkctl/cmd/cmd.go b/pkg/tkctl/cmd/cmd.go index ac3f858a2c..7ec148760e 100644 --- a/pkg/tkctl/cmd/cmd.go +++ b/pkg/tkctl/cmd/cmd.go @@ -15,7 +15,6 @@ package cmd import ( "flag" - "github.com/pingcap/tidb-operator/pkg/tkctl/cmd/version" "io" "github.com/pingcap/tidb-operator/pkg/tkctl/cmd/completion" @@ -26,6 +25,7 @@ import ( "github.com/pingcap/tidb-operator/pkg/tkctl/cmd/list" "github.com/pingcap/tidb-operator/pkg/tkctl/cmd/upinfo" "github.com/pingcap/tidb-operator/pkg/tkctl/cmd/use" + "github.com/pingcap/tidb-operator/pkg/tkctl/cmd/version" "github.com/pingcap/tidb-operator/pkg/tkctl/config" "github.com/spf13/cobra" "k8s.io/cli-runtime/pkg/genericclioptions" From 2de8462287c2d25aa91f4b792338bd30614cd881 Mon Sep 17 00:00:00 2001 From: luolibin Date: Fri, 23 Aug 2019 21:03:24 +0800 Subject: [PATCH 2/6] fix wrong binary name --- pkg/tkctl/cmd/ctop/ctop.go | 7 ++++--- pkg/tkctl/cmd/debug/debug.go | 9 +++++---- pkg/tkctl/cmd/info/info.go | 9 +++++---- pkg/tkctl/cmd/list/list.go | 6 +++--- pkg/tkctl/cmd/upinfo/upinfo.go | 6 +++--- pkg/tkctl/cmd/use/use.go | 5 +++-- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/pkg/tkctl/cmd/ctop/ctop.go b/pkg/tkctl/cmd/ctop/ctop.go index db042722a6..14f092f834 100644 --- a/pkg/tkctl/cmd/ctop/ctop.go +++ b/pkg/tkctl/cmd/ctop/ctop.go @@ -15,6 +15,8 @@ package ctop import ( "fmt" + "strings" + "github.com/pingcap/tidb-operator/pkg/tkctl/config" "github.com/pingcap/tidb-operator/pkg/tkctl/executor" "github.com/pingcap/tidb-operator/pkg/tkctl/util" @@ -26,16 +28,15 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" - "strings" ) const ( ctopExample = ` # ctop the specified pod - tkc ctop POD_NAME + tkctl ctop POD_NAME # ctop the specified node - tkc ctop node/NODE_NAME + tkctl ctop node/NODE_NAME ` ctopUsage = "expected 'ctop POD_NAME' or 'ctop node/NODE_NAME' for the ctop command" defaultImage = "quay.io/vektorlab/ctop:0.7.2" diff --git a/pkg/tkctl/cmd/debug/debug.go b/pkg/tkctl/cmd/debug/debug.go index c058c7342d..43b7ae15b6 100644 --- a/pkg/tkctl/cmd/debug/debug.go +++ b/pkg/tkctl/cmd/debug/debug.go @@ -15,6 +15,7 @@ package debug import ( "fmt" + "github.com/pingcap/tidb-operator/pkg/tkctl/config" "github.com/pingcap/tidb-operator/pkg/tkctl/executor" "github.com/pingcap/tidb-operator/pkg/tkctl/util" @@ -31,16 +32,16 @@ import ( const ( debugExample = ` # debug a container in the running pod, the first container will be picked by default - tkc debug POD_NAME + tkctl debug POD_NAME # specify namespace or container - tkc debug --namespace foo POD_NAME -c CONTAINER_NAME + tkctl debug --namespace foo POD_NAME -c CONTAINER_NAME # override the default troubleshooting image - tkc debug POD_NAME --image aylei/debug-jvm + tkctl debug POD_NAME --image aylei/debug-jvm # override entrypoint of debug container - tkc debug POD_NAME --image aylei/debug-jvm /bin/bash + tkctl debug POD_NAME --image aylei/debug-jvm /bin/bash ` debugLongDesc = ` diff --git a/pkg/tkctl/cmd/info/info.go b/pkg/tkctl/cmd/info/info.go index 0b38744cf9..6b6cdea06c 100644 --- a/pkg/tkctl/cmd/info/info.go +++ b/pkg/tkctl/cmd/info/info.go @@ -15,6 +15,8 @@ package info import ( "fmt" + "io" + "github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1" "github.com/pingcap/tidb-operator/pkg/client/clientset/versioned" "github.com/pingcap/tidb-operator/pkg/label" @@ -22,7 +24,6 @@ import ( "github.com/pingcap/tidb-operator/pkg/tkctl/readable" "github.com/pingcap/tidb-operator/pkg/tkctl/util" "github.com/spf13/cobra" - "io" "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/cli-runtime/pkg/genericclioptions" @@ -38,13 +39,13 @@ const ( ` infoExample = ` # get current tidb cluster info (set by tkc use) - tkc info + tkctl info # get specified tidb cluster info - tkc info -t another-cluster + tkctl info -t another-cluster ` infoUsage = `expected 'info -t CLUSTER_NAME' for the info command or -using 'tkc use' to set tidb cluster first. +using 'tkctl use' to set tidb cluster first. ` ) diff --git a/pkg/tkctl/cmd/list/list.go b/pkg/tkctl/cmd/list/list.go index 8264c08789..1521355edd 100644 --- a/pkg/tkctl/cmd/list/list.go +++ b/pkg/tkctl/cmd/list/list.go @@ -33,13 +33,13 @@ const ( ` listExample = ` # list all clusters and sync to local config - tkc list + tkctl list # filter by namespace - tkc list --namespace=foo + tkctl list --namespace=foo # get tidb cluster in all namespaces - tkc list -A + tkctl list -A ` ) diff --git a/pkg/tkctl/cmd/upinfo/upinfo.go b/pkg/tkctl/cmd/upinfo/upinfo.go index da802385bb..3c4ef3afa4 100644 --- a/pkg/tkctl/cmd/upinfo/upinfo.go +++ b/pkg/tkctl/cmd/upinfo/upinfo.go @@ -42,13 +42,13 @@ const ( ` upinfoExample = ` # get current tidb cluster info (set by tkc user) - tkc upinfo + tkctl upinfo # get specified tidb cluster component upgrade info - tkc upinfo -t another-cluster + tkctl upinfo -t another-cluster ` infoUsage = `expected 'upinfo -t CLUSTER_NAME' for the upinfo command or -using 'tkc use' to set tidb cluster first. +using 'tkctl use' to set tidb cluster first. ` UPDATED = "updated" UPDATING = "updating" diff --git a/pkg/tkctl/cmd/use/use.go b/pkg/tkctl/cmd/use/use.go index b573fe15ca..6e25d6ef2f 100644 --- a/pkg/tkctl/cmd/use/use.go +++ b/pkg/tkctl/cmd/use/use.go @@ -15,6 +15,7 @@ package use import ( "fmt" + "github.com/pingcap/tidb-operator/pkg/client/clientset/versioned" "github.com/pingcap/tidb-operator/pkg/tkctl/config" "github.com/spf13/cobra" @@ -32,10 +33,10 @@ const ( ` useExample = ` # specify a tidb cluster to use - tkc use demo-cluster + tkctl use demo-cluster # specify kubernetes context and namespace - tkc use --context=demo-ctx --namespace=demo-ns demo-cluster + tkctl use --context=demo-ctx --namespace=demo-ns demo-cluster ` useUsage = "expected 'use CLUSTER_NAME' for the use command" ) From cbeb785d14348bd7c6996fb80cb63be3b1cffc8e Mon Sep 17 00:00:00 2001 From: luolibin Date: Fri, 23 Aug 2019 21:13:02 +0800 Subject: [PATCH 3/6] support output info with -owide --- pkg/tkctl/readable/print_flags.go | 9 +++++++- pkg/tkctl/readable/printers.go | 37 ++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/pkg/tkctl/readable/print_flags.go b/pkg/tkctl/readable/print_flags.go index f18890983f..5b73ff60f1 100644 --- a/pkg/tkctl/readable/print_flags.go +++ b/pkg/tkctl/readable/print_flags.go @@ -34,9 +34,15 @@ func NewPrintFlags() *PrintFlags { } } +// Copy returns a copy of PrintFlags for mutation +func (p *PrintFlags) Copy() PrintFlags { + printFlags := *p + return printFlags +} + func (p *PrintFlags) AddFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&p.OutputFormat, "output", "o", p.OutputFormat, - "Output format. json|yaml|default.") + "Output format. json|yaml|wide") p.JSONYamlPrintFlags.AddFlags(cmd) } @@ -53,6 +59,7 @@ func (p *PrintFlags) ToPrinter(withKind, withNamespace bool) (printers.ResourceP printer := kubeprinters.NewHumanReadablePrinter(scheme.Codecs.UniversalDecoder(), kubeprinters.PrintOptions{ WithNamespace: withNamespace, + Wide: p.OutputFormat == "wide", WithKind: withKind, }) // Add custom handlers diff --git a/pkg/tkctl/readable/printers.go b/pkg/tkctl/readable/printers.go index 047c0c0d00..634a1a2d4e 100644 --- a/pkg/tkctl/readable/printers.go +++ b/pkg/tkctl/readable/printers.go @@ -15,8 +15,11 @@ package readable import ( "fmt" + "time" + "github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1" "k8s.io/api/core/v1" + apiv1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1" @@ -24,7 +27,6 @@ import ( "k8s.io/apimachinery/pkg/util/duration" "k8s.io/kubernetes/pkg/printers" "k8s.io/kubernetes/pkg/util/node" - "time" ) const ( @@ -40,7 +42,7 @@ type PodBasicColumns struct { Memory string Age string PodIP string - HostIP string + NodeName string MemInfo string CPUInfo string @@ -66,7 +68,8 @@ func AddHandlers(h printers.PrintHandler) { {Name: "CPU", Type: "string", Description: "The Pod total cpu request and limit."}, {Name: "Restarts", Type: "integer", Description: "The number of times the containers in this pod have been restarted."}, {Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]}, - {Name: "Node", Type: "string", Description: "Node IP"}, + {Name: "IP", Type: "string", Priority: 1, Description: apiv1.PodStatus{}.SwaggerDoc()["podIP"]}, + {Name: "Node", Type: "string", Priority: 1, Description: apiv1.PodSpec{}.SwaggerDoc()["nodeName"]}, } h.TableHandler(commonPodColumns, printPod) h.TableHandler(commonPodColumns, printPodList) @@ -76,8 +79,9 @@ func AddHandlers(h printers.PrintHandler) { {Name: "Claim", Type: "string", Format: "name", Description: "Volume claim"}, {Name: "Status", Type: "string", Description: "Volume status"}, {Name: "Capacity", Type: "string", Description: "Volume capacity"}, - {Name: "Node", Type: "string", Description: "Mounted node"}, - {Name: "Local", Type: "string", Description: "Local path"}, + {Name: "StorageClass", Type: "string", Description: "Storage class of volume"}, + {Name: "Node", Type: "string", Priority: 1, Description: "Mounted node"}, + {Name: "Local", Type: "string", Priority: 1, Description: "Local path"}, } h.TableHandler(volumeColumns, printVolume) h.TableHandler(volumeColumns, printVolumeList) @@ -142,8 +146,11 @@ func printPod(pod *v1.Pod, options printers.PrintOptions) ([]metav1beta1.TableRo columns.MemInfo, columns.CPUInfo, columns.Restarts, - columns.Age, - columns.HostIP) + columns.Age) + + if options.Wide { + row.Cells = append(row.Cells, columns.PodIP, columns.NodeName) + } return []metav1beta1.TableRow{row}, nil } @@ -166,7 +173,7 @@ func printVolume(volume *v1.PersistentVolume, options printers.PrintOptions) ([] claim := unset if volume.Spec.ClaimRef != nil { - claim = volume.Spec.ClaimRef.Name + claim = fmt.Sprintf("%s/%s", volume.Spec.ClaimRef.Namespace, volume.Spec.ClaimRef.Name) } local := unset if volume.Spec.Local != nil { @@ -194,7 +201,11 @@ func printVolume(volume *v1.PersistentVolume, options printers.PrintOptions) ([] capacity = val.String() } } - row.Cells = append(row.Cells, volume.Name, claim, volume.Status.Phase, capacity, host, local) + row.Cells = append(row.Cells, volume.Name, claim, volume.Status.Phase, capacity, volume.Spec.StorageClassName) + + if options.Wide { + row.Cells = append(row.Cells, host, local) + } return []metav1beta1.TableRow{row}, nil } @@ -273,10 +284,10 @@ func basicPodColumns(pod *v1.Pod) *PodBasicColumns { reason = "Terminating" } - hostIP := pod.Status.HostIP + nodeName := pod.Spec.NodeName podIP := pod.Status.PodIP - if hostIP == "" { - hostIP = unset + if nodeName == "" { + nodeName = unset } if podIP == "" { podIP = unset @@ -325,7 +336,7 @@ func basicPodColumns(pod *v1.Pod) *PodBasicColumns { Reason: reason, Restarts: int64(restarts), Age: translateTimestampSince(pod.CreationTimestamp), - HostIP: hostIP, + NodeName: nodeName, PodIP: podIP, MemInfo: memInfo, CPUInfo: cpuInfo, From 0313573570c309a8e3d24542ab4ebff21f2c9f26 Mon Sep 17 00:00:00 2001 From: luolibin Date: Fri, 23 Aug 2019 21:14:06 +0800 Subject: [PATCH 4/6] improve get command output --- pkg/tkctl/cmd/get/get.go | 241 +++++++++++++++++++++++++++++++-------- 1 file changed, 192 insertions(+), 49 deletions(-) diff --git a/pkg/tkctl/cmd/get/get.go b/pkg/tkctl/cmd/get/get.go index fabf00608e..fcbd93bbd2 100644 --- a/pkg/tkctl/cmd/get/get.go +++ b/pkg/tkctl/cmd/get/get.go @@ -14,7 +14,10 @@ package get import ( + "encoding/json" "fmt" + "strings" + "github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1" "github.com/pingcap/tidb-operator/pkg/client/clientset/versioned" "github.com/pingcap/tidb-operator/pkg/label" @@ -22,12 +25,15 @@ import ( "github.com/pingcap/tidb-operator/pkg/tkctl/readable" "github.com/spf13/cobra" "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime" + utilerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/client-go/kubernetes" + apicore "k8s.io/kubernetes/pkg/apis/core" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" - kubeprinters "k8s.io/kubernetes/pkg/printers" - "strings" ) const ( @@ -35,20 +41,20 @@ const ( Get tidb component detail. Available components include: all, pd, tidb, tikv, volume - You can omit --tidbcluster= option by running 'tkc use ', + You can omit --tidbcluster= option by running 'tkctl use ', ` getExample = ` # get PD details - tkc get pd + tkctl get pd # get multiple kinds of resources - tkc get tikv,tidb,volume + tkctl get tikv,tidb,volume # get volume details and choose different format - tkc get volume -o yaml + tkctl get volume -o yaml # get all components - tkc get all + tkctl get all ` getUsage = "expect 'get -t=CLUSTER_NAME kind | get -A kind' for get command or set tidb cluster by 'use' first" ) @@ -67,12 +73,14 @@ type GetOptions struct { AllClusters bool Namespace string TidbClusterName string + ResourceName string GetPD bool GetTiKV bool GetTiDB bool GetVolume bool - PrintFlags *readable.PrintFlags + IsHumanReadablePrinter bool + PrintFlags *readable.PrintFlags tcCli *versioned.Clientset kubeCli *kubernetes.Clientset @@ -83,7 +91,6 @@ type GetOptions struct { // NewCmdGet creates the get command which get the tidb component detail func NewCmdGet(tkcContext *config.TkcContext, streams genericclioptions.IOStreams) *cobra.Command { options := NewGetOptions(streams) - cmd := &cobra.Command{ Use: "get", Short: "get pd|tikv|tidb|volume|all", @@ -147,6 +154,11 @@ func (o *GetOptions) Complete(tkcContext *config.TkcContext, cmd *cobra.Command, } o.kubeCli = kubeClient + // human readable printers have special conversion rules, so we determine if we're using one. + if len(o.PrintFlags.OutputFormat) == 0 || o.PrintFlags.OutputFormat == "wide" { + o.IsHumanReadablePrinter = true + } + resources := args[0] for _, resource := range strings.Split(resources, ",") { switch resource { @@ -166,6 +178,10 @@ func (o *GetOptions) Complete(tkcContext *config.TkcContext, cmd *cobra.Command, o.GetVolume = true } } + + if len(args) > 1 { + o.ResourceName = args[1] + } return nil } @@ -190,50 +206,177 @@ func (o *GetOptions) Run(tkcContext *config.TkcContext, cmd *cobra.Command, args tcs = []v1alpha1.TidbCluster{*tc} } - printer, err := o.PrintFlags.ToPrinter(false, o.AllClusters) - if err != nil { - return err - } - w := kubeprinters.GetNewTabWriter(o.Out) - printTidbInfo := len(tcs) > 1 + multiTidbCluster := len(tcs) > 1 var errs []error - for i := range tcs { - tc := tcs[i] - if printTidbInfo { - w.Write([]byte(fmt.Sprintf("Cluster: %s/%s\n", tc.Namespace, tc.Name))) - w.Flush() - } - flushPods := func(kind string) { - podList, err := o.kubeCli.CoreV1().Pods(tc.Namespace).List(metav1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s,%s=%s", label.InstanceLabelKey, tc.Name, label.ComponentLabelKey, kind), - }) - if err != nil { - errs = append(errs, err) - } - printer.PrintObj(podList, w) - w.Flush() + for i, tc := range tcs { + if multiTidbCluster { + o.Out.Write([]byte(fmt.Sprintf("Cluster: %s/%s\n", tc.Namespace, tc.Name))) } + // TODO: do a big batch or steadily print parts in minor step? - if o.GetPD { - flushPods(kindPD) - } - if o.GetTiKV { - flushPods(kindTiKV) - } - if o.GetTiDB { - flushPods(kindTiDB) - } - if o.GetVolume { - volumeList, err := o.kubeCli.CoreV1().PersistentVolumes().List(metav1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s,%s=%s", label.InstanceLabelKey, tc.Name, - label.NamespaceLabelKey, tc.Namespace), - }) - if err != nil { - return err + if err := o.PrintOutput(&tc, kindPD, o.GetPD); err != nil { + errs = append(errs, err) + } + + if err := o.PrintOutput(&tc, kindTiKV, o.GetTiKV); err != nil { + errs = append(errs, err) + } + + if err := o.PrintOutput(&tc, kindTiDB, o.GetTiDB); err != nil { + errs = append(errs, err) + } + + if err := o.PrintOutput(&tc, kindVolume, o.GetVolume); err != nil { + errs = append(errs, err) + } + + if multiTidbCluster && i != len(tcs)-1 { + o.Out.Write([]byte("\n")) + } + } + return utilerrors.NewAggregate(errs) +} + +func (o *GetOptions) PrintOutput(tc *v1alpha1.TidbCluster, resourceType string, needPrint bool) error { + if !needPrint { + return nil + } + + switch resourceType { + case kindPD, kindTiDB, kindTiKV: + var objs []runtime.Object + var listOptions metav1.ListOptions + if len(o.ResourceName) == 0 { + listOptions = metav1.ListOptions{ + LabelSelector: fmt.Sprintf("%s=%s,%s=%s", label.InstanceLabelKey, tc.Name, label.ComponentLabelKey, resourceType), + } + } else { + listOptions = metav1.ListOptions{ + FieldSelector: fmt.Sprintf("metadata.name=%s", o.ResourceName), + } + } + + podList, err := o.kubeCli.CoreV1().Pods(tc.Namespace).List(listOptions) + if err != nil { + return err + } + for _, pod := range podList.Items { + pod.GetObjectKind().SetGroupVersionKind(v1.SchemeGroupVersion.WithKind("Pod")) + objs = append(objs, &pod) + } + + if !o.IsHumanReadablePrinter { + return o.printGeneric(objs) + } + + printer, err := o.PrintFlags.ToPrinter(false, o.AllClusters) + if err != nil { + return err + } + + return printer.PrintObj(podList, o.Out) + case kindVolume: + var objs []runtime.Object + var listOptions metav1.ListOptions + if len(o.ResourceName) == 0 { + listOptions = metav1.ListOptions{ + LabelSelector: fmt.Sprintf("%s=%s,%s=%s", label.InstanceLabelKey, tc.Name, label.NamespaceLabelKey, tc.Namespace), + } + } else { + listOptions = metav1.ListOptions{ + FieldSelector: fmt.Sprintf("metadata.name=%s", o.ResourceName), } - printer.PrintObj(volumeList, w) - w.Flush() } + + volumeList, err := o.kubeCli.CoreV1().PersistentVolumes().List(listOptions) + if err != nil { + return err + } + for _, volume := range volumeList.Items { + volume.GetObjectKind().SetGroupVersionKind(v1.SchemeGroupVersion.WithKind("PersistentVolume")) + objs = append(objs, &volume) + } + + if !o.IsHumanReadablePrinter { + return o.printGeneric(objs) + } + + // PersistentVolume without namespace concept + printer, err := o.PrintFlags.ToPrinter(false, false) + if err != nil { + return err + } + + return printer.PrintObj(volumeList, o.Out) } - return nil + return fmt.Errorf("Unknow resource type %s", resourceType) +} + +func (o *GetOptions) printGeneric(objs []runtime.Object) error { + printer, err := o.PrintFlags.ToPrinter(false, false) + if err != nil { + return err + } + + if len(objs) == 0 { + return nil + } + + var allObj runtime.Object + if len(objs) > 1 { + list := apicore.List{ + TypeMeta: metav1.TypeMeta{ + Kind: "List", + APIVersion: "v1", + }, + ListMeta: metav1.ListMeta{}, + } + for _, obj := range objs { + list.Items = append(list.Items, obj) + } + + listData, err := json.Marshal(list) + if err != nil { + return err + } + + converted, err := runtime.Decode(unstructured.UnstructuredJSONScheme, listData) + if err != nil { + return err + } + + allObj = converted + } else { + allObj = objs[0] + } + + isList := meta.IsListType(allObj) + if !isList { + return printer.PrintObj(allObj, o.Out) + } + + items, err := meta.ExtractList(allObj) + if err != nil { + return err + } + + // take the items and create a new list for display + list := &unstructured.UnstructuredList{ + Object: map[string]interface{}{ + "kind": "List", + "apiVersion": "v1", + "metadata": map[string]interface{}{}, + }, + } + if listMeta, err := meta.ListAccessor(allObj); err == nil { + list.Object["metadata"] = map[string]interface{}{ + "selfLink": listMeta.GetSelfLink(), + "resourceVersion": listMeta.GetResourceVersion(), + } + } + + for _, item := range items { + list.Items = append(list.Items, *item.(*unstructured.Unstructured)) + } + return printer.PrintObj(list, o.Out) } From 367456c4d5b2598a4a9c86b7c547ce7f4bfff535 Mon Sep 17 00:00:00 2001 From: luolibin Date: Sun, 25 Aug 2019 12:13:01 +0800 Subject: [PATCH 5/6] remove unused code --- pkg/tkctl/readable/print_flags.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pkg/tkctl/readable/print_flags.go b/pkg/tkctl/readable/print_flags.go index 5b73ff60f1..f3ace23391 100644 --- a/pkg/tkctl/readable/print_flags.go +++ b/pkg/tkctl/readable/print_flags.go @@ -34,12 +34,6 @@ func NewPrintFlags() *PrintFlags { } } -// Copy returns a copy of PrintFlags for mutation -func (p *PrintFlags) Copy() PrintFlags { - printFlags := *p - return printFlags -} - func (p *PrintFlags) AddFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&p.OutputFormat, "output", "o", p.OutputFormat, "Output format. json|yaml|wide") From a7d8ebe5b7e52748a144a0f93c51f70407ead98b Mon Sep 17 00:00:00 2001 From: luolibin Date: Sun, 25 Aug 2019 12:27:16 +0800 Subject: [PATCH 6/6] add more example --- pkg/tkctl/cmd/get/get.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/tkctl/cmd/get/get.go b/pkg/tkctl/cmd/get/get.go index fcbd93bbd2..3585551c6d 100644 --- a/pkg/tkctl/cmd/get/get.go +++ b/pkg/tkctl/cmd/get/get.go @@ -53,6 +53,12 @@ const ( # get volume details and choose different format tkctl get volume -o yaml + # get details of a specific pd/tikv/tidb/volume + tkctl get volume -oyaml + + # output all columns, including omitted columns + tkctl get pd,volume -owide + # get all components tkctl get all `