From 825bb0b32a56988d93de42c0ce18df475b55fc22 Mon Sep 17 00:00:00 2001 From: Dennis Marttinen Date: Fri, 9 Aug 2019 16:25:16 +0300 Subject: [PATCH 1/5] Remove RepoDigests, Replace with new OCIContentID, implement parsers --- pkg/apis/ignite/types.go | 10 +--- pkg/apis/ignite/v1alpha2/types.go | 10 +--- pkg/apis/meta/v1alpha1/image.go | 96 +++++++++++++++++++++++++++++-- pkg/source/docker.go | 22 ++++++- 4 files changed, 113 insertions(+), 25 deletions(-) diff --git a/pkg/apis/ignite/types.go b/pkg/apis/ignite/types.go index cfc862635..75d1ad8a0 100644 --- a/pkg/apis/ignite/types.go +++ b/pkg/apis/ignite/types.go @@ -52,16 +52,10 @@ type OCIImageClaim struct { // OCIImageSource specifies how the OCI image was imported. // It is the status variant of OCIImageClaim type OCIImageSource struct { - // ID defines the source's ID (e.g. the Docker image ID) - ID string `json:"id"` + // ID defines the source's content ID (e.g. the canonical OCI path or Docker image ID) + ID *meta.OCIContentID `json:"id"` // Size defines the size of the source in bytes Size meta.Size `json:"size"` - // RepoDigests defines the image name as it was when pulled - // from a repository, and the digest of the image - // The format is $registry/$user/$image@sha256:$digest - // This field is unpopulated if the image used as the source - // has never been pushed to or pulled from a registry - RepoDigests []string `json:"repoDigests,omitempty"` } // ImageStatus defines the status of the image diff --git a/pkg/apis/ignite/v1alpha2/types.go b/pkg/apis/ignite/v1alpha2/types.go index 2002656e5..7324db32c 100644 --- a/pkg/apis/ignite/v1alpha2/types.go +++ b/pkg/apis/ignite/v1alpha2/types.go @@ -52,16 +52,10 @@ type OCIImageClaim struct { // OCIImageSource specifies how the OCI image was imported. // It is the status variant of OCIImageClaim type OCIImageSource struct { - // ID defines the source's ID (e.g. the Docker image ID) - ID string `json:"id"` + // ID defines the source's content ID (e.g. the canonical OCI path or Docker image ID) + ID *meta.OCIContentID `json:"id"` // Size defines the size of the source in bytes Size meta.Size `json:"size"` - // RepoDigests defines the image name as it was when pulled - // from a repository, and the digest of the image - // The format is $registry/$user/$image@sha256:$digest - // This field is unpopulated if the image used as the source - // has never been pushed to or pulled from a registry - RepoDigests []string `json:"repoDigests,omitempty"` } // ImageStatus defines the status of the image diff --git a/pkg/apis/meta/v1alpha1/image.go b/pkg/apis/meta/v1alpha1/image.go index 6fc7cceb2..a8b45899f 100644 --- a/pkg/apis/meta/v1alpha1/image.go +++ b/pkg/apis/meta/v1alpha1/image.go @@ -3,19 +3,21 @@ package v1alpha1 import ( "encoding/json" "fmt" + "net/url" "github.com/containers/image/docker/reference" + "github.com/opencontainers/go-digest" ) // NewOCIImageRef parses and normalizes a reference to an OCI (docker) image. func NewOCIImageRef(imageStr string) (OCIImageRef, error) { named, err := reference.ParseDockerRef(imageStr) if err != nil { - return OCIImageRef(""), err + return "", err } namedTagged, ok := named.(reference.NamedTagged) if !ok { - return OCIImageRef(""), fmt.Errorf("could not parse image name with a tag %s", imageStr) + return "", fmt.Errorf("could not parse image name with a tag %s", imageStr) } return OCIImageRef(reference.FamiliarString(namedTagged)), nil } @@ -32,10 +34,6 @@ func (i OCIImageRef) IsUnset() bool { return len(i) == 0 } -func (i OCIImageRef) MarshalJSON() ([]byte, error) { - return json.Marshal(string(i)) -} - func (i *OCIImageRef) UnmarshalJSON(b []byte) error { var str string var err error @@ -47,3 +45,89 @@ func (i *OCIImageRef) UnmarshalJSON(b []byte) error { *i, err = NewOCIImageRef(str) return err } + +func ParseOCIContentID(str string) (*OCIContentID, error) { + named, err := reference.ParseDockerRef(str) + if err != nil { + return nil, err + } + + if canonical, ok := named.(reference.Canonical); ok { + return &OCIContentID{ + repoName: named.Name(), + digest: canonical.Digest().String(), + }, nil + } + + d, err := digest.Parse(str) + if err != nil { + return nil, err + } + + return &OCIContentID{ + digest: d.String(), + }, nil +} + +type OCIContentID struct { + repoName string // Fully qualified image name, e.g. "docker.io/library/node" or blank if the image is local + digest string // Repo digest of the image, or sha256sum provided by the source if the image is local +} + +var _ json.Marshaler = &OCIContentID{} +var _ json.Unmarshaler = &OCIContentID{} + +func (o *OCIContentID) String() string { + if len(o.repoName) > 0 { + return fmt.Sprintf("oci://%s", o.RepoDigest()) + } + + return fmt.Sprintf("docker://%s", o.Digest()) +} + +func parseOCIString(s string) (*OCIContentID, error) { + u, err := url.Parse(s) + if err != nil { + return nil, err + } + + // Remove the "docker://" or "oci://" scheme by only caring about the host and path + return ParseOCIContentID(u.Host + u.Path) +} + +// Local returns true if the image has no repoName, i.e. it's not available from a registry +func (o *OCIContentID) Local() bool { + return len(o.repoName) == 0 +} + +// Digest is a getter for the digest field +func (o *OCIContentID) Digest() string { + return o.digest +} + +// RepoDigest returns a repo digest based on the OCIContentID if it is not local +func (o *OCIContentID) RepoDigest() (s string) { + if !o.Local() { + s = fmt.Sprintf("%s@%s", o.repoName, o.digest) + } + + return +} + +func (o *OCIContentID) MarshalJSON() ([]byte, error) { + return json.Marshal(o.String()) +} + +func (o *OCIContentID) UnmarshalJSON(b []byte) (err error) { + var s string + if err = json.Unmarshal(b, &s); err != nil { + return err + } + + var id *OCIContentID + if id, err = parseOCIString(s); err == nil { + *o = *id + } + + return +} diff --git a/pkg/source/docker.go b/pkg/source/docker.go index fc767b195..ba14465ad 100644 --- a/pkg/source/docker.go +++ b/pkg/source/docker.go @@ -54,10 +54,26 @@ func (ds *DockerSource) Parse(ociRef meta.OCIImageRef) (*api.OCIImageSource, err } ds.imageID = res.ID + + // By default parse the OCI content ID from the Docker image ID + contentRef := res.ID + if len(res.RepoDigests) > 0 { + // If the image has Repo digests, use the first one of them to parse + // the fully qualified OCI image name and digest. All of the digests + // point to the same contents, so it doesn't matter which one we use + // here. It will be translated to the right content by the runtime. + contentRef = res.RepoDigests[0] + } + + // Parse the OCI content ID based on the available reference + ci, err := meta.ParseOCIContentID(contentRef) + if err != nil { + return nil, err + } + return &api.OCIImageSource{ - ID: res.ID, - RepoDigests: res.RepoDigests, - Size: meta.NewSizeFromBytes(uint64(res.Size)), + ID: ci, + Size: meta.NewSizeFromBytes(uint64(res.Size)), }, nil } From f551053879f90cef47ab9a25de8a2ca7e7835109 Mon Sep 17 00:00:00 2001 From: Dennis Marttinen Date: Fri, 9 Aug 2019 16:26:23 +0300 Subject: [PATCH 2/5] Add two-way conversions for v1alpha1.OCIImageSource for OCIContentID --- pkg/apis/ignite/v1alpha1/conversion.go | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pkg/apis/ignite/v1alpha1/conversion.go b/pkg/apis/ignite/v1alpha1/conversion.go index bb9e02cac..01f67bff7 100644 --- a/pkg/apis/ignite/v1alpha1/conversion.go +++ b/pkg/apis/ignite/v1alpha1/conversion.go @@ -2,6 +2,7 @@ package v1alpha1 import ( "github.com/weaveworks/ignite/pkg/apis/ignite" + meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1" "k8s.io/apimachinery/pkg/conversion" ) @@ -44,3 +45,42 @@ func Convert_v1alpha1_VMStatus_To_ignite_VMStatus(in *VMStatus, out *ignite.VMSt return nil } + +// Convert_ignite_OCIImageSource_To_v1alpha1_OCIImageSource calls the autogenerated conversion function along with custom conversion logic +func Convert_ignite_OCIImageSource_To_v1alpha1_OCIImageSource(in *ignite.OCIImageSource, out *OCIImageSource, s conversion.Scope) error { + if err := autoConvert_ignite_OCIImageSource_To_v1alpha1_OCIImageSource(in, out, s); err != nil { + return err + } + + // If the OCI content ID is local, i.e. not available from a repository, + // populate the ID field of v1alpha1.OCIImageSource. Otherwise add the + // the repo digest of the ID as the only digest for v1alpha1. + if in.ID.Local() { + out.ID = in.ID.Digest() + } else { + out.RepoDigests = []string{in.ID.RepoDigest()} + } + + return nil +} + +// Convert_v1alpha1_OCIImageSource_To_ignite_OCIImageSource calls the autogenerated conversion function along with custom conversion logic +func Convert_v1alpha1_OCIImageSource_To_ignite_OCIImageSource(in *OCIImageSource, out *ignite.OCIImageSource, s conversion.Scope) (err error) { + if err = autoConvert_v1alpha1_OCIImageSource_To_ignite_OCIImageSource(in, out, s); err != nil { + return err + } + + // By default parse the OCI content ID from the Docker image ID + contentRef := in.ID + if len(in.RepoDigests) > 0 { + // If the image has Repo digests, use the first one of them to parse + // the fully qualified OCI image name and digest. All of the digests + // point to the same contents, so it doesn't matter which one we use + // here. It will be translated to the right content by the runtime. + contentRef = in.RepoDigests[0] + } + + // Parse the OCI content ID based on the available reference + out.ID, err = meta.ParseOCIContentID(contentRef) + return +} From 21f3373476be824f32f757947a1abaa05e383e58 Mon Sep 17 00:00:00 2001 From: Dennis Marttinen Date: Fri, 9 Aug 2019 16:28:27 +0300 Subject: [PATCH 3/5] make autogen tidy --- docs/api/ignite_v1alpha1.md | 35 +++++++- docs/api/ignite_v1alpha2.md | 60 ++++++------- docs/api/meta_v1alpha1.md | 88 ++++++++++++++++--- go.mod | 3 +- go.sum | 6 ++ .../v1alpha1/zz_generated.conversion.go | 27 +++--- .../v1alpha2/zz_generated.conversion.go | 6 +- .../ignite/v1alpha2/zz_generated.deepcopy.go | 10 +-- pkg/apis/ignite/zz_generated.deepcopy.go | 10 +-- .../meta/v1alpha1/zz_generated.deepcopy.go | 16 ++++ pkg/openapi/openapi_generated.go | 48 ++++++---- pkg/openapi/violations.txt | 3 +- vendor/github.com/google/gofuzz/go.mod | 3 + vendor/github.com/json-iterator/go/adapter.go | 2 +- vendor/github.com/json-iterator/go/go.mod | 11 +++ vendor/github.com/json-iterator/go/go.sum | 14 +++ .../github.com/json-iterator/go/iter_skip.go | 25 +++--- .../json-iterator/go/reflect_native.go | 14 +-- .../go/reflect_struct_decoder.go | 2 +- .../json-iterator/go/stream_float.go | 17 ++++ vendor/modules.txt | 4 +- 21 files changed, 284 insertions(+), 120 deletions(-) create mode 100644 vendor/github.com/google/gofuzz/go.mod create mode 100644 vendor/github.com/json-iterator/go/go.mod create mode 100644 vendor/github.com/json-iterator/go/go.sum diff --git a/docs/api/ignite_v1alpha1.md b/docs/api/ignite_v1alpha1.md index d21c4750a..0500a41cc 100644 --- a/docs/api/ignite_v1alpha1.md +++ b/docs/api/ignite_v1alpha1.md @@ -15,12 +15,21 @@ - [Constants](#pkg-constants) - [Variables](#pkg-variables) + - [func + Convert\_ignite\_OCIImageSource\_To\_v1alpha1\_OCIImageSource(in + *ignite.OCIImageSource, out *OCIImageSource, s conversion.Scope) + error](#Convert_ignite_OCIImageSource_To_v1alpha1_OCIImageSource) - [func Convert\_ignite\_VMSpec\_To\_v1alpha1\_VMSpec(in *ignite.VMSpec, out *VMSpec, s conversion.Scope) error](#Convert_ignite_VMSpec_To_v1alpha1_VMSpec) - [func Convert\_ignite\_VMStatus\_To\_v1alpha1\_VMStatus(in *ignite.VMStatus, out *VMStatus, s conversion.Scope) error](#Convert_ignite_VMStatus_To_v1alpha1_VMStatus) + - [func + Convert\_v1alpha1\_OCIImageSource\_To\_ignite\_OCIImageSource(in + *OCIImageSource, out *ignite.OCIImageSource, s conversion.Scope) + (err + error)](#Convert_v1alpha1_OCIImageSource_To_ignite_OCIImageSource) - [func Convert\_v1alpha1\_VMSpec\_To\_ignite\_VMSpec(in *VMSpec, out *ignite.VMSpec, s conversion.Scope) error](#Convert_v1alpha1_VMSpec_To_ignite_VMSpec) @@ -115,7 +124,16 @@ var SchemeGroupVersion = schema.GroupVersion{ SchemeGroupVersion is group version used to register these objects -## func [Convert\_ignite\_VMSpec\_To\_v1alpha1\_VMSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha1/conversion.go?s=239:342#L9) +## func [Convert\_ignite\_OCIImageSource\_To\_v1alpha1\_OCIImageSource](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha1/conversion.go?s=2032:2167#L50) + +``` go +func Convert_ignite_OCIImageSource_To_v1alpha1_OCIImageSource(in *ignite.OCIImageSource, out *OCIImageSource, s conversion.Scope) error +``` + +Convert\_ignite\_OCIImageSource\_To\_v1alpha1\_OCIImageSource calls the +autogenerated conversion function along with custom conversion logic + +## func [Convert\_ignite\_VMSpec\_To\_v1alpha1\_VMSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha1/conversion.go?s=299:402#L10) ``` go func Convert_ignite_VMSpec_To_v1alpha1_VMSpec(in *ignite.VMSpec, out *VMSpec, s conversion.Scope) error @@ -124,7 +142,7 @@ func Convert_ignite_VMSpec_To_v1alpha1_VMSpec(in *ignite.VMSpec, out *VMSpec, s Convert\_ignite\_VMSpec\_To\_v1alpha1\_VMSpec calls the autogenerated conversion function along with custom conversion logic -## func [Convert\_ignite\_VMStatus\_To\_v1alpha1\_VMStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha1/conversion.go?s=1038:1149#L21) +## func [Convert\_ignite\_VMStatus\_To\_v1alpha1\_VMStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha1/conversion.go?s=1098:1209#L22) ``` go func Convert_ignite_VMStatus_To_v1alpha1_VMStatus(in *ignite.VMStatus, out *VMStatus, s conversion.Scope) error @@ -133,7 +151,16 @@ func Convert_ignite_VMStatus_To_v1alpha1_VMStatus(in *ignite.VMStatus, out *VMSt Convert\_ignite\_VMStatus\_To\_v1alpha1\_VMStatus calls the autogenerated conversion function along with custom conversion logic -## func [Convert\_v1alpha1\_VMSpec\_To\_ignite\_VMSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha1/conversion.go?s=637:740#L15) +## func [Convert\_v1alpha1\_OCIImageSource\_To\_ignite\_OCIImageSource](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha1/conversion.go?s=2757:2898#L68) + +``` go +func Convert_v1alpha1_OCIImageSource_To_ignite_OCIImageSource(in *OCIImageSource, out *ignite.OCIImageSource, s conversion.Scope) (err error) +``` + +Convert\_v1alpha1\_OCIImageSource\_To\_ignite\_OCIImageSource calls the +autogenerated conversion function along with custom conversion logic + +## func [Convert\_v1alpha1\_VMSpec\_To\_ignite\_VMSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha1/conversion.go?s=697:800#L16) ``` go func Convert_v1alpha1_VMSpec_To_ignite_VMSpec(in *VMSpec, out *ignite.VMSpec, s conversion.Scope) error @@ -142,7 +169,7 @@ func Convert_v1alpha1_VMSpec_To_ignite_VMSpec(in *VMSpec, out *ignite.VMSpec, s Convert\_ignite\_VMSpec\_To\_v1alpha1\_VMSpec calls the autogenerated conversion function along with custom conversion logic -## func [Convert\_v1alpha1\_VMStatus\_To\_ignite\_VMStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha1/conversion.go?s=1522:1633#L37) +## func [Convert\_v1alpha1\_VMStatus\_To\_ignite\_VMStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha1/conversion.go?s=1582:1693#L38) ``` go func Convert_v1alpha1_VMStatus_To_ignite_VMStatus(in *VMStatus, out *ignite.VMStatus, s conversion.Scope) error diff --git a/docs/api/ignite_v1alpha2.md b/docs/api/ignite_v1alpha2.md index cb0e35c0f..99d44cab5 100644 --- a/docs/api/ignite_v1alpha2.md +++ b/docs/api/ignite_v1alpha2.md @@ -135,7 +135,7 @@ func SetDefaults_VMNetworkSpec(obj *VMNetworkSpec) func SetDefaults_VMSpec(obj *VMSpec) ``` -## type [BlockDeviceVolume](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=8095:8155#L218) +## type [BlockDeviceVolume](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=7799:7859#L212) ``` go type BlockDeviceVolume struct { @@ -145,7 +145,7 @@ type BlockDeviceVolume struct { BlockDeviceVolume defines a block device on the host -## type [FileMapping](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=8390:8485#L229) +## type [FileMapping](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=8094:8189#L223) ``` go type FileMapping struct { @@ -199,7 +199,7 @@ type ImageSpec struct { ImageSpec declares what the image contains -## type [ImageStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=2320:2469#L68) +## type [ImageStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=2024:2173#L62) ``` go type ImageStatus struct { @@ -210,7 +210,7 @@ type ImageStatus struct { ImageStatus defines the status of the image -## type [Kernel](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=4848:5315#L132) +## type [Kernel](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=4552:5019#L126) ``` go type Kernel struct { @@ -230,7 +230,7 @@ kernels This file is stored in /var/lib/firecracker/kernels/{oci-image-digest}/metadata.json +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -## type [KernelSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=5368:5541#L144) +## type [KernelSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=5072:5245#L138) ``` go type KernelSpec struct { @@ -240,7 +240,7 @@ type KernelSpec struct { KernelSpec describes the properties of a kernel -## type [KernelStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=5592:5708#L151) +## type [KernelStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=5296:5412#L145) ``` go type KernelStatus struct { @@ -251,7 +251,7 @@ type KernelStatus struct { KernelStatus describes the status of a kernel -## type [NetworkMode](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=8839:8862#L244) +## type [NetworkMode](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=8543:8566#L238) ``` go type NetworkMode string @@ -268,7 +268,7 @@ const ( ) ``` -### func (NetworkMode) [String](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=8902:8939#L248) +### func (NetworkMode) [String](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=8606:8643#L242) ``` go func (nm NetworkMode) String() string @@ -290,27 +290,21 @@ type OCIImageClaim struct { OCIImageClaim defines a claim for importing an OCI image -## type [OCIImageSource](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=1743:2271#L54) +## type [OCIImageSource](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=1743:1975#L54) ``` go type OCIImageSource struct { - // ID defines the source's ID (e.g. the Docker image ID) - ID string `json:"id"` + // ID defines the source's content ID (e.g. the canonical OCI path or Docker image ID) + ID *meta.OCIContentID `json:"id"` // Size defines the size of the source in bytes Size meta.Size `json:"size"` - // RepoDigests defines the image name as it was when pulled - // from a repository, and the digest of the image - // The format is $registry/$user/$image@sha256:$digest - // This field is unpopulated if the image used as the source - // has never been pushed to or pulled from a registry - RepoDigests []string `json:"repoDigests,omitempty"` } ``` OCIImageSource specifies how the OCI image was imported. It is the status variant of OCIImageClaim -## type [Pool](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=2744:2924#L77) +## type [Pool](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=2448:2628#L71) ``` go type Pool struct { @@ -326,7 +320,7 @@ snapshotter part of Ignite, and the file (existing as a singleton) is present at /var/lib/firecracker/snapshotter/pool.json +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -## type [PoolDevice](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=4215:4605#L119) +## type [PoolDevice](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=3919:4309#L113) ``` go type PoolDevice struct { @@ -342,7 +336,7 @@ type PoolDevice struct { PoolDevice defines one device in the pool -## type [PoolDeviceType](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=3944:3970#L109) +## type [PoolDeviceType](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=3648:3674#L103) ``` go type PoolDeviceType string @@ -357,7 +351,7 @@ const ( ) ``` -## type [PoolSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=2971:3684#L87) +## type [PoolSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=2675:3388#L81) ``` go type PoolSpec struct { @@ -378,7 +372,7 @@ type PoolSpec struct { PoolSpec defines the Pool’s specification -## type [PoolStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=3734:3942#L103) +## type [PoolStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=3438:3646#L97) ``` go type PoolStatus struct { @@ -390,7 +384,7 @@ type PoolStatus struct { PoolStatus defines the Pool’s current status -## type [Runtime](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=9335:9381#L261) +## type [Runtime](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=9039:9085#L255) ``` go type Runtime struct { @@ -400,7 +394,7 @@ type Runtime struct { Runtime specifies the VM’s runtime information -## type [SSH](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=8705:8782#L238) +## type [SSH](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=8409:8486#L232) ``` go type SSH struct { @@ -425,7 +419,7 @@ func (s *SSH) MarshalJSON() ([]byte, error) func (s *SSH) UnmarshalJSON(b []byte) error ``` -## type [VM](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=5910:6365#L159) +## type [VM](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=5614:6069#L153) ``` go type VM struct { @@ -444,7 +438,7 @@ VM represents a virtual machine run by Firecracker These files are stored in /var/lib/firecracker/vm/{vm-id}/metadata.json +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -## type [VMImageSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=7348:7417#L191) +## type [VMImageSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=7052:7121#L185) ``` go type VMImageSpec struct { @@ -452,7 +446,7 @@ type VMImageSpec struct { } ``` -## type [VMKernelSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=7419:7540#L195) +## type [VMKernelSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=7123:7244#L189) ``` go type VMKernelSpec struct { @@ -461,7 +455,7 @@ type VMKernelSpec struct { } ``` -## type [VMNetworkSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=7542:7660#L200) +## type [VMNetworkSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=7246:7364#L194) ``` go type VMNetworkSpec struct { @@ -470,7 +464,7 @@ type VMNetworkSpec struct { } ``` -## type [VMSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=6413:7346#L171) +## type [VMSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=6117:7050#L165) ``` go type VMSpec struct { @@ -496,7 +490,7 @@ type VMSpec struct { VMSpec describes the configuration of a VM -## type [VMStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=9422:9761#L266) +## type [VMStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=9126:9465#L260) ``` go type VMStatus struct { @@ -511,7 +505,7 @@ type VMStatus struct { VMStatus defines the status of a VM -## type [VMStorageSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=7721:7865#L206) +## type [VMStorageSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=7425:7569#L200) ``` go type VMStorageSpec struct { @@ -522,7 +516,7 @@ type VMStorageSpec struct { VMStorageSpec defines the VM’s Volumes and VolumeMounts -## type [Volume](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=7906:8037#L212) +## type [Volume](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=7610:7741#L206) ``` go type Volume struct { @@ -533,7 +527,7 @@ type Volume struct { Volume defines named storage volume -## type [VolumeMount](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=8227:8323#L223) +## type [VolumeMount](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=7931:8027#L217) ``` go type VolumeMount struct { diff --git a/docs/api/meta_v1alpha1.md b/docs/api/meta_v1alpha1.md index 2f021acaa..7f9957c39 100644 --- a/docs/api/meta_v1alpha1.md +++ b/docs/api/meta_v1alpha1.md @@ -28,12 +28,22 @@ - [func (k Kind) Lower() string](#Kind.Lower) - [func (k Kind) String() string](#Kind.String) - [func (k Kind) Title() string](#Kind.Title) + - [type OCIContentID](#OCIContentID) + - [func ParseOCIContentID(str string) (\*OCIContentID, + error)](#ParseOCIContentID) + - [func (o \*OCIContentID) Digest() string](#OCIContentID.Digest) + - [func (o \*OCIContentID) Local() bool](#OCIContentID.Local) + - [func (o \*OCIContentID) MarshalJSON() (\[\]byte, + error)](#OCIContentID.MarshalJSON) + - [func (o \*OCIContentID) RepoDigest() (s + string)](#OCIContentID.RepoDigest) + - [func (o \*OCIContentID) String() string](#OCIContentID.String) + - [func (o \*OCIContentID) UnmarshalJSON(b \[\]byte) (err + error)](#OCIContentID.UnmarshalJSON) - [type OCIImageRef](#OCIImageRef) - [func NewOCIImageRef(imageStr string) (OCIImageRef, error)](#NewOCIImageRef) - [func (i OCIImageRef) IsUnset() bool](#OCIImageRef.IsUnset) - - [func (i OCIImageRef) MarshalJSON() (\[\]byte, - error)](#OCIImageRef.MarshalJSON) - [func (i OCIImageRef) String() string](#OCIImageRef.String) - [func (i \*OCIImageRef) UnmarshalJSON(b \[\]byte) error](#OCIImageRef.UnmarshalJSON) @@ -240,13 +250,71 @@ func (k Kind) Title() string Returns a title case string representation of the Kind -## type [OCIImageRef](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=562:585#L23) +## type [OCIContentID](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=1396:1637#L72) + +``` go +type OCIContentID struct { + // contains filtered or unexported fields +} +``` + +### func [ParseOCIContentID](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=967:1024#L49) + +``` go +func ParseOCIContentID(str string) (*OCIContentID, error) +``` + +### func (\*OCIContentID) [Digest](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=2344:2382#L104) + +``` go +func (o *OCIContentID) Digest() string +``` + +Digest is a getter for the digest field + +### func (\*OCIContentID) [Local](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=2231:2266#L99) + +``` go +func (o *OCIContentID) Local() bool +``` + +Local returns true if the image has no repoName, i.e. it’s not available +from a registry + +### func (\*OCIContentID) [MarshalJSON](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=2616:2668#L117) + +``` go +func (o *OCIContentID) MarshalJSON() ([]byte, error) +``` + +### func (\*OCIContentID) [RepoDigest](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=2486:2532#L109) + +``` go +func (o *OCIContentID) RepoDigest() (s string) +``` + +RepoDigest returns a repo digest based on the OCIContentID if it is not +local + +### func (\*OCIContentID) [String](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=1720:1758#L80) + +``` go +func (o *OCIContentID) String() string +``` + +### func (\*OCIContentID) [UnmarshalJSON](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=2707:2765#L121) + +``` go +func (o *OCIContentID) UnmarshalJSON(b []byte) (err error) +``` + +## type [OCIImageRef](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=586:609#L25) ``` go type OCIImageRef string ``` -### func [NewOCIImageRef](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=181:238#L11) +### func [NewOCIImageRef](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=231:288#L13) ``` go func NewOCIImageRef(imageStr string) (OCIImageRef, error) @@ -255,25 +323,19 @@ func NewOCIImageRef(imageStr string) (OCIImageRef, error) NewOCIImageRef parses and normalizes a reference to an OCI (docker) image. -### func (OCIImageRef) [IsUnset](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=685:720#L31) +### func (OCIImageRef) [IsUnset](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=709:744#L33) ``` go func (i OCIImageRef) IsUnset() bool ``` -### func (OCIImageRef) [MarshalJSON](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=746:796#L35) - -``` go -func (i OCIImageRef) MarshalJSON() ([]byte, error) -``` - -### func (OCIImageRef) [String](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=625:661#L27) +### func (OCIImageRef) [String](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=649:685#L29) ``` go func (i OCIImageRef) String() string ``` -### func (\*OCIImageRef) [UnmarshalJSON](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=834:885#L39) +### func (\*OCIImageRef) [UnmarshalJSON](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=770:821#L37) ``` go func (i *OCIImageRef) UnmarshalJSON(b []byte) error diff --git a/go.mod b/go.mod index 1a7d47b57..e65ed73d4 100644 --- a/go.mod +++ b/go.mod @@ -19,11 +19,12 @@ require ( github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d // indirect github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e github.com/gorilla/mux v1.7.2 // indirect + github.com/json-iterator/go v1.1.7 // indirect github.com/krolaw/dhcp4 v0.0.0-20190531080455-7b64900047ae github.com/lithammer/dedent v1.1.0 github.com/miekg/dns v1.1.14 github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c // indirect - github.com/opencontainers/go-digest v1.0.0-rc1 // indirect + github.com/opencontainers/go-digest v1.0.0-rc1 github.com/opencontainers/image-spec v1.0.1 // indirect github.com/otiai10/copy v1.0.1 github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776 // indirect diff --git a/go.sum b/go.sum index b2525b635..1aa61beb8 100644 --- a/go.sum +++ b/go.sum @@ -125,6 +125,8 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= +github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gnostic v0.0.0-20170426233943-68f4ded48ba9/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= @@ -144,6 +146,8 @@ github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBv github.com/json-iterator/go v0.0.0-20180701071628-ab8a2e0c74be/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo= +github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -174,9 +178,11 @@ github.com/miekg/dns v1.1.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3N github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8dQu6DMTwH4oIuGN8GJDAlqDdVE= diff --git a/pkg/apis/ignite/v1alpha1/zz_generated.conversion.go b/pkg/apis/ignite/v1alpha1/zz_generated.conversion.go index 7fb3f107e..f1123d1f8 100644 --- a/pkg/apis/ignite/v1alpha1/zz_generated.conversion.go +++ b/pkg/apis/ignite/v1alpha1/zz_generated.conversion.go @@ -220,6 +220,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*ignite.OCIImageSource)(nil), (*OCIImageSource)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_ignite_OCIImageSource_To_v1alpha1_OCIImageSource(a.(*ignite.OCIImageSource), b.(*OCIImageSource), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*ignite.VMSpec)(nil), (*VMSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_ignite_VMSpec_To_v1alpha1_VMSpec(a.(*ignite.VMSpec), b.(*VMSpec), scope) }); err != nil { @@ -230,6 +235,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*OCIImageSource)(nil), (*ignite.OCIImageSource)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_OCIImageSource_To_ignite_OCIImageSource(a.(*OCIImageSource), b.(*ignite.OCIImageSource), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*VMSpec)(nil), (*ignite.VMSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha1_VMSpec_To_ignite_VMSpec(a.(*VMSpec), b.(*ignite.VMSpec), scope) }); err != nil { @@ -454,29 +464,18 @@ func Convert_ignite_OCIImageClaim_To_v1alpha1_OCIImageClaim(in *ignite.OCIImageC } func autoConvert_v1alpha1_OCIImageSource_To_ignite_OCIImageSource(in *OCIImageSource, out *ignite.OCIImageSource, s conversion.Scope) error { - out.ID = in.ID + // WARNING: in.ID requires manual conversion: inconvertible types (string vs *github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1.OCIContentID) out.Size = in.Size - out.RepoDigests = *(*[]string)(unsafe.Pointer(&in.RepoDigests)) + // WARNING: in.RepoDigests requires manual conversion: does not exist in peer-type return nil } -// Convert_v1alpha1_OCIImageSource_To_ignite_OCIImageSource is an autogenerated conversion function. -func Convert_v1alpha1_OCIImageSource_To_ignite_OCIImageSource(in *OCIImageSource, out *ignite.OCIImageSource, s conversion.Scope) error { - return autoConvert_v1alpha1_OCIImageSource_To_ignite_OCIImageSource(in, out, s) -} - func autoConvert_ignite_OCIImageSource_To_v1alpha1_OCIImageSource(in *ignite.OCIImageSource, out *OCIImageSource, s conversion.Scope) error { - out.ID = in.ID + // WARNING: in.ID requires manual conversion: inconvertible types (*github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1.OCIContentID vs string) out.Size = in.Size - out.RepoDigests = *(*[]string)(unsafe.Pointer(&in.RepoDigests)) return nil } -// Convert_ignite_OCIImageSource_To_v1alpha1_OCIImageSource is an autogenerated conversion function. -func Convert_ignite_OCIImageSource_To_v1alpha1_OCIImageSource(in *ignite.OCIImageSource, out *OCIImageSource, s conversion.Scope) error { - return autoConvert_ignite_OCIImageSource_To_v1alpha1_OCIImageSource(in, out, s) -} - func autoConvert_v1alpha1_Pool_To_ignite_Pool(in *Pool, out *ignite.Pool, s conversion.Scope) error { out.TypeMeta = in.TypeMeta if err := Convert_v1alpha1_PoolSpec_To_ignite_PoolSpec(&in.Spec, &out.Spec, s); err != nil { diff --git a/pkg/apis/ignite/v1alpha2/zz_generated.conversion.go b/pkg/apis/ignite/v1alpha2/zz_generated.conversion.go index 9208be57e..6ccf1f405 100644 --- a/pkg/apis/ignite/v1alpha2/zz_generated.conversion.go +++ b/pkg/apis/ignite/v1alpha2/zz_generated.conversion.go @@ -504,9 +504,8 @@ func Convert_ignite_OCIImageClaim_To_v1alpha2_OCIImageClaim(in *ignite.OCIImageC } func autoConvert_v1alpha2_OCIImageSource_To_ignite_OCIImageSource(in *OCIImageSource, out *ignite.OCIImageSource, s conversion.Scope) error { - out.ID = in.ID + out.ID = (*v1alpha1.OCIContentID)(unsafe.Pointer(in.ID)) out.Size = in.Size - out.RepoDigests = *(*[]string)(unsafe.Pointer(&in.RepoDigests)) return nil } @@ -516,9 +515,8 @@ func Convert_v1alpha2_OCIImageSource_To_ignite_OCIImageSource(in *OCIImageSource } func autoConvert_ignite_OCIImageSource_To_v1alpha2_OCIImageSource(in *ignite.OCIImageSource, out *OCIImageSource, s conversion.Scope) error { - out.ID = in.ID + out.ID = (*v1alpha1.OCIContentID)(unsafe.Pointer(in.ID)) out.Size = in.Size - out.RepoDigests = *(*[]string)(unsafe.Pointer(&in.RepoDigests)) return nil } diff --git a/pkg/apis/ignite/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/ignite/v1alpha2/zz_generated.deepcopy.go index ba143a5eb..e309a3e11 100644 --- a/pkg/apis/ignite/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/ignite/v1alpha2/zz_generated.deepcopy.go @@ -186,12 +186,12 @@ func (in *OCIImageClaim) DeepCopy() *OCIImageClaim { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *OCIImageSource) DeepCopyInto(out *OCIImageSource) { *out = *in - out.Size = in.Size - if in.RepoDigests != nil { - in, out := &in.RepoDigests, &out.RepoDigests - *out = make([]string, len(*in)) - copy(*out, *in) + if in.ID != nil { + in, out := &in.ID, &out.ID + *out = new(v1alpha1.OCIContentID) + **out = **in } + out.Size = in.Size return } diff --git a/pkg/apis/ignite/zz_generated.deepcopy.go b/pkg/apis/ignite/zz_generated.deepcopy.go index e332d1204..bc2f2edfb 100644 --- a/pkg/apis/ignite/zz_generated.deepcopy.go +++ b/pkg/apis/ignite/zz_generated.deepcopy.go @@ -186,12 +186,12 @@ func (in *OCIImageClaim) DeepCopy() *OCIImageClaim { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *OCIImageSource) DeepCopyInto(out *OCIImageSource) { *out = *in - out.Size = in.Size - if in.RepoDigests != nil { - in, out := &in.RepoDigests, &out.RepoDigests - *out = make([]string, len(*in)) - copy(*out, *in) + if in.ID != nil { + in, out := &in.ID, &out.ID + *out = new(v1alpha1.OCIContentID) + **out = **in } + out.Size = in.Size return } diff --git a/pkg/apis/meta/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/meta/v1alpha1/zz_generated.deepcopy.go index e17ed7317..4f831ebde 100644 --- a/pkg/apis/meta/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/meta/v1alpha1/zz_generated.deepcopy.go @@ -112,6 +112,22 @@ func (in IPAddresses) DeepCopy() IPAddresses { return *out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OCIContentID) DeepCopyInto(out *OCIContentID) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OCIContentID. +func (in *OCIContentID) DeepCopy() *OCIContentID { + if in == nil { + return nil + } + out := new(OCIContentID) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ObjectMeta) DeepCopyInto(out *ObjectMeta) { *out = *in diff --git a/pkg/openapi/openapi_generated.go b/pkg/openapi/openapi_generated.go index 0dbf86a1c..a83f6e38a 100644 --- a/pkg/openapi/openapi_generated.go +++ b/pkg/openapi/openapi_generated.go @@ -60,6 +60,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/weaveworks/ignite/pkg/apis/ignite/v1alpha2.VolumeMount": schema_pkg_apis_ignite_v1alpha2_VolumeMount(ref), "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1.APIType": schema_pkg_apis_meta_v1alpha1_APIType(ref), "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1.DMID": schema_pkg_apis_meta_v1alpha1_DMID(ref), + "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1.OCIContentID": schema_pkg_apis_meta_v1alpha1_OCIContentID(ref), "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1.ObjectMeta": schema_pkg_apis_meta_v1alpha1_ObjectMeta(ref), "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1.PortMapping": schema_pkg_apis_meta_v1alpha1_PortMapping(ref), "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1.Size": schema_pkg_apis_meta_v1alpha1_Size(ref), @@ -964,9 +965,8 @@ func schema_pkg_apis_ignite_v1alpha2_OCIImageSource(ref common.ReferenceCallback Properties: map[string]spec.Schema{ "id": { SchemaProps: spec.SchemaProps{ - Description: "ID defines the source's ID (e.g. the Docker image ID)", - Type: []string{"string"}, - Format: "", + Description: "ID defines the source's content ID (e.g. the canonical OCI path or Docker image ID)", + Ref: ref("github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1.OCIContentID"), }, }, "size": { @@ -975,26 +975,12 @@ func schema_pkg_apis_ignite_v1alpha2_OCIImageSource(ref common.ReferenceCallback Ref: ref("github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1.Size"), }, }, - "repoDigests": { - SchemaProps: spec.SchemaProps{ - Description: "RepoDigests defines the image name as it was when pulled from a repository, and the digest of the image The format is $registry/$user/$image@sha256:$digest This field is unpopulated if the image used as the source has never been pushed to or pulled from a registry", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, }, Required: []string{"id", "size"}, }, }, Dependencies: []string{ - "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1.Size"}, + "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1.OCIContentID", "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1.Size"}, } } @@ -1552,6 +1538,32 @@ func schema_pkg_apis_meta_v1alpha1_DMID(ref common.ReferenceCallback) common.Ope } } +func schema_pkg_apis_meta_v1alpha1_OCIContentID(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "repoName": { + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + "digest": { + SchemaProps: spec.SchemaProps{ + Description: "Fully qualified image name, e.g. \"docker.io/library/node\" or blank if the image is local", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"repoName", "digest"}, + }, + }, + } +} + func schema_pkg_apis_meta_v1alpha1_ObjectMeta(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/pkg/openapi/violations.txt b/pkg/openapi/violations.txt index 6f9b171d4..3ba10b204 100644 --- a/pkg/openapi/violations.txt +++ b/pkg/openapi/violations.txt @@ -1,7 +1,6 @@ API rule violation: list_type_missing,github.com/weaveworks/ignite/pkg/apis/ignite/v1alpha1,OCIImageSource,RepoDigests API rule violation: list_type_missing,github.com/weaveworks/ignite/pkg/apis/ignite/v1alpha1,PoolStatus,Devices API rule violation: list_type_missing,github.com/weaveworks/ignite/pkg/apis/ignite/v1alpha1,VMSpec,CopyFiles -API rule violation: list_type_missing,github.com/weaveworks/ignite/pkg/apis/ignite/v1alpha2,OCIImageSource,RepoDigests API rule violation: list_type_missing,github.com/weaveworks/ignite/pkg/apis/ignite/v1alpha2,PoolStatus,Devices API rule violation: list_type_missing,github.com/weaveworks/ignite/pkg/apis/ignite/v1alpha2,VMSpec,CopyFiles API rule violation: list_type_missing,github.com/weaveworks/ignite/pkg/apis/ignite/v1alpha2,VMStorageSpec,VolumeMounts @@ -9,6 +8,8 @@ API rule violation: list_type_missing,github.com/weaveworks/ignite/pkg/apis/igni API rule violation: names_match,github.com/weaveworks/ignite/pkg/apis/ignite/v1alpha1,VMSpec,CPUs API rule violation: names_match,github.com/weaveworks/ignite/pkg/apis/ignite/v1alpha2,VMSpec,CPUs API rule violation: names_match,github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1,DMID,index +API rule violation: names_match,github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1,OCIContentID,digest +API rule violation: names_match,github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1,OCIContentID,repoName API rule violation: names_match,github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1,Size,ByteSize API rule violation: names_match,github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1,Time,Time API rule violation: names_match,github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1,TypeMeta,TypeMeta diff --git a/vendor/github.com/google/gofuzz/go.mod b/vendor/github.com/google/gofuzz/go.mod new file mode 100644 index 000000000..8ec4fe9e9 --- /dev/null +++ b/vendor/github.com/google/gofuzz/go.mod @@ -0,0 +1,3 @@ +module github.com/google/gofuzz + +go 1.12 diff --git a/vendor/github.com/json-iterator/go/adapter.go b/vendor/github.com/json-iterator/go/adapter.go index e674d0f39..92d2cc4a3 100644 --- a/vendor/github.com/json-iterator/go/adapter.go +++ b/vendor/github.com/json-iterator/go/adapter.go @@ -16,7 +16,7 @@ func Unmarshal(data []byte, v interface{}) error { return ConfigDefault.Unmarshal(data, v) } -// UnmarshalFromString convenient method to read from string instead of []byte +// UnmarshalFromString is a convenient method to read from string instead of []byte func UnmarshalFromString(str string, v interface{}) error { return ConfigDefault.UnmarshalFromString(str, v) } diff --git a/vendor/github.com/json-iterator/go/go.mod b/vendor/github.com/json-iterator/go/go.mod new file mode 100644 index 000000000..e05c42ff5 --- /dev/null +++ b/vendor/github.com/json-iterator/go/go.mod @@ -0,0 +1,11 @@ +module github.com/json-iterator/go + +go 1.12 + +require ( + github.com/davecgh/go-spew v1.1.1 + github.com/google/gofuzz v1.0.0 + github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 + github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 + github.com/stretchr/testify v1.3.0 +) diff --git a/vendor/github.com/json-iterator/go/go.sum b/vendor/github.com/json-iterator/go/go.sum new file mode 100644 index 000000000..d778b5a14 --- /dev/null +++ b/vendor/github.com/json-iterator/go/go.sum @@ -0,0 +1,14 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/vendor/github.com/json-iterator/go/iter_skip.go b/vendor/github.com/json-iterator/go/iter_skip.go index f58beb913..e91eefb15 100644 --- a/vendor/github.com/json-iterator/go/iter_skip.go +++ b/vendor/github.com/json-iterator/go/iter_skip.go @@ -37,17 +37,24 @@ func (iter *Iterator) SkipAndReturnBytes() []byte { return iter.stopCapture() } -type captureBuffer struct { - startedAt int - captured []byte +// SkipAndAppendBytes skips next JSON element and appends its content to +// buffer, returning the result. +func (iter *Iterator) SkipAndAppendBytes(buf []byte) []byte { + iter.startCaptureTo(buf, iter.head) + iter.Skip() + return iter.stopCapture() } -func (iter *Iterator) startCapture(captureStartedAt int) { +func (iter *Iterator) startCaptureTo(buf []byte, captureStartedAt int) { if iter.captured != nil { panic("already in capture mode") } iter.captureStartedAt = captureStartedAt - iter.captured = make([]byte, 0, 32) + iter.captured = buf +} + +func (iter *Iterator) startCapture(captureStartedAt int) { + iter.startCaptureTo(make([]byte, 0, 32), captureStartedAt) } func (iter *Iterator) stopCapture() []byte { @@ -58,13 +65,7 @@ func (iter *Iterator) stopCapture() []byte { remaining := iter.buf[iter.captureStartedAt:iter.head] iter.captureStartedAt = -1 iter.captured = nil - if len(captured) == 0 { - copied := make([]byte, len(remaining)) - copy(copied, remaining) - return copied - } - captured = append(captured, remaining...) - return captured + return append(captured, remaining...) } // Skip skips a json object and positions to relatively the next json object diff --git a/vendor/github.com/json-iterator/go/reflect_native.go b/vendor/github.com/json-iterator/go/reflect_native.go index 9042eb0cb..f88722d14 100644 --- a/vendor/github.com/json-iterator/go/reflect_native.go +++ b/vendor/github.com/json-iterator/go/reflect_native.go @@ -432,17 +432,19 @@ func (codec *base64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { } func (codec *base64Codec) Encode(ptr unsafe.Pointer, stream *Stream) { - src := *((*[]byte)(ptr)) - if len(src) == 0 { + if codec.sliceType.UnsafeIsNil(ptr) { stream.WriteNil() return } + src := *((*[]byte)(ptr)) encoding := base64.StdEncoding stream.writeByte('"') - size := encoding.EncodedLen(len(src)) - buf := make([]byte, size) - encoding.Encode(buf, src) - stream.buf = append(stream.buf, buf...) + if len(src) != 0 { + size := encoding.EncodedLen(len(src)) + buf := make([]byte, size) + encoding.Encode(buf, src) + stream.buf = append(stream.buf, buf...) + } stream.writeByte('"') } diff --git a/vendor/github.com/json-iterator/go/reflect_struct_decoder.go b/vendor/github.com/json-iterator/go/reflect_struct_decoder.go index 355d2d116..932641ac4 100644 --- a/vendor/github.com/json-iterator/go/reflect_struct_decoder.go +++ b/vendor/github.com/json-iterator/go/reflect_struct_decoder.go @@ -530,8 +530,8 @@ func (decoder *generalStructDecoder) decodeOneField(ptr unsafe.Pointer, iter *It } } if fieldDecoder == nil { - msg := "found unknown field: " + field if decoder.disallowUnknownFields { + msg := "found unknown field: " + field iter.ReportError("ReadObject", msg) } c := iter.nextToken() diff --git a/vendor/github.com/json-iterator/go/stream_float.go b/vendor/github.com/json-iterator/go/stream_float.go index f318d2c59..826aa594a 100644 --- a/vendor/github.com/json-iterator/go/stream_float.go +++ b/vendor/github.com/json-iterator/go/stream_float.go @@ -1,6 +1,7 @@ package jsoniter import ( + "fmt" "math" "strconv" ) @@ -13,6 +14,10 @@ func init() { // WriteFloat32 write float32 to stream func (stream *Stream) WriteFloat32(val float32) { + if math.IsInf(float64(val), 0) || math.IsNaN(float64(val)) { + stream.Error = fmt.Errorf("unsupported value: %f", val) + return + } abs := math.Abs(float64(val)) fmt := byte('f') // Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right. @@ -26,6 +31,10 @@ func (stream *Stream) WriteFloat32(val float32) { // WriteFloat32Lossy write float32 to stream with ONLY 6 digits precision although much much faster func (stream *Stream) WriteFloat32Lossy(val float32) { + if math.IsInf(float64(val), 0) || math.IsNaN(float64(val)) { + stream.Error = fmt.Errorf("unsupported value: %f", val) + return + } if val < 0 { stream.writeByte('-') val = -val @@ -54,6 +63,10 @@ func (stream *Stream) WriteFloat32Lossy(val float32) { // WriteFloat64 write float64 to stream func (stream *Stream) WriteFloat64(val float64) { + if math.IsInf(val, 0) || math.IsNaN(val) { + stream.Error = fmt.Errorf("unsupported value: %f", val) + return + } abs := math.Abs(val) fmt := byte('f') // Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right. @@ -67,6 +80,10 @@ func (stream *Stream) WriteFloat64(val float64) { // WriteFloat64Lossy write float64 to stream with ONLY 6 digits precision although much much faster func (stream *Stream) WriteFloat64Lossy(val float64) { + if math.IsInf(val, 0) || math.IsNaN(val) { + stream.Error = fmt.Errorf("unsupported value: %f", val) + return + } if val < 0 { stream.writeByte('-') val = -val diff --git a/vendor/modules.txt b/vendor/modules.txt index dbd5a56f3..63aafb0a0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -102,7 +102,7 @@ github.com/golang/protobuf/ptypes github.com/golang/protobuf/ptypes/any github.com/golang/protobuf/ptypes/duration github.com/golang/protobuf/ptypes/timestamp -# github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf +# github.com/google/gofuzz v1.0.0 github.com/google/gofuzz # github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d github.com/googleapis/gnostic/OpenAPIv2 @@ -112,7 +112,7 @@ github.com/googleapis/gnostic/extensions github.com/goombaio/namegenerator # github.com/inconshreveable/mousetrap v1.0.0 github.com/inconshreveable/mousetrap -# github.com/json-iterator/go v1.1.6 +# github.com/json-iterator/go v1.1.7 github.com/json-iterator/go # github.com/konsorten/go-windows-terminal-sequences v1.0.1 github.com/konsorten/go-windows-terminal-sequences From d4495d00a5dee6e07be761014f4f87944e1cf929 Mon Sep 17 00:00:00 2001 From: Dennis Marttinen Date: Fri, 9 Aug 2019 17:23:00 +0300 Subject: [PATCH 4/5] Address feedback --- pkg/apis/ignite/v1alpha1/conversion.go | 4 +-- pkg/apis/meta/v1alpha1/image.go | 40 ++++++++++++++++++++------ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/pkg/apis/ignite/v1alpha1/conversion.go b/pkg/apis/ignite/v1alpha1/conversion.go index 01f67bff7..7cccc81bc 100644 --- a/pkg/apis/ignite/v1alpha1/conversion.go +++ b/pkg/apis/ignite/v1alpha1/conversion.go @@ -56,9 +56,9 @@ func Convert_ignite_OCIImageSource_To_v1alpha1_OCIImageSource(in *ignite.OCIImag // populate the ID field of v1alpha1.OCIImageSource. Otherwise add the // the repo digest of the ID as the only digest for v1alpha1. if in.ID.Local() { - out.ID = in.ID.Digest() + out.ID = in.ID.Digest().String() } else { - out.RepoDigests = []string{in.ID.RepoDigest()} + out.RepoDigests = []string{in.ID.RepoDigest().String()} } return nil diff --git a/pkg/apis/meta/v1alpha1/image.go b/pkg/apis/meta/v1alpha1/image.go index a8b45899f..62f1bdb0c 100644 --- a/pkg/apis/meta/v1alpha1/image.go +++ b/pkg/apis/meta/v1alpha1/image.go @@ -4,11 +4,17 @@ import ( "encoding/json" "fmt" "net/url" + "strings" "github.com/containers/image/docker/reference" "github.com/opencontainers/go-digest" ) +const ( + ociSchemeRegistry = "oci://" + ociSchemeLocal = "docker://" +) + // NewOCIImageRef parses and normalizes a reference to an OCI (docker) image. func NewOCIImageRef(imageStr string) (OCIImageRef, error) { named, err := reference.ParseDockerRef(imageStr) @@ -46,6 +52,11 @@ func (i *OCIImageRef) UnmarshalJSON(b []byte) error { return err } +// ParseOCIContentID takes in a string to parse into an *OCIContentID +// If given a local Docker SHA like "sha256:3285f65b2651c68b5316e7a1fbabd30b5ae47914ac5791ac4bb9d59d029b924b", +// it will be parsed into the local format, encoded as "docker://". Given a full repo digest, such as +// "weaveworks/ignite-ubuntu@sha256:3285f65b2651c68b5316e7a1fbabd30b5ae47914ac5791ac4bb9d59d029b924b", it will +// be parsed into the OCI registry format, encoded as "oci://@". func ParseOCIContentID(str string) (*OCIContentID, error) { named, err := reference.ParseDockerRef(str) if err != nil { @@ -78,11 +89,12 @@ var _ json.Marshaler = &OCIContentID{} var _ json.Unmarshaler = &OCIContentID{} func (o *OCIContentID) String() string { - if len(o.repoName) > 0 { - return fmt.Sprintf("oci://%s", o.RepoDigest()) + scheme := ociSchemeRegistry + if o.Local() { + scheme = ociSchemeLocal } - return fmt.Sprintf("docker://%s", o.Digest()) + return scheme + o.ociString() } func parseOCIString(s string) (*OCIContentID, error) { @@ -95,20 +107,32 @@ func parseOCIString(s string) (*OCIContentID, error) { return ParseOCIContentID(u.Host + u.Path) } +// ociString returns the internal string representation for either format +func (o *OCIContentID) ociString() string { + var sb strings.Builder + if !o.Local() { + sb.WriteString(o.repoName + "@") + } + + sb.WriteString(o.digest) + return sb.String() +} + // Local returns true if the image has no repoName, i.e. it's not available from a registry func (o *OCIContentID) Local() bool { return len(o.repoName) == 0 } -// Digest is a getter for the digest field -func (o *OCIContentID) Digest() string { - return o.digest +// Digest gets the digest of the content ID +func (o *OCIContentID) Digest() digest.Digest { + return digest.Digest(o.digest) } // RepoDigest returns a repo digest based on the OCIContentID if it is not local -func (o *OCIContentID) RepoDigest() (s string) { +func (o *OCIContentID) RepoDigest() (n reference.Named) { if !o.Local() { - s = fmt.Sprintf("%s@%s", o.repoName, o.digest) + // Were parsing already validated data, ignore the error + n, _ = reference.ParseDockerRef(o.ociString()) } return From 22ef566fc6be2ea8d2b8cb2f63da7d9ae11653e1 Mon Sep 17 00:00:00 2001 From: Dennis Marttinen Date: Fri, 9 Aug 2019 17:40:36 +0300 Subject: [PATCH 5/5] make autogen tidy --- docs/api/ignite_v1alpha1.md | 2 +- docs/api/meta_v1alpha1.md | 48 ++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/docs/api/ignite_v1alpha1.md b/docs/api/ignite_v1alpha1.md index 0500a41cc..40a808734 100644 --- a/docs/api/ignite_v1alpha1.md +++ b/docs/api/ignite_v1alpha1.md @@ -151,7 +151,7 @@ func Convert_ignite_VMStatus_To_v1alpha1_VMStatus(in *ignite.VMStatus, out *VMSt Convert\_ignite\_VMStatus\_To\_v1alpha1\_VMStatus calls the autogenerated conversion function along with custom conversion logic -## func [Convert\_v1alpha1\_OCIImageSource\_To\_ignite\_OCIImageSource](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha1/conversion.go?s=2757:2898#L68) +## func [Convert\_v1alpha1\_OCIImageSource\_To\_ignite\_OCIImageSource](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha1/conversion.go?s=2775:2916#L68) ``` go func Convert_v1alpha1_OCIImageSource_To_ignite_OCIImageSource(in *OCIImageSource, out *ignite.OCIImageSource, s conversion.Scope) (err error) diff --git a/docs/api/meta_v1alpha1.md b/docs/api/meta_v1alpha1.md index f95a5bf38..f2d5eb190 100644 --- a/docs/api/meta_v1alpha1.md +++ b/docs/api/meta_v1alpha1.md @@ -32,12 +32,13 @@ - [type OCIContentID](#OCIContentID) - [func ParseOCIContentID(str string) (\*OCIContentID, error)](#ParseOCIContentID) - - [func (o \*OCIContentID) Digest() string](#OCIContentID.Digest) + - [func (o \*OCIContentID) Digest() + digest.Digest](#OCIContentID.Digest) - [func (o \*OCIContentID) Local() bool](#OCIContentID.Local) - [func (o \*OCIContentID) MarshalJSON() (\[\]byte, error)](#OCIContentID.MarshalJSON) - - [func (o \*OCIContentID) RepoDigest() (s - string)](#OCIContentID.RepoDigest) + - [func (o \*OCIContentID) RepoDigest() (n + reference.Named)](#OCIContentID.RepoDigest) - [func (o \*OCIContentID) String() string](#OCIContentID.String) - [func (o \*OCIContentID) UnmarshalJSON(b \[\]byte) (err error)](#OCIContentID.UnmarshalJSON) @@ -259,7 +260,7 @@ func (k Kind) Title() string Returns a title case string representation of the Kind -## type [OCIContentID](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=1396:1637#L72) +## type [OCIContentID](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=1961:2202#L83) ``` go type OCIContentID struct { @@ -267,21 +268,30 @@ type OCIContentID struct { } ``` -### func [ParseOCIContentID](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=967:1024#L49) +### func [ParseOCIContentID](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=1532:1589#L60) ``` go func ParseOCIContentID(str string) (*OCIContentID, error) ``` -### func (\*OCIContentID) [Digest](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=2344:2382#L104) +ParseOCIContentID takes in a string to parse into an \*OCIContentID If +given a local Docker SHA like +“sha256:3285f65b2651c68b5316e7a1fbabd30b5ae47914ac5791ac4bb9d59d029b924b”, +it will be parsed into the local format, encoded as “docker://”. +Given a full repo digest, such as +“weaveworks/ignite-ubuntu@sha256:3285f65b2651c68b5316e7a1fbabd30b5ae47914ac5791ac4bb9d59d029b924b”, +it will be parsed into the OCI registry format, encoded as +“oci://@”. + +### func (\*OCIContentID) [Digest](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=3137:3182#L127) ``` go -func (o *OCIContentID) Digest() string +func (o *OCIContentID) Digest() digest.Digest ``` -Digest is a getter for the digest field +Digest gets the digest of the content ID -### func (\*OCIContentID) [Local](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=2231:2266#L99) +### func (\*OCIContentID) [Local](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=3023:3058#L122) ``` go func (o *OCIContentID) Local() bool @@ -290,40 +300,40 @@ func (o *OCIContentID) Local() bool Local returns true if the image has no repoName, i.e. it’s not available from a registry -### func (\*OCIContentID) [MarshalJSON](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=2616:2668#L117) +### func (\*OCIContentID) [MarshalJSON](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=3499:3551#L141) ``` go func (o *OCIContentID) MarshalJSON() ([]byte, error) ``` -### func (\*OCIContentID) [RepoDigest](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=2486:2532#L109) +### func (\*OCIContentID) [RepoDigest](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=3301:3356#L132) ``` go -func (o *OCIContentID) RepoDigest() (s string) +func (o *OCIContentID) RepoDigest() (n reference.Named) ``` RepoDigest returns a repo digest based on the OCIContentID if it is not local -### func (\*OCIContentID) [String](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=1720:1758#L80) +### func (\*OCIContentID) [String](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=2285:2323#L91) ``` go func (o *OCIContentID) String() string ``` -### func (\*OCIContentID) [UnmarshalJSON](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=2707:2765#L121) +### func (\*OCIContentID) [UnmarshalJSON](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=3590:3648#L145) ``` go func (o *OCIContentID) UnmarshalJSON(b []byte) (err error) ``` -## type [OCIImageRef](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=586:609#L25) +## type [OCIImageRef](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=671:694#L31) ``` go type OCIImageRef string ``` -### func [NewOCIImageRef](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=231:288#L13) +### func [NewOCIImageRef](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=316:373#L19) ``` go func NewOCIImageRef(imageStr string) (OCIImageRef, error) @@ -332,19 +342,19 @@ func NewOCIImageRef(imageStr string) (OCIImageRef, error) NewOCIImageRef parses and normalizes a reference to an OCI (docker) image. -### func (OCIImageRef) [IsUnset](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=709:744#L33) +### func (OCIImageRef) [IsUnset](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=794:829#L39) ``` go func (i OCIImageRef) IsUnset() bool ``` -### func (OCIImageRef) [String](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=649:685#L29) +### func (OCIImageRef) [String](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=734:770#L35) ``` go func (i OCIImageRef) String() string ``` -### func (\*OCIImageRef) [UnmarshalJSON](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=770:821#L37) +### func (\*OCIImageRef) [UnmarshalJSON](https://github.com/weaveworks/ignite/tree/master/pkg/apis/meta/v1alpha1/image.go?s=855:906#L43) ``` go func (i *OCIImageRef) UnmarshalJSON(b []byte) error