Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Object inspection support #107

Merged
merged 2 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions api/ignite.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
## <a name="pkg-index">Index</a>
* [Constants](#pkg-constants)
* [Variables](#pkg-variables)
* [func SetDefaults_Image(obj *Image)](#SetDefaults_Image)
* [func SetDefaults_Kernel(obj *Kernel)](#SetDefaults_Kernel)
* [func SetDefaults_OCIImageClaim(obj *OCIImageClaim)](#SetDefaults_OCIImageClaim)
* [func SetDefaults_PoolSpec(obj *PoolSpec)](#SetDefaults_PoolSpec)
* [func SetDefaults_VM(obj *VM)](#SetDefaults_VM)
* [func SetDefaults_VMKernelSpec(obj *VMKernelSpec)](#SetDefaults_VMKernelSpec)
* [func SetDefaults_VMSpec(obj *VMSpec)](#SetDefaults_VMSpec)
* [func SetDefaults_VMStatus(obj *VMStatus)](#SetDefaults_VMStatus)
Expand All @@ -42,6 +45,8 @@
* [type PoolStatus](#PoolStatus)
* [type SSH](#SSH)
* [type VM](#VM)
* [func (vm *VM) SetImage(image *Image)](#VM.SetImage)
* [func (vm *VM) SetKernel(kernel *Kernel)](#VM.SetKernel)
* [type VMImageSource](#VMImageSource)
* [type VMImageSpec](#VMImageSpec)
* [type VMKernelSpec](#VMKernelSpec)
Expand Down Expand Up @@ -93,31 +98,51 @@ SchemeGroupVersion is group version used to register these objects



## <a name="SetDefaults_OCIImageClaim">func</a> [SetDefaults_OCIImageClaim](/pkg/apis/ignite/v1alpha1/defaults.go?s=263:313#L13)
## <a name="SetDefaults_Image">func</a> [SetDefaults_Image](/pkg/apis/ignite/v1alpha1/defaults.go?s=2025:2059#L83)
``` go
func SetDefaults_Image(obj *Image)
```


## <a name="SetDefaults_Kernel">func</a> [SetDefaults_Kernel](/pkg/apis/ignite/v1alpha1/defaults.go?s=2083:2119#L87)
``` go
func SetDefaults_Kernel(obj *Kernel)
```


## <a name="SetDefaults_OCIImageClaim">func</a> [SetDefaults_OCIImageClaim](/pkg/apis/ignite/v1alpha1/defaults.go?s=274:324#L14)
``` go
func SetDefaults_OCIImageClaim(obj *OCIImageClaim)
```


## <a name="SetDefaults_PoolSpec">func</a> [SetDefaults_PoolSpec](/pkg/apis/ignite/v1alpha1/defaults.go?s=353:393#L17)
## <a name="SetDefaults_PoolSpec">func</a> [SetDefaults_PoolSpec](/pkg/apis/ignite/v1alpha1/defaults.go?s=364:404#L18)
``` go
func SetDefaults_PoolSpec(obj *PoolSpec)
```


## <a name="SetDefaults_VMKernelSpec">func</a> [SetDefaults_VMKernelSpec](/pkg/apis/ignite/v1alpha1/defaults.go?s=1315:1363#L57)
## <a name="SetDefaults_VM">func</a> [SetDefaults_VM](/pkg/apis/ignite/v1alpha1/defaults.go?s=1973:2001#L79)
``` go
func SetDefaults_VM(obj *VM)
```
TODO: Temporary hacks to populate TypeMeta until we get the generator working



## <a name="SetDefaults_VMKernelSpec">func</a> [SetDefaults_VMKernelSpec](/pkg/apis/ignite/v1alpha1/defaults.go?s=1326:1374#L58)
``` go
func SetDefaults_VMKernelSpec(obj *VMKernelSpec)
```


## <a name="SetDefaults_VMSpec">func</a> [SetDefaults_VMSpec](/pkg/apis/ignite/v1alpha1/defaults.go?s=919:955#L39)
## <a name="SetDefaults_VMSpec">func</a> [SetDefaults_VMSpec](/pkg/apis/ignite/v1alpha1/defaults.go?s=930:966#L40)
``` go
func SetDefaults_VMSpec(obj *VMSpec)
```


## <a name="SetDefaults_VMStatus">func</a> [SetDefaults_VMStatus](/pkg/apis/ignite/v1alpha1/defaults.go?s=1449:1489#L63)
## <a name="SetDefaults_VMStatus">func</a> [SetDefaults_VMStatus](/pkg/apis/ignite/v1alpha1/defaults.go?s=1460:1500#L64)
``` go
func SetDefaults_VMStatus(obj *VMStatus)
```
Expand Down Expand Up @@ -548,6 +573,24 @@ These files are stored in /var/lib/firecracker/vm/{vm-id}/metadata.json



### <a name="VM.SetImage">func</a> (\*VM) [SetImage](/pkg/apis/ignite/v1alpha1/helpers.go?s=658:694#L30)
``` go
func (vm *VM) SetImage(image *Image)
```
SetImage populates relevant fields to an Image on the VM object




### <a name="VM.SetKernel">func</a> (\*VM) [SetKernel](/pkg/apis/ignite/v1alpha1/helpers.go?s=942:981#L38)
``` go
func (vm *VM) SetKernel(kernel *Kernel)
```
SetKernel populates relevant fields to a Kernel on the VM object




## <a name="VMImageSource">type</a> [VMImageSource](/pkg/apis/ignite/v1alpha1/types.go?s=8568:8676#L232)
``` go
type VMImageSource struct {
Expand Down
45 changes: 45 additions & 0 deletions cmd/ignite/cmd/inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cmd

import (
"io"

"github.com/lithammer/dedent"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/weaveworks/ignite/cmd/ignite/run"
"github.com/weaveworks/ignite/pkg/errutils"
)

// NewCmdInspect inspects an Ignite Object
func NewCmdInspect(out io.Writer) *cobra.Command {
i := &run.InspectFlags{}

cmd := &cobra.Command{
Use: "inspect <kind> <object>",
Short: "Inspect an Ignite Object",
Long: dedent.Dedent(`
Retrieve information about the given object of the given kind.
The kind can be "image", "kernel" or "vm". The object is matched
by prefix based on its ID and name. Outputs JSON by default, can
be overridden with the output flag (-o, --output).
`),
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
errutils.Check(func() error {
io, err := i.NewInspectOptions(args[0], args[1])
if err != nil {
return err
}

return run.Inspect(io)
}())
},
}

addInspectFlags(cmd.Flags(), i)
return cmd
}

func addInspectFlags(fs *pflag.FlagSet, i *run.InspectFlags) {
fs.StringVarP(&i.OutputFormat, "output", "o", "json", "Output the object in the specified format")
}
1 change: 1 addition & 0 deletions cmd/ignite/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command {
root.AddCommand(NewCmdKill(os.Stdout))
root.AddCommand(NewCmdLogs(os.Stdout))
root.AddCommand(NewCmdGitOps(os.Stdout))
root.AddCommand(NewCmdInspect(os.Stdout))
root.AddCommand(NewCmdPs(os.Stdout))
root.AddCommand(NewCmdRm(os.Stdout))
root.AddCommand(NewCmdRmi(os.Stdout))
Expand Down
68 changes: 68 additions & 0 deletions cmd/ignite/run/inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package run

import (
"bytes"
"fmt"
"strings"

"github.com/weaveworks/ignite/pkg/apis/ignite/scheme"
"github.com/weaveworks/ignite/pkg/client"
"github.com/weaveworks/ignite/pkg/filter"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: grouping

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c6622cf.


meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
)

type InspectFlags struct {
OutputFormat string
}

type inspectOptions struct {
*InspectFlags
object meta.Object
}

func (i *InspectFlags) NewInspectOptions(k, objectMatch string) (*inspectOptions, error) {
var err error
var kind meta.Kind
io := &inspectOptions{InspectFlags: i}

switch strings.ToLower(k) {
case meta.KindImage.Lower():
kind = meta.KindImage
case meta.KindKernel.Lower():
kind = meta.KindKernel
case meta.KindVM.Lower():
kind = meta.KindVM
default:
return nil, fmt.Errorf("unrecognized kind: %q", k)
}

if io.object, err = client.Dynamic(kind).Find(filter.NewIDNameFilter(objectMatch)); err != nil {
return nil, err
}

return io, nil
}

func Inspect(io *inspectOptions) error {
var b []byte
var err error

// Select the encoder and encode the object with it
switch io.OutputFormat {
case "json":
b, err = scheme.Serializer.EncodeJSON(io.object)
case "yaml":
b, err = scheme.Serializer.EncodeYAML(io.object)
default:
err = fmt.Errorf("unrecognized output format: %q", io.OutputFormat)
}

if err != nil {
return err
}

// Print the encoded object
fmt.Println(string(bytes.TrimSpace(b)))
return nil
}
1 change: 1 addition & 0 deletions docs/cli/ignite.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Example usage:
* [ignite create](ignite_create.md) - Create a new VM without starting it
* [ignite gitops](ignite_gitops.md) - Run the GitOps feature of Ignite
* [ignite image](ignite_image.md) - Manage base images for VMs
* [ignite inspect](ignite_inspect.md) - Inspect an Ignite Object
* [ignite kernel](ignite_kernel.md) - Manage VM kernels
* [ignite kill](ignite_kill.md) - Kill running VMs
* [ignite logs](ignite_logs.md) - Get the logs for a running VM
Expand Down
34 changes: 34 additions & 0 deletions docs/cli/ignite_inspect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## ignite inspect

Inspect an Ignite Object

### Synopsis


Retrieve information about the given object of the given kind.
The kind can be "image", "kernel" or "vm". The object is matched
by prefix based on its ID and name. Outputs JSON by default, can
be overridden to YAML with the yaml flag (-y, --yaml).


```
ignite inspect <kind> <object> [flags]
```

### Options

```
-h, --help help for inspect
-o, --output string Output the object in the specified format (default "json")
```

### Options inherited from parent commands

```
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO

* [ignite](ignite.md) - ignite: easily run Firecracker VMs

3 changes: 2 additions & 1 deletion pkg/apis/ignite/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package v1alpha1

import (
"reflect"

meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"github.com/weaveworks/ignite/pkg/constants"
"k8s.io/apimachinery/pkg/runtime"
"reflect"
)

func addDefaultingFuncs(scheme *runtime.Scheme) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/ignite/v1alpha1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ func (vm *VM) SetKernel(kernel *Kernel) {
vm.Status.Kernel.OCIImageSource = kernel.Status.OCISource
// TODO: Remove this
vm.Status.Kernel.UID = kernel.GetUID()
}
}
3 changes: 2 additions & 1 deletion pkg/storage/cache.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package storage

import (
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"log"

meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
)

// Cache is an intermediate caching layer, which conforms to Storage
Expand Down