Sitelet https://web.archive.org/web/20201116230549/https://github.com/operator-framework/api/pull/60
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/metadata: bundle metadata utils and types #60

Open
wants to merge 3 commits into
base: master
from

Conversation

@estroz
Copy link
Member

@estroz estroz commented Aug 12, 2020 •

There should be a canonical set of utilities and types that can find and parse an annotations.yaml in a bundle directory instead of re-implementing that logic in various ways in various operator-framework repos. This repo is a good home for them because it is the source of truth for many OF APIs.

/cc @kevinrizza @dinhxuanvu

/kind feature

… in a directory and its children
@estroz estroz force-pushed the estroz:feature/find-metadata branch from 262762c to 8b174fd Aug 12, 2020
@estroz
Copy link
Member Author

@estroz estroz commented Aug 12, 2020

Relevant to this PR: because we're adding this function to the api lib, can we consider adding the bundle spec itself to this lib, specifically labels and some convenient access methods for them?

// readAnnotations reads annotations from file(s) in bundleRoot and returns them as a map.
func readAnnotations(fs afero.Fs, annotationsPath string) (map[string]string, error) {
// The annotations file is well-defined.
b, err := afero.ReadFile(fs, annotationsPath)

This comment has been minimized.

@kevinrizza

kevinrizza Aug 12, 2020
Member

Why not just use ioutil instead of adding an external dependency?

This comment has been minimized.

@estroz

estroz Aug 12, 2020
Author Member

It's much easier to test with afero since we don't have to write testdata to disk for each new case. Plus there's a Go design draft for a std file system interface, which we could replace this with in the future.


// Use the arbitrarily-indexed representation of the annotations file for forwards and backwards compatibility.
annotations := struct {
Annotations map[string]string `json:"annotations"`

This comment has been minimized.

@kevinrizza

kevinrizza Aug 12, 2020
Member

Why don't we use a more versioned structured type here? Just so that additional arbitrary annotations can be added? It seems like either way we need to validate that it has the set of required annotations to make the bundle work, so maybe that should be included here?

This comment has been minimized.

@estroz

estroz Aug 12, 2020
Author Member

Exactly, so arbitrary annotations can be added. There may be a way to load both versioned and arbitrary annotations into some struct type, which I can experiment with in this PR, but I wasn't sure about doing that initially (see #60 (comment)).

This comment has been minimized.

@estroz

estroz Aug 12, 2020
Author Member

Done

and return the full AnnotationsFile from FindAnnotations()

pkg/manifests: move metadata types to pkg/metadata
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/afero"

This comment has been minimized.

@njhale

njhale Aug 12, 2020
Member

nice find!

@estroz estroz changed the title pkg/metadata: add `annotations.yaml` search utility function `FindAnnotations()` pkg/metadata: bundle metadata utils and types Aug 13, 2020
pkg/metadata/types.go Outdated Show resolved Hide resolved
Copy link
Member

@dinhxuanvu dinhxuanvu left a comment

/lgtm
Just a small nit.

Copy link
Member

@dinhxuanvu dinhxuanvu left a comment

/lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.