mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 05:21:58 +00:00
Merge pull request #7024 from kazegusuri/all_namespace
Allow kubectl to handle all namespace
This commit is contained in:
commit
8a14296145
@ -229,6 +229,7 @@ _kubectl_get()
|
|||||||
flags_with_completion=()
|
flags_with_completion=()
|
||||||
flags_completion=()
|
flags_completion=()
|
||||||
|
|
||||||
|
flags+=("--all-namespaces")
|
||||||
flags+=("--help")
|
flags+=("--help")
|
||||||
flags+=("-h")
|
flags+=("-h")
|
||||||
flags+=("--no-headers")
|
flags+=("--no-headers")
|
||||||
|
@ -65,6 +65,6 @@ kubectl
|
|||||||
* [kubectl update](kubectl_update.md) - Update a resource by filename or stdin.
|
* [kubectl update](kubectl_update.md) - Update a resource by filename or stdin.
|
||||||
* [kubectl version](kubectl_version.md) - Print the client and server version information.
|
* [kubectl version](kubectl_version.md) - Print the client and server version information.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra at 2015-05-15 00:05:04.556347262 +0000 UTC
|
###### Auto generated by spf13/cobra at 2015-05-22 14:24:30.1784975 +0000 UTC
|
||||||
|
|
||||||
[]()
|
[]()
|
||||||
|
@ -42,6 +42,7 @@ $ kubectl get rc/web service/frontend pods/web-pod-13je7
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
|
--all-namespaces=false: If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
|
||||||
-h, --help=false: help for get
|
-h, --help=false: help for get
|
||||||
--no-headers=false: When using the default output, don't print headers.
|
--no-headers=false: When using the default output, don't print headers.
|
||||||
-o, --output="": Output format. One of: json|yaml|template|templatefile.
|
-o, --output="": Output format. One of: json|yaml|template|templatefile.
|
||||||
@ -84,6 +85,6 @@ $ kubectl get rc/web service/frontend pods/web-pod-13je7
|
|||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
|
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra at 2015-05-20 23:52:21.968486735 +0000 UTC
|
###### Auto generated by spf13/cobra at 2015-05-22 14:24:30.17132893 +0000 UTC
|
||||||
|
|
||||||
[]()
|
[]()
|
||||||
|
@ -25,6 +25,10 @@ of the \-\-template flag, you can filter the attributes of the fetched resource(
|
|||||||
|
|
||||||
|
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
|
.PP
|
||||||
|
\fB\-\-all\-namespaces\fP=false
|
||||||
|
If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with \-\-namespace.
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
\fB\-h\fP, \fB\-\-help\fP=false
|
\fB\-h\fP, \fB\-\-help\fP=false
|
||||||
help for get
|
help for get
|
||||||
|
@ -138,7 +138,7 @@ func NewTestFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
|
|||||||
Describer: func(*meta.RESTMapping) (kubectl.Describer, error) {
|
Describer: func(*meta.RESTMapping) (kubectl.Describer, error) {
|
||||||
return t.Describer, t.Err
|
return t.Describer, t.Err
|
||||||
},
|
},
|
||||||
Printer: func(mapping *meta.RESTMapping, noHeaders bool) (kubectl.ResourcePrinter, error) {
|
Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool) (kubectl.ResourcePrinter, error) {
|
||||||
return t.Printer, t.Err
|
return t.Printer, t.Err
|
||||||
},
|
},
|
||||||
Validator: func() (validation.Schema, error) {
|
Validator: func() (validation.Schema, error) {
|
||||||
@ -192,7 +192,7 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
|
|||||||
Describer: func(*meta.RESTMapping) (kubectl.Describer, error) {
|
Describer: func(*meta.RESTMapping) (kubectl.Describer, error) {
|
||||||
return t.Describer, t.Err
|
return t.Describer, t.Err
|
||||||
},
|
},
|
||||||
Printer: func(mapping *meta.RESTMapping, noHeaders bool) (kubectl.ResourcePrinter, error) {
|
Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool) (kubectl.ResourcePrinter, error) {
|
||||||
return t.Printer, t.Err
|
return t.Printer, t.Err
|
||||||
},
|
},
|
||||||
Validator: func() (validation.Schema, error) {
|
Validator: func() (validation.Schema, error) {
|
||||||
@ -239,7 +239,7 @@ func TestClientVersions(t *testing.T) {
|
|||||||
|
|
||||||
func ExamplePrintReplicationController() {
|
func ExamplePrintReplicationController() {
|
||||||
f, tf, codec := NewAPIFactory()
|
f, tf, codec := NewAPIFactory()
|
||||||
tf.Printer = kubectl.NewHumanReadablePrinter(false)
|
tf.Printer = kubectl.NewHumanReadablePrinter(false, false)
|
||||||
tf.Client = &client.FakeRESTClient{
|
tf.Client = &client.FakeRESTClient{
|
||||||
Codec: codec,
|
Codec: codec,
|
||||||
Client: nil,
|
Client: nil,
|
||||||
|
@ -58,7 +58,7 @@ $ kubectl get rc/web service/frontend pods/web-pod-13je7`
|
|||||||
// NewCmdGet creates a command object for the generic "get" action, which
|
// NewCmdGet creates a command object for the generic "get" action, which
|
||||||
// retrieves one or more resources from a server.
|
// retrieves one or more resources from a server.
|
||||||
func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||||
p := kubectl.NewHumanReadablePrinter(false)
|
p := kubectl.NewHumanReadablePrinter(false, false)
|
||||||
validArgs := p.HandledResources()
|
validArgs := p.HandledResources()
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
@ -76,6 +76,7 @@ func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
|||||||
cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on")
|
cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on")
|
||||||
cmd.Flags().BoolP("watch", "w", false, "After listing/getting the requested object, watch for changes.")
|
cmd.Flags().BoolP("watch", "w", false, "After listing/getting the requested object, watch for changes.")
|
||||||
cmd.Flags().Bool("watch-only", false, "Watch for changes to the requested object(s), without listing/getting first.")
|
cmd.Flags().Bool("watch-only", false, "Watch for changes to the requested object(s), without listing/getting first.")
|
||||||
|
cmd.Flags().Bool("all-namespaces", false, "If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +84,7 @@ func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
|||||||
// TODO: convert all direct flag accessors to a struct and pass that instead of cmd
|
// TODO: convert all direct flag accessors to a struct and pass that instead of cmd
|
||||||
func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
|
func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
|
||||||
selector := cmdutil.GetFlagString(cmd, "selector")
|
selector := cmdutil.GetFlagString(cmd, "selector")
|
||||||
|
allNamespaces := cmdutil.GetFlagBool(cmd, "all-namespaces")
|
||||||
mapper, typer := f.Object()
|
mapper, typer := f.Object()
|
||||||
|
|
||||||
cmdNamespace, err := f.DefaultNamespace()
|
cmdNamespace, err := f.DefaultNamespace()
|
||||||
@ -94,7 +96,7 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
|
|||||||
isWatch, isWatchOnly := cmdutil.GetFlagBool(cmd, "watch"), cmdutil.GetFlagBool(cmd, "watch-only")
|
isWatch, isWatchOnly := cmdutil.GetFlagBool(cmd, "watch"), cmdutil.GetFlagBool(cmd, "watch-only")
|
||||||
if isWatch || isWatchOnly {
|
if isWatch || isWatchOnly {
|
||||||
r := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
|
r := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
|
||||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
NamespaceParam(cmdNamespace).DefaultNamespace().AllNamespaces(allNamespaces).
|
||||||
SelectorParam(selector).
|
SelectorParam(selector).
|
||||||
ResourceTypeOrNameArgs(true, args...).
|
ResourceTypeOrNameArgs(true, args...).
|
||||||
SingleResourceType().
|
SingleResourceType().
|
||||||
@ -108,7 +110,7 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
printer, err := f.PrinterForMapping(cmd, mapping)
|
printer, err := f.PrinterForMapping(cmd, mapping, allNamespaces)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -143,7 +145,7 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
|
|||||||
}
|
}
|
||||||
|
|
||||||
b := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
|
b := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
|
||||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
NamespaceParam(cmdNamespace).DefaultNamespace().AllNamespaces(allNamespaces).
|
||||||
SelectorParam(selector).
|
SelectorParam(selector).
|
||||||
ResourceTypeOrNameArgs(true, args...).
|
ResourceTypeOrNameArgs(true, args...).
|
||||||
ContinueOnError().
|
ContinueOnError().
|
||||||
@ -180,7 +182,7 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
|
|||||||
|
|
||||||
// use the default printer for each object
|
// use the default printer for each object
|
||||||
return b.Do().Visit(func(r *resource.Info) error {
|
return b.Do().Visit(func(r *resource.Info) error {
|
||||||
printer, err := f.PrinterForMapping(cmd, r.Mapping)
|
printer, err := f.PrinterForMapping(cmd, r.Mapping, allNamespaces)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
printer, err := f.PrinterForMapping(cmd, info.Mapping)
|
printer, err := f.PrinterForMapping(cmd, info.Mapping, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ type Factory struct {
|
|||||||
// Returns a Describer for displaying the specified RESTMapping type or an error.
|
// Returns a Describer for displaying the specified RESTMapping type or an error.
|
||||||
Describer func(mapping *meta.RESTMapping) (kubectl.Describer, error)
|
Describer func(mapping *meta.RESTMapping) (kubectl.Describer, error)
|
||||||
// Returns a Printer for formatting objects of the given type or an error.
|
// Returns a Printer for formatting objects of the given type or an error.
|
||||||
Printer func(mapping *meta.RESTMapping, noHeaders bool) (kubectl.ResourcePrinter, error)
|
Printer func(mapping *meta.RESTMapping, noHeaders, withNamespace bool) (kubectl.ResourcePrinter, error)
|
||||||
// Returns a Resizer for changing the size of the specified RESTMapping type or an error
|
// Returns a Resizer for changing the size of the specified RESTMapping type or an error
|
||||||
Resizer func(mapping *meta.RESTMapping) (kubectl.Resizer, error)
|
Resizer func(mapping *meta.RESTMapping) (kubectl.Resizer, error)
|
||||||
// Returns a Reaper for gracefully shutting down resources.
|
// Returns a Reaper for gracefully shutting down resources.
|
||||||
@ -143,8 +143,8 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
|
|||||||
}
|
}
|
||||||
return describer, nil
|
return describer, nil
|
||||||
},
|
},
|
||||||
Printer: func(mapping *meta.RESTMapping, noHeaders bool) (kubectl.ResourcePrinter, error) {
|
Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool) (kubectl.ResourcePrinter, error) {
|
||||||
return kubectl.NewHumanReadablePrinter(noHeaders), nil
|
return kubectl.NewHumanReadablePrinter(noHeaders, withNamespace), nil
|
||||||
},
|
},
|
||||||
PodSelectorForObject: func(object runtime.Object) (string, error) {
|
PodSelectorForObject: func(object runtime.Object) (string, error) {
|
||||||
// TODO: replace with a swagger schema based approach (identify pod selector via schema introspection)
|
// TODO: replace with a swagger schema based approach (identify pod selector via schema introspection)
|
||||||
@ -343,7 +343,7 @@ func (f *Factory) PrintObject(cmd *cobra.Command, obj runtime.Object, out io.Wri
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
printer, err := f.PrinterForMapping(cmd, mapping)
|
printer, err := f.PrinterForMapping(cmd, mapping, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -352,7 +352,7 @@ func (f *Factory) PrintObject(cmd *cobra.Command, obj runtime.Object, out io.Wri
|
|||||||
|
|
||||||
// PrinterForMapping returns a printer suitable for displaying the provided resource type.
|
// PrinterForMapping returns a printer suitable for displaying the provided resource type.
|
||||||
// Requires that printer flags have been added to cmd (see AddPrinterFlags).
|
// Requires that printer flags have been added to cmd (see AddPrinterFlags).
|
||||||
func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMapping) (kubectl.ResourcePrinter, error) {
|
func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMapping, withNamespace bool) (kubectl.ResourcePrinter, error) {
|
||||||
printer, ok, err := PrinterForCommand(cmd)
|
printer, ok, err := PrinterForCommand(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -373,7 +373,7 @@ func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMappin
|
|||||||
}
|
}
|
||||||
printer = kubectl.NewVersionedPrinter(printer, mapping.ObjectConvertor, version, mapping.APIVersion)
|
printer = kubectl.NewVersionedPrinter(printer, mapping.ObjectConvertor, version, mapping.APIVersion)
|
||||||
} else {
|
} else {
|
||||||
printer, err = f.Printer(mapping, GetFlagBool(cmd, "no-headers"))
|
printer, err = f.Printer(mapping, GetFlagBool(cmd, "no-headers"), withNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
@ -220,6 +221,15 @@ func (b *Builder) DefaultNamespace() *Builder {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllNamespaces instructs the builder to use NamespaceAll as a namespace to request resources
|
||||||
|
// acroll all namespace. This overrides the namespace set by NamespaceParam().
|
||||||
|
func (b *Builder) AllNamespaces(allNamespace bool) *Builder {
|
||||||
|
if allNamespace {
|
||||||
|
b.namespace = api.NamespaceAll
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
// RequireNamespace instructs the builder to set the namespace value for any object found
|
// RequireNamespace instructs the builder to set the namespace value for any object found
|
||||||
// to NamespaceParam() if empty, and if the value on the resource does not match
|
// to NamespaceParam() if empty, and if the value on the resource does not match
|
||||||
// NamespaceParam() an error will be returned.
|
// NamespaceParam() an error will be returned.
|
||||||
|
@ -32,6 +32,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
|
||||||
"github.com/docker/docker/pkg/units"
|
"github.com/docker/docker/pkg/units"
|
||||||
@ -177,16 +178,18 @@ type handlerEntry struct {
|
|||||||
// will only be printed if the object type changes. This makes it useful for printing items
|
// will only be printed if the object type changes. This makes it useful for printing items
|
||||||
// recieved from watches.
|
// recieved from watches.
|
||||||
type HumanReadablePrinter struct {
|
type HumanReadablePrinter struct {
|
||||||
handlerMap map[reflect.Type]*handlerEntry
|
handlerMap map[reflect.Type]*handlerEntry
|
||||||
noHeaders bool
|
noHeaders bool
|
||||||
lastType reflect.Type
|
withNamespace bool
|
||||||
|
lastType reflect.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHumanReadablePrinter creates a HumanReadablePrinter.
|
// NewHumanReadablePrinter creates a HumanReadablePrinter.
|
||||||
func NewHumanReadablePrinter(noHeaders bool) *HumanReadablePrinter {
|
func NewHumanReadablePrinter(noHeaders, withNamespace bool) *HumanReadablePrinter {
|
||||||
printer := &HumanReadablePrinter{
|
printer := &HumanReadablePrinter{
|
||||||
handlerMap: make(map[reflect.Type]*handlerEntry),
|
handlerMap: make(map[reflect.Type]*handlerEntry),
|
||||||
noHeaders: noHeaders,
|
noHeaders: noHeaders,
|
||||||
|
withNamespace: withNamespace,
|
||||||
}
|
}
|
||||||
printer.addDefaultHandlers()
|
printer.addDefaultHandlers()
|
||||||
return printer
|
return printer
|
||||||
@ -195,7 +198,7 @@ func NewHumanReadablePrinter(noHeaders bool) *HumanReadablePrinter {
|
|||||||
// Handler adds a print handler with a given set of columns to HumanReadablePrinter instance.
|
// Handler adds a print handler with a given set of columns to HumanReadablePrinter instance.
|
||||||
// printFunc is the function that will be called to print an object.
|
// printFunc is the function that will be called to print an object.
|
||||||
// It must be of the following type:
|
// It must be of the following type:
|
||||||
// func printFunc(object ObjectType, w io.Writer) error
|
// func printFunc(object ObjectType, w io.Writer, withNamespace bool) error
|
||||||
// where ObjectType is the type of the object that will be printed.
|
// where ObjectType is the type of the object that will be printed.
|
||||||
func (h *HumanReadablePrinter) Handler(columns []string, printFunc interface{}) error {
|
func (h *HumanReadablePrinter) Handler(columns []string, printFunc interface{}) error {
|
||||||
printFuncValue := reflect.ValueOf(printFunc)
|
printFuncValue := reflect.ValueOf(printFunc)
|
||||||
@ -216,14 +219,14 @@ func (h *HumanReadablePrinter) validatePrintHandlerFunc(printFunc reflect.Value)
|
|||||||
return fmt.Errorf("invalid print handler. %#v is not a function.", printFunc)
|
return fmt.Errorf("invalid print handler. %#v is not a function.", printFunc)
|
||||||
}
|
}
|
||||||
funcType := printFunc.Type()
|
funcType := printFunc.Type()
|
||||||
if funcType.NumIn() != 2 || funcType.NumOut() != 1 {
|
if funcType.NumIn() != 3 || funcType.NumOut() != 1 {
|
||||||
return fmt.Errorf("invalid print handler." +
|
return fmt.Errorf("invalid print handler." +
|
||||||
"Must accept 2 parameters and return 1 value.")
|
"Must accept 3 parameters and return 1 value.")
|
||||||
}
|
}
|
||||||
if funcType.In(1) != reflect.TypeOf((*io.Writer)(nil)).Elem() ||
|
if funcType.In(1) != reflect.TypeOf((*io.Writer)(nil)).Elem() ||
|
||||||
funcType.Out(0) != reflect.TypeOf((*error)(nil)).Elem() {
|
funcType.Out(0) != reflect.TypeOf((*error)(nil)).Elem() {
|
||||||
return fmt.Errorf("invalid print handler. The expected signature is: "+
|
return fmt.Errorf("invalid print handler. The expected signature is: "+
|
||||||
"func handler(obj %v, w io.Writer) error", funcType.In(0))
|
"func handler(obj %v, w io.Writer, withNamespace bool) error", funcType.In(0))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -391,9 +394,16 @@ func interpretContainerStatus(status *api.ContainerStatus) (string, string, stri
|
|||||||
return "", "", "", fmt.Errorf("unknown container state %#v", *state)
|
return "", "", "", fmt.Errorf("unknown container state %#v", *state)
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPod(pod *api.Pod, w io.Writer) error {
|
func printPod(pod *api.Pod, w io.Writer, withNamespace bool) error {
|
||||||
|
var name string
|
||||||
|
if withNamespace {
|
||||||
|
name = types.NamespacedName{pod.Namespace, pod.Name}.String()
|
||||||
|
} else {
|
||||||
|
name = pod.Name
|
||||||
|
}
|
||||||
|
|
||||||
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
|
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
|
||||||
pod.Name,
|
name,
|
||||||
pod.Status.PodIP,
|
pod.Status.PodIP,
|
||||||
"", "",
|
"", "",
|
||||||
podHostString(pod.Spec.Host, pod.Status.HostIP),
|
podHostString(pod.Spec.Host, pod.Status.HostIP),
|
||||||
@ -411,8 +421,8 @@ func printPod(pod *api.Pod, w io.Writer) error {
|
|||||||
// Container status has not been reported yet. Print basic information
|
// Container status has not been reported yet. Print basic information
|
||||||
// of the containers and exit the function.
|
// of the containers and exit the function.
|
||||||
for _, container := range pod.Spec.Containers {
|
for _, container := range pod.Spec.Containers {
|
||||||
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
|
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
|
||||||
"", "", container.Name, container.Image, "", "", "", "")
|
"", "", container.Name, container.Image, "", "", "", "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -442,23 +452,30 @@ func printPod(pod *api.Pod, w io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPodList(podList *api.PodList, w io.Writer) error {
|
func printPodList(podList *api.PodList, w io.Writer, withNamespace bool) error {
|
||||||
for _, pod := range podList.Items {
|
for _, pod := range podList.Items {
|
||||||
if err := printPod(&pod, w); err != nil {
|
if err := printPod(&pod, w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPodTemplate(pod *api.PodTemplate, w io.Writer) error {
|
func printPodTemplate(pod *api.PodTemplate, w io.Writer, withNamespace bool) error {
|
||||||
|
var name string
|
||||||
|
if withNamespace {
|
||||||
|
name = types.NamespacedName{pod.Namespace, pod.Name}.String()
|
||||||
|
} else {
|
||||||
|
name = pod.Name
|
||||||
|
}
|
||||||
|
|
||||||
containers := pod.Template.Spec.Containers
|
containers := pod.Template.Spec.Containers
|
||||||
var firstContainer api.Container
|
var firstContainer api.Container
|
||||||
if len(containers) > 0 {
|
if len(containers) > 0 {
|
||||||
firstContainer, containers = containers[0], containers[1:]
|
firstContainer, containers = containers[0], containers[1:]
|
||||||
}
|
}
|
||||||
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n",
|
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n",
|
||||||
pod.Name,
|
name,
|
||||||
firstContainer.Name,
|
firstContainer.Name,
|
||||||
firstContainer.Image,
|
firstContainer.Image,
|
||||||
formatLabels(pod.Template.Labels),
|
formatLabels(pod.Template.Labels),
|
||||||
@ -476,23 +493,30 @@ func printPodTemplate(pod *api.PodTemplate, w io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPodTemplateList(podList *api.PodTemplateList, w io.Writer) error {
|
func printPodTemplateList(podList *api.PodTemplateList, w io.Writer, withNamespace bool) error {
|
||||||
for _, pod := range podList.Items {
|
for _, pod := range podList.Items {
|
||||||
if err := printPodTemplate(&pod, w); err != nil {
|
if err := printPodTemplate(&pod, w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printReplicationController(controller *api.ReplicationController, w io.Writer) error {
|
func printReplicationController(controller *api.ReplicationController, w io.Writer, withNamespace bool) error {
|
||||||
|
var name string
|
||||||
|
if withNamespace {
|
||||||
|
name = types.NamespacedName{controller.Namespace, controller.Name}.String()
|
||||||
|
} else {
|
||||||
|
name = controller.Name
|
||||||
|
}
|
||||||
|
|
||||||
containers := controller.Spec.Template.Spec.Containers
|
containers := controller.Spec.Template.Spec.Containers
|
||||||
var firstContainer api.Container
|
var firstContainer api.Container
|
||||||
if len(containers) > 0 {
|
if len(containers) > 0 {
|
||||||
firstContainer, containers = containers[0], containers[1:]
|
firstContainer, containers = containers[0], containers[1:]
|
||||||
}
|
}
|
||||||
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\n",
|
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\n",
|
||||||
controller.Name,
|
name,
|
||||||
firstContainer.Name,
|
firstContainer.Name,
|
||||||
firstContainer.Image,
|
firstContainer.Image,
|
||||||
formatLabels(controller.Spec.Selector),
|
formatLabels(controller.Spec.Selector),
|
||||||
@ -510,21 +534,29 @@ func printReplicationController(controller *api.ReplicationController, w io.Writ
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printReplicationControllerList(list *api.ReplicationControllerList, w io.Writer) error {
|
func printReplicationControllerList(list *api.ReplicationControllerList, w io.Writer, withNamespace bool) error {
|
||||||
for _, controller := range list.Items {
|
for _, controller := range list.Items {
|
||||||
if err := printReplicationController(&controller, w); err != nil {
|
if err := printReplicationController(&controller, w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printService(svc *api.Service, w io.Writer) error {
|
func printService(svc *api.Service, w io.Writer, withNamespace bool) error {
|
||||||
|
var name string
|
||||||
|
if withNamespace {
|
||||||
|
name = types.NamespacedName{svc.Namespace, svc.Name}.String()
|
||||||
|
} else {
|
||||||
|
name = svc.Name
|
||||||
|
}
|
||||||
|
|
||||||
ips := []string{svc.Spec.PortalIP}
|
ips := []string{svc.Spec.PortalIP}
|
||||||
for _, publicIP := range svc.Spec.PublicIPs {
|
for _, publicIP := range svc.Spec.PublicIPs {
|
||||||
ips = append(ips, publicIP)
|
ips = append(ips, publicIP)
|
||||||
}
|
}
|
||||||
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d/%s\n", svc.Name, formatLabels(svc.Labels),
|
|
||||||
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d/%s\n", name, formatLabels(svc.Labels),
|
||||||
formatLabels(svc.Spec.Selector), ips[0], svc.Spec.Ports[0].Port, svc.Spec.Ports[0].Protocol); err != nil {
|
formatLabels(svc.Spec.Selector), ips[0], svc.Spec.Ports[0].Port, svc.Spec.Ports[0].Protocol); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -551,51 +583,64 @@ func printService(svc *api.Service, w io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printServiceList(list *api.ServiceList, w io.Writer) error {
|
func printServiceList(list *api.ServiceList, w io.Writer, withNamespace bool) error {
|
||||||
for _, svc := range list.Items {
|
for _, svc := range list.Items {
|
||||||
if err := printService(&svc, w); err != nil {
|
if err := printService(&svc, w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printEndpoints(endpoints *api.Endpoints, w io.Writer) error {
|
func printEndpoints(endpoints *api.Endpoints, w io.Writer, withNamespace bool) error {
|
||||||
_, err := fmt.Fprintf(w, "%s\t%s\n", endpoints.Name, formatEndpoints(endpoints, nil))
|
var name string
|
||||||
|
if withNamespace {
|
||||||
|
name = types.NamespacedName{endpoints.Namespace, endpoints.Name}.String()
|
||||||
|
} else {
|
||||||
|
name = endpoints.Name
|
||||||
|
}
|
||||||
|
_, err := fmt.Fprintf(w, "%s\t%s\n", name, formatEndpoints(endpoints, nil))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func printEndpointsList(list *api.EndpointsList, w io.Writer) error {
|
func printEndpointsList(list *api.EndpointsList, w io.Writer, withNamespace bool) error {
|
||||||
for _, item := range list.Items {
|
for _, item := range list.Items {
|
||||||
if err := printEndpoints(&item, w); err != nil {
|
if err := printEndpoints(&item, w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printNamespace(item *api.Namespace, w io.Writer) error {
|
func printNamespace(item *api.Namespace, w io.Writer, withNamespace bool) error {
|
||||||
_, err := fmt.Fprintf(w, "%s\t%s\t%s\n", item.Name, formatLabels(item.Labels), item.Status.Phase)
|
_, err := fmt.Fprintf(w, "%s\t%s\t%s\n", item.Name, formatLabels(item.Labels), item.Status.Phase)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func printNamespaceList(list *api.NamespaceList, w io.Writer) error {
|
func printNamespaceList(list *api.NamespaceList, w io.Writer, withNamespace bool) error {
|
||||||
for _, item := range list.Items {
|
for _, item := range list.Items {
|
||||||
if err := printNamespace(&item, w); err != nil {
|
if err := printNamespace(&item, w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printSecret(item *api.Secret, w io.Writer) error {
|
func printSecret(item *api.Secret, w io.Writer, withNamespace bool) error {
|
||||||
_, err := fmt.Fprintf(w, "%s\t%s\t%v\n", item.Name, item.Type, len(item.Data))
|
var name string
|
||||||
|
if withNamespace {
|
||||||
|
name = types.NamespacedName{item.Namespace, item.Name}.String()
|
||||||
|
} else {
|
||||||
|
name = item.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := fmt.Fprintf(w, "%s\t%s\t%v\n", name, item.Type, len(item.Data))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func printSecretList(list *api.SecretList, w io.Writer) error {
|
func printSecretList(list *api.SecretList, w io.Writer, withNamespace bool) error {
|
||||||
for _, item := range list.Items {
|
for _, item := range list.Items {
|
||||||
if err := printSecret(&item, w); err != nil {
|
if err := printSecret(&item, w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -603,14 +648,21 @@ func printSecretList(list *api.SecretList, w io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printServiceAccount(item *api.ServiceAccount, w io.Writer) error {
|
func printServiceAccount(item *api.ServiceAccount, w io.Writer, withNamespace bool) error {
|
||||||
_, err := fmt.Fprintf(w, "%s\t%d\n", item.Name, len(item.Secrets))
|
var name string
|
||||||
|
if withNamespace {
|
||||||
|
name = types.NamespacedName{item.Namespace, item.Name}.String()
|
||||||
|
} else {
|
||||||
|
name = item.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := fmt.Fprintf(w, "%s\t%d\n", name, len(item.Secrets))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func printServiceAccountList(list *api.ServiceAccountList, w io.Writer) error {
|
func printServiceAccountList(list *api.ServiceAccountList, w io.Writer, withNamespace bool) error {
|
||||||
for _, item := range list.Items {
|
for _, item := range list.Items {
|
||||||
if err := printServiceAccount(&item, w); err != nil {
|
if err := printServiceAccount(&item, w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -618,7 +670,7 @@ func printServiceAccountList(list *api.ServiceAccountList, w io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printNode(node *api.Node, w io.Writer) error {
|
func printNode(node *api.Node, w io.Writer, withNamespace bool) error {
|
||||||
conditionMap := make(map[api.NodeConditionType]*api.NodeCondition)
|
conditionMap := make(map[api.NodeConditionType]*api.NodeCondition)
|
||||||
NodeAllConditions := []api.NodeConditionType{api.NodeReady}
|
NodeAllConditions := []api.NodeConditionType{api.NodeReady}
|
||||||
for i := range node.Status.Conditions {
|
for i := range node.Status.Conditions {
|
||||||
@ -645,16 +697,23 @@ func printNode(node *api.Node, w io.Writer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func printNodeList(list *api.NodeList, w io.Writer) error {
|
func printNodeList(list *api.NodeList, w io.Writer, withNamespace bool) error {
|
||||||
for _, node := range list.Items {
|
for _, node := range list.Items {
|
||||||
if err := printNode(&node, w); err != nil {
|
if err := printNode(&node, w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPersistentVolume(pv *api.PersistentVolume, w io.Writer) error {
|
func printPersistentVolume(pv *api.PersistentVolume, w io.Writer, withNamespace bool) error {
|
||||||
|
var name string
|
||||||
|
if withNamespace {
|
||||||
|
name = types.NamespacedName{pv.Namespace, pv.Name}.String()
|
||||||
|
} else {
|
||||||
|
name = pv.Name
|
||||||
|
}
|
||||||
|
|
||||||
claimRefUID := ""
|
claimRefUID := ""
|
||||||
if pv.Spec.ClaimRef != nil {
|
if pv.Spec.ClaimRef != nil {
|
||||||
claimRefUID += pv.Spec.ClaimRef.Namespace
|
claimRefUID += pv.Spec.ClaimRef.Namespace
|
||||||
@ -667,34 +726,41 @@ func printPersistentVolume(pv *api.PersistentVolume, w io.Writer) error {
|
|||||||
aQty := pv.Spec.Capacity[api.ResourceStorage]
|
aQty := pv.Spec.Capacity[api.ResourceStorage]
|
||||||
aSize := aQty.Value()
|
aSize := aQty.Value()
|
||||||
|
|
||||||
_, err := fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s\n", pv.Name, pv.Labels, aSize, modesStr, pv.Status.Phase, claimRefUID)
|
_, err := fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s\n", name, formatLabels(pv.Labels), aSize, modesStr, pv.Status.Phase, claimRefUID)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPersistentVolumeList(list *api.PersistentVolumeList, w io.Writer) error {
|
func printPersistentVolumeList(list *api.PersistentVolumeList, w io.Writer, withNamespace bool) error {
|
||||||
for _, pv := range list.Items {
|
for _, pv := range list.Items {
|
||||||
if err := printPersistentVolume(&pv, w); err != nil {
|
if err := printPersistentVolume(&pv, w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPersistentVolumeClaim(pvc *api.PersistentVolumeClaim, w io.Writer) error {
|
func printPersistentVolumeClaim(pvc *api.PersistentVolumeClaim, w io.Writer, withNamespace bool) error {
|
||||||
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", pvc.Name, pvc.Labels, pvc.Status.Phase, pvc.Spec.VolumeName)
|
var name string
|
||||||
|
if withNamespace {
|
||||||
|
name = types.NamespacedName{pvc.Namespace, pvc.Name}.String()
|
||||||
|
} else {
|
||||||
|
name = pvc.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", name, pvc.Labels, pvc.Status.Phase, pvc.Spec.VolumeName)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPersistentVolumeClaimList(list *api.PersistentVolumeClaimList, w io.Writer) error {
|
func printPersistentVolumeClaimList(list *api.PersistentVolumeClaimList, w io.Writer, withNamespace bool) error {
|
||||||
for _, psd := range list.Items {
|
for _, psd := range list.Items {
|
||||||
if err := printPersistentVolumeClaim(&psd, w); err != nil {
|
if err := printPersistentVolumeClaim(&psd, w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printEvent(event *api.Event, w io.Writer) error {
|
func printEvent(event *api.Event, w io.Writer, withNamespace bool) error {
|
||||||
_, err := fmt.Fprintf(
|
_, err := fmt.Fprintf(
|
||||||
w, "%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",
|
w, "%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",
|
||||||
event.FirstTimestamp.Time.Format(time.RFC1123Z),
|
event.FirstTimestamp.Time.Format(time.RFC1123Z),
|
||||||
@ -711,53 +777,67 @@ func printEvent(event *api.Event, w io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sorts and prints the EventList in a human-friendly format.
|
// Sorts and prints the EventList in a human-friendly format.
|
||||||
func printEventList(list *api.EventList, w io.Writer) error {
|
func printEventList(list *api.EventList, w io.Writer, withNamespace bool) error {
|
||||||
sort.Sort(SortableEvents(list.Items))
|
sort.Sort(SortableEvents(list.Items))
|
||||||
for i := range list.Items {
|
for i := range list.Items {
|
||||||
if err := printEvent(&list.Items[i], w); err != nil {
|
if err := printEvent(&list.Items[i], w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printLimitRange(limitRange *api.LimitRange, w io.Writer) error {
|
func printLimitRange(limitRange *api.LimitRange, w io.Writer, withNamespace bool) error {
|
||||||
|
var name string
|
||||||
|
if withNamespace {
|
||||||
|
name = types.NamespacedName{limitRange.Namespace, limitRange.Name}.String()
|
||||||
|
} else {
|
||||||
|
name = limitRange.Name
|
||||||
|
}
|
||||||
|
|
||||||
_, err := fmt.Fprintf(
|
_, err := fmt.Fprintf(
|
||||||
w, "%s\n",
|
w, "%s\n",
|
||||||
limitRange.Name,
|
name,
|
||||||
)
|
)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the LimitRangeList in a human-friendly format.
|
// Prints the LimitRangeList in a human-friendly format.
|
||||||
func printLimitRangeList(list *api.LimitRangeList, w io.Writer) error {
|
func printLimitRangeList(list *api.LimitRangeList, w io.Writer, withNamespace bool) error {
|
||||||
for i := range list.Items {
|
for i := range list.Items {
|
||||||
if err := printLimitRange(&list.Items[i], w); err != nil {
|
if err := printLimitRange(&list.Items[i], w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printResourceQuota(resourceQuota *api.ResourceQuota, w io.Writer) error {
|
func printResourceQuota(resourceQuota *api.ResourceQuota, w io.Writer, withNamespace bool) error {
|
||||||
|
var name string
|
||||||
|
if withNamespace {
|
||||||
|
name = types.NamespacedName{resourceQuota.Namespace, resourceQuota.Name}.String()
|
||||||
|
} else {
|
||||||
|
name = resourceQuota.Name
|
||||||
|
}
|
||||||
|
|
||||||
_, err := fmt.Fprintf(
|
_, err := fmt.Fprintf(
|
||||||
w, "%s\n",
|
w, "%s\n",
|
||||||
resourceQuota.Name,
|
name,
|
||||||
)
|
)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the ResourceQuotaList in a human-friendly format.
|
// Prints the ResourceQuotaList in a human-friendly format.
|
||||||
func printResourceQuotaList(list *api.ResourceQuotaList, w io.Writer) error {
|
func printResourceQuotaList(list *api.ResourceQuotaList, w io.Writer, withNamespace bool) error {
|
||||||
for i := range list.Items {
|
for i := range list.Items {
|
||||||
if err := printResourceQuota(&list.Items[i], w); err != nil {
|
if err := printResourceQuota(&list.Items[i], w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printComponentStatus(item *api.ComponentStatus, w io.Writer) error {
|
func printComponentStatus(item *api.ComponentStatus, w io.Writer, withNamespace bool) error {
|
||||||
status := "Unknown"
|
status := "Unknown"
|
||||||
message := ""
|
message := ""
|
||||||
error := ""
|
error := ""
|
||||||
@ -777,9 +857,9 @@ func printComponentStatus(item *api.ComponentStatus, w io.Writer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func printComponentStatusList(list *api.ComponentStatusList, w io.Writer) error {
|
func printComponentStatusList(list *api.ComponentStatusList, w io.Writer, withNamespace bool) error {
|
||||||
for _, item := range list.Items {
|
for _, item := range list.Items {
|
||||||
if err := printComponentStatus(&item, w); err != nil {
|
if err := printComponentStatus(&item, w, withNamespace); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -797,7 +877,7 @@ func (h *HumanReadablePrinter) PrintObj(obj runtime.Object, output io.Writer) er
|
|||||||
h.printHeader(handler.columns, w)
|
h.printHeader(handler.columns, w)
|
||||||
h.lastType = t
|
h.lastType = t
|
||||||
}
|
}
|
||||||
args := []reflect.Value{reflect.ValueOf(obj), reflect.ValueOf(w)}
|
args := []reflect.Value{reflect.ValueOf(obj), reflect.ValueOf(w), reflect.ValueOf(h.withNamespace)}
|
||||||
resultValue := handler.printFunc.Call(args)[0]
|
resultValue := handler.printFunc.Call(args)[0]
|
||||||
if resultValue.IsNil() {
|
if resultValue.IsNil() {
|
||||||
return nil
|
return nil
|
||||||
|
@ -237,18 +237,18 @@ type TestUnknownType struct{}
|
|||||||
|
|
||||||
func (*TestUnknownType) IsAnAPIObject() {}
|
func (*TestUnknownType) IsAnAPIObject() {}
|
||||||
|
|
||||||
func PrintCustomType(obj *TestPrintType, w io.Writer) error {
|
func PrintCustomType(obj *TestPrintType, w io.Writer, withNamespace bool) error {
|
||||||
_, err := fmt.Fprintf(w, "%s", obj.Data)
|
_, err := fmt.Fprintf(w, "%s", obj.Data)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrorPrintHandler(obj *TestPrintType, w io.Writer) error {
|
func ErrorPrintHandler(obj *TestPrintType, w io.Writer, withNamespace bool) error {
|
||||||
return fmt.Errorf("ErrorPrintHandler error")
|
return fmt.Errorf("ErrorPrintHandler error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCustomTypePrinting(t *testing.T) {
|
func TestCustomTypePrinting(t *testing.T) {
|
||||||
columns := []string{"Data"}
|
columns := []string{"Data"}
|
||||||
printer := NewHumanReadablePrinter(false)
|
printer := NewHumanReadablePrinter(false, false)
|
||||||
printer.Handler(columns, PrintCustomType)
|
printer.Handler(columns, PrintCustomType)
|
||||||
|
|
||||||
obj := TestPrintType{"test object"}
|
obj := TestPrintType{"test object"}
|
||||||
@ -265,7 +265,7 @@ func TestCustomTypePrinting(t *testing.T) {
|
|||||||
|
|
||||||
func TestPrintHandlerError(t *testing.T) {
|
func TestPrintHandlerError(t *testing.T) {
|
||||||
columns := []string{"Data"}
|
columns := []string{"Data"}
|
||||||
printer := NewHumanReadablePrinter(false)
|
printer := NewHumanReadablePrinter(false, false)
|
||||||
printer.Handler(columns, ErrorPrintHandler)
|
printer.Handler(columns, ErrorPrintHandler)
|
||||||
obj := TestPrintType{"test object"}
|
obj := TestPrintType{"test object"}
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
@ -276,7 +276,7 @@ func TestPrintHandlerError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUnknownTypePrinting(t *testing.T) {
|
func TestUnknownTypePrinting(t *testing.T) {
|
||||||
printer := NewHumanReadablePrinter(false)
|
printer := NewHumanReadablePrinter(false, false)
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
err := printer.PrintObj(&TestUnknownType{}, buffer)
|
err := printer.PrintObj(&TestUnknownType{}, buffer)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -465,8 +465,8 @@ func TestPrinters(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
printers := map[string]ResourcePrinter{
|
printers := map[string]ResourcePrinter{
|
||||||
"humanReadable": NewHumanReadablePrinter(true),
|
"humanReadable": NewHumanReadablePrinter(true, false),
|
||||||
"humanReadableHeaders": NewHumanReadablePrinter(false),
|
"humanReadableHeaders": NewHumanReadablePrinter(false, false),
|
||||||
"json": &JSONPrinter{},
|
"json": &JSONPrinter{},
|
||||||
"yaml": &YAMLPrinter{},
|
"yaml": &YAMLPrinter{},
|
||||||
"template": templatePrinter,
|
"template": templatePrinter,
|
||||||
@ -503,7 +503,7 @@ func TestPrinters(t *testing.T) {
|
|||||||
|
|
||||||
func TestPrintEventsResultSorted(t *testing.T) {
|
func TestPrintEventsResultSorted(t *testing.T) {
|
||||||
// Arrange
|
// Arrange
|
||||||
printer := NewHumanReadablePrinter(false /* noHeaders */)
|
printer := NewHumanReadablePrinter(false /* noHeaders */, false)
|
||||||
|
|
||||||
obj := api.EventList{
|
obj := api.EventList{
|
||||||
Items: []api.Event{
|
Items: []api.Event{
|
||||||
@ -544,7 +544,7 @@ func TestPrintEventsResultSorted(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintMinionStatus(t *testing.T) {
|
func TestPrintMinionStatus(t *testing.T) {
|
||||||
printer := NewHumanReadablePrinter(false)
|
printer := NewHumanReadablePrinter(false, false)
|
||||||
table := []struct {
|
table := []struct {
|
||||||
minion api.Node
|
minion api.Node
|
||||||
status string
|
status string
|
||||||
@ -727,7 +727,7 @@ func TestPrintHumanReadableService(t *testing.T) {
|
|||||||
|
|
||||||
for _, svc := range tests {
|
for _, svc := range tests {
|
||||||
buff := bytes.Buffer{}
|
buff := bytes.Buffer{}
|
||||||
printService(&svc, &buff)
|
printService(&svc, &buff, false)
|
||||||
output := string(buff.Bytes())
|
output := string(buff.Bytes())
|
||||||
ip := svc.Spec.PortalIP
|
ip := svc.Spec.PortalIP
|
||||||
if !strings.Contains(output, ip) {
|
if !strings.Contains(output, ip) {
|
||||||
@ -855,6 +855,179 @@ func TestInterpretContainerStatus(t *testing.T) {
|
|||||||
if msg != test.expectedMessage {
|
if msg != test.expectedMessage {
|
||||||
t.Errorf("expected: %s, got: %s", test.expectedMessage, msg)
|
t.Errorf("expected: %s, got: %s", test.expectedMessage, msg)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrintHumanReadableWithNamespace(t *testing.T) {
|
||||||
|
namespaceName := "testnamespace"
|
||||||
|
name := "test"
|
||||||
|
table := []struct {
|
||||||
|
obj runtime.Object
|
||||||
|
printNamespace bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
obj: &api.Pod{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||||
|
},
|
||||||
|
printNamespace: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &api.ReplicationController{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||||
|
Spec: api.ReplicationControllerSpec{
|
||||||
|
Replicas: 2,
|
||||||
|
Template: &api.PodTemplateSpec{
|
||||||
|
ObjectMeta: api.ObjectMeta{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"name": "foo",
|
||||||
|
"type": "production",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Spec: api.PodSpec{
|
||||||
|
Containers: []api.Container{
|
||||||
|
{
|
||||||
|
Image: "foo/bar",
|
||||||
|
TerminationMessagePath: api.TerminationMessagePathDefault,
|
||||||
|
ImagePullPolicy: api.PullIfNotPresent,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RestartPolicy: api.RestartPolicyAlways,
|
||||||
|
DNSPolicy: api.DNSDefault,
|
||||||
|
NodeSelector: map[string]string{
|
||||||
|
"baz": "blah",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
printNamespace: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &api.Service{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||||
|
Spec: api.ServiceSpec{
|
||||||
|
PortalIP: "1.2.3.4",
|
||||||
|
PublicIPs: []string{
|
||||||
|
"2.3.4.5",
|
||||||
|
},
|
||||||
|
Ports: []api.ServicePort{
|
||||||
|
{
|
||||||
|
Port: 80,
|
||||||
|
Protocol: "TCP",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
printNamespace: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &api.Endpoints{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||||
|
Subsets: []api.EndpointSubset{{
|
||||||
|
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}, {IP: "localhost"}},
|
||||||
|
Ports: []api.EndpointPort{{Port: 8080}},
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
printNamespace: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &api.Namespace{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: name},
|
||||||
|
},
|
||||||
|
printNamespace: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &api.Secret{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||||
|
},
|
||||||
|
printNamespace: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &api.ServiceAccount{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||||
|
Secrets: []api.ObjectReference{},
|
||||||
|
},
|
||||||
|
printNamespace: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &api.Node{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: name},
|
||||||
|
Status: api.NodeStatus{},
|
||||||
|
},
|
||||||
|
printNamespace: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &api.PersistentVolume{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||||
|
Spec: api.PersistentVolumeSpec{},
|
||||||
|
},
|
||||||
|
printNamespace: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &api.PersistentVolumeClaim{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||||
|
Spec: api.PersistentVolumeClaimSpec{},
|
||||||
|
},
|
||||||
|
printNamespace: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &api.Event{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||||
|
Source: api.EventSource{Component: "kubelet"},
|
||||||
|
Message: "Item 1",
|
||||||
|
FirstTimestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
|
||||||
|
LastTimestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
|
||||||
|
Count: 1,
|
||||||
|
},
|
||||||
|
printNamespace: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &api.LimitRange{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||||
|
},
|
||||||
|
printNamespace: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &api.ResourceQuota{
|
||||||
|
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||||
|
},
|
||||||
|
printNamespace: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
obj: &api.ComponentStatus{
|
||||||
|
Conditions: []api.ComponentCondition{
|
||||||
|
{Type: api.ComponentHealthy, Status: api.ConditionTrue, Message: "ok", Error: ""},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
printNamespace: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
printer := NewHumanReadablePrinter(false, false)
|
||||||
|
for _, test := range table {
|
||||||
|
buffer := &bytes.Buffer{}
|
||||||
|
err := printer.PrintObj(test.obj, buffer)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("An error occurred printing object: %#v", err)
|
||||||
|
}
|
||||||
|
matched := contains(strings.Fields(buffer.String()), fmt.Sprintf("%s/%s", namespaceName, name))
|
||||||
|
if matched {
|
||||||
|
t.Errorf("Expect printing object not to contain namespace: %v", test.obj)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printer = NewHumanReadablePrinter(false, true)
|
||||||
|
for _, test := range table {
|
||||||
|
buffer := &bytes.Buffer{}
|
||||||
|
err := printer.PrintObj(test.obj, buffer)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("An error occurred printing object: %#v", err)
|
||||||
|
}
|
||||||
|
matched := contains(strings.Fields(buffer.String()), fmt.Sprintf("%s/%s", namespaceName, name))
|
||||||
|
if test.printNamespace && !matched {
|
||||||
|
t.Errorf("Expect printing object to contain namespace: %v", test.obj)
|
||||||
|
} else if !test.printNamespace && matched {
|
||||||
|
t.Errorf("Expect printing object not to contain namespace: %v", test.obj)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user