Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
Add inspect command
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Jan 13, 2020
1 parent 49e287a commit 8f42e2b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -77,6 +77,7 @@ COMMANDS:
pull Pull an image or a repository from a registry
rmi Remove one or more images
push Push an image or a repository to a registry
inspect Return low-level information on k3c objects
events Get real time events from the server
daemon Run the container daemon
volume, volumes, v Manage volumes
Expand Down
35 changes: 35 additions & 0 deletions cmd/inspect/inspect.go
@@ -0,0 +1,35 @@
package inspect

import (
"github.com/rancher/k3c/pkg/cliclient"
"github.com/rancher/k3c/pkg/tables"
"github.com/urfave/cli/v2"
)

type Inspect struct {
Format string `usage:"Pretty-print images using a Go template" default:"json"`
}

func (i *Inspect) Run(ctx *cli.Context) error {
c, err := cliclient.New(ctx)
if err != nil {
return err
}

t := tables.NewInspect(ctx)

for _, arg := range ctx.Args().Slice() {
container, _, _, err := c.GetContainer(ctx.Context, arg)
if err == nil {
t.Write(container)
continue
}

image, err := c.GetImage(ctx.Context, arg)
if err == nil {
t.Write(image)
}
}

return t.Close()
}
5 changes: 4 additions & 1 deletion main.go
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/rancher/k3c/cmd/events"
"github.com/rancher/k3c/cmd/exec"
"github.com/rancher/k3c/cmd/images"
"github.com/rancher/k3c/cmd/inspect"
"github.com/rancher/k3c/cmd/logs"
"github.com/rancher/k3c/cmd/ps"
"github.com/rancher/k3c/cmd/pull"
Expand All @@ -33,7 +34,6 @@ import (
)

var (
//asdf
appName = filepath.Base(os.Args[0])
debugConfig debug.Config
)
Expand Down Expand Up @@ -101,6 +101,9 @@ func main() {
command(&push.Push{},
"Push an image or a repository to a registry",
"NAME[:TAG]"),
command(&inspect.Inspect{},
"Return low-level information on k3c objects",
"NAME|ID [NAME|ID...]"),

command(&events.Events{},
"Get real time events from the server",
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/container.go
Expand Up @@ -171,7 +171,7 @@ func (c *Daemon) Attach(ctx context.Context, name string, opts *v1alpha1.AttachO
}

func (c *Daemon) GetContainer(ctx context.Context, name string) (*v1.Pod, *v1.Container, string, error) {
pods, err := c.listPods(ctx, false)
pods, err := c.listPods(ctx, true)
if err != nil {
return nil, nil, "", err
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/tables/inspect.go
@@ -0,0 +1,15 @@
package tables

import (
"github.com/rancher/k3c/pkg/table"
"github.com/urfave/cli/v2"
)

func NewInspect(cli *cli.Context) table.Writer {
cols := [][]string{
{"", "{{. | json}}"},
}

w := table.NewWriter(cols, config(cli, ""))
return w
}

0 comments on commit 8f42e2b

Please sign in to comment.