From f1660754bd0736a665302dc812949b00b6313ca6 Mon Sep 17 00:00:00 2001 From: Ilya Dmitrichenko Date: Fri, 22 Sep 2023 10:06:20 +0100 Subject: [PATCH] oci/client: relax annotation parser This is in order to allow `flux pull artifact` to retrieve any kind of OCI artifact, e.g. a Helm chart for debugging. --- oci/client/meta.go | 35 ++++++++--------------------------- oci/client/pull.go | 5 +---- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/oci/client/meta.go b/oci/client/meta.go index 9a4d287af..592f8234a 100644 --- a/oci/client/meta.go +++ b/oci/client/meta.go @@ -17,17 +17,15 @@ limitations under the License. package client import ( - "fmt" - "github.com/fluxcd/pkg/oci" ) // Metadata holds the upstream information about on artifact's source. // https://github.com/opencontainers/image-spec/blob/main/annotations.md type Metadata struct { - Created string `json:"created"` - Source string `json:"source_url"` - Revision string `json:"source_revision"` + Created string `json:"created,omitempty"` + Source string `json:"source_url,omitempty"` + Revision string `json:"source_revision,omitempty"` Digest string `json:"digest"` URL string `json:"url"` Annotations map[string]string `json:"annotations,omitempty"` @@ -49,28 +47,11 @@ func (m *Metadata) ToAnnotations() map[string]string { } // MetadataFromAnnotations parses the OpenContainers annotations and returns a Metadata object. -func MetadataFromAnnotations(annotations map[string]string) (*Metadata, error) { - created, ok := annotations[oci.CreatedAnnotation] - if !ok { - return nil, fmt.Errorf("'%s' annotation not found", oci.CreatedAnnotation) - } - - source, ok := annotations[oci.SourceAnnotation] - if !ok { - return nil, fmt.Errorf("'%s' annotation not found", oci.SourceAnnotation) - } - - revision, ok := annotations[oci.RevisionAnnotation] - if !ok { - return nil, fmt.Errorf("'%s' annotation not found", oci.RevisionAnnotation) - } - - m := Metadata{ - Created: created, - Source: source, - Revision: revision, +func MetadataFromAnnotations(annotations map[string]string) *Metadata { + return &Metadata{ + Created: annotations[oci.CreatedAnnotation], + Source: annotations[oci.SourceAnnotation], + Revision: annotations[oci.RevisionAnnotation], Annotations: annotations, } - - return &m, nil } diff --git a/oci/client/pull.go b/oci/client/pull.go index cbc5e6de9..4776538c0 100644 --- a/oci/client/pull.go +++ b/oci/client/pull.go @@ -47,10 +47,7 @@ func (c *Client) Pull(ctx context.Context, url, outDir string) (*Metadata, error return nil, fmt.Errorf("parsing manifest failed: %w", err) } - meta, err := MetadataFromAnnotations(manifest.Annotations) - if err != nil { - return nil, err - } + meta := MetadataFromAnnotations(manifest.Annotations) meta.Digest = ref.Context().Digest(digest.String()).String() layers, err := img.Layers()