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

Add structured validation for the API types #216

Merged
merged 3 commits into from
Jul 18, 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
60 changes: 7 additions & 53 deletions api/ignite.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
+k8s:deepcopy-gen=package
+k8s:defaulter-gen=TypeMeta
+k8s:openapi-gen=true
+k8s:conversion-gen=github.com/weaveworks/ignite/pkg/apis/ignite



Expand All @@ -26,7 +27,6 @@
* [func SetDefaults_VMNetworkSpec(obj *VMNetworkSpec)](#SetDefaults_VMNetworkSpec)
* [func SetDefaults_VMSpec(obj *VMSpec)](#SetDefaults_VMSpec)
* [func SetDefaults_VMStatus(obj *VMStatus)](#SetDefaults_VMStatus)
* [func ValidateNetworkMode(mode NetworkMode) error](#ValidateNetworkMode)
* [type FileMapping](#FileMapping)
* [type Image](#Image)
* [type ImageSourceType](#ImageSourceType)
Expand All @@ -36,7 +36,6 @@
* [type KernelSpec](#KernelSpec)
* [type KernelStatus](#KernelStatus)
* [type NetworkMode](#NetworkMode)
* [func GetNetworkModes() []NetworkMode](#GetNetworkModes)
* [func (nm NetworkMode) String() string](#NetworkMode.String)
* [type OCIImageClaim](#OCIImageClaim)
* [type OCIImageSource](#OCIImageSource)
Expand All @@ -49,8 +48,6 @@
* [func (s *SSH) MarshalJSON() ([]byte, error)](#SSH.MarshalJSON)
* [func (s *SSH) UnmarshalJSON(b []byte) error](#SSH.UnmarshalJSON)
* [type VM](#VM)
* [func (vm *VM) SetImage(image *Image)](#VM.SetImage)
* [func (vm *VM) SetKernel(kernel *Kernel)](#VM.SetKernel)
* [type VMImageSpec](#VMImageSpec)
* [type VMKernelSpec](#VMKernelSpec)
* [type VMNetworkSpec](#VMNetworkSpec)
Expand All @@ -60,30 +57,21 @@


#### <a name="pkg-files">Package files</a>
[defaults.go](/pkg/apis/ignite/v1alpha1/defaults.go) [doc.go](/pkg/apis/ignite/v1alpha1/doc.go) [helpers.go](/pkg/apis/ignite/v1alpha1/helpers.go) [json.go](/pkg/apis/ignite/v1alpha1/json.go) [register.go](/pkg/apis/ignite/v1alpha1/register.go) [types.go](/pkg/apis/ignite/v1alpha1/types.go)
[defaults.go](/pkg/apis/ignite/v1alpha1/defaults.go) [doc.go](/pkg/apis/ignite/v1alpha1/doc.go) [json.go](/pkg/apis/ignite/v1alpha1/json.go) [register.go](/pkg/apis/ignite/v1alpha1/register.go) [types.go](/pkg/apis/ignite/v1alpha1/types.go)


## <a name="pkg-constants">Constants</a>
``` go
const (
// GroupName is the group name use in this package
GroupName = "ignite.weave.works"

// VMKind returns the kind for the VM API type
VMKind = "VM"
// KernelKind returns the kind for the Kernel API type
KernelKind = "Kernel"
// PoolKind returns the kind for the Pool API type
PoolKind = "Pool"
// ImageKind returns the kind for the Image API type
ImageKind = "Image"
KindImage meta.Kind = "Image"
KindKernel meta.Kind = "Kernel"
KindVM meta.Kind = "VM"
)
```
``` go
const (
KindImage meta.Kind = "Image"
KindKernel meta.Kind = "Kernel"
KindVM meta.Kind = "VM"
// GroupName is the group name use in this package
GroupName = "ignite.weave.works"
)
```

Expand Down Expand Up @@ -165,15 +153,6 @@ func SetDefaults_VMStatus(obj *VMStatus)
```


## <a name="ValidateNetworkMode">func</a> [ValidateNetworkMode](/pkg/apis/ignite/v1alpha1/helpers.go?s=317:365#L15)
``` go
func ValidateNetworkMode(mode NetworkMode) error
```
ValidateNetworkMode validates the network mode
TODO: This should move into a dedicated validation package




## <a name="FileMapping">type</a> [FileMapping](/pkg/apis/ignite/v1alpha1/types.go?s=7677:7772#L206)
``` go
Expand Down Expand Up @@ -364,13 +343,6 @@ const (



### <a name="GetNetworkModes">func</a> [GetNetworkModes](/pkg/apis/ignite/v1alpha1/helpers.go?s=92:128#L6)
``` go
func GetNetworkModes() []NetworkMode
```
GetNetworkModes gets the list of available network modes





Expand Down Expand Up @@ -615,24 +587,6 @@ 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=856:895#L36)
``` go
func (vm *VM) SetKernel(kernel *Kernel)
```
SetKernel populates relevant fields to a Kernel on the VM object




## <a name="VMImageSpec">type</a> [VMImageSpec](/pkg/apis/ignite/v1alpha1/types.go?s=7298:7367#L191)
``` go
type VMImageSpec struct {
Expand Down
6 changes: 1 addition & 5 deletions cmd/ignite/cmd/cmdutil/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ type NetworkModeFlag struct {
}

func (nf *NetworkModeFlag) Set(val string) error {
nm := api.NetworkMode(val)
if err := api.ValidateNetworkMode(nm); err != nil {
return err
}
*nf.value = nm
*nf.value = api.NetworkMode(val)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/ignite/run/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"path"
"strings"

"github.com/weaveworks/ignite/pkg/apis/ignite/scheme"
api "github.com/weaveworks/ignite/pkg/apis/ignite"
"github.com/weaveworks/ignite/pkg/apis/ignite/scheme"
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"github.com/weaveworks/ignite/pkg/client"
"github.com/weaveworks/ignite/pkg/metadata"
Expand Down
2 changes: 1 addition & 1 deletion cmd/ignite/run/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"strings"

"github.com/weaveworks/ignite/pkg/apis/ignite/scheme"
api "github.com/weaveworks/ignite/pkg/apis/ignite"
"github.com/weaveworks/ignite/pkg/apis/ignite/scheme"
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"github.com/weaveworks/ignite/pkg/client"
"github.com/weaveworks/ignite/pkg/filter"
Expand Down
Loading