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

Graph Loader initial implementation #224

Merged

Conversation

kevinrizza
Copy link
Member

*Create new graph type that can describe channel graphs of packages
*Create initial implementation of loading it from existing sqlite db

This graph implementation should be used as a declarative structure to define the update graph for both input and output in the future

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 24, 2020
Copy link
Member

@Bowenislandsong Bowenislandsong left a comment

Choose a reason for hiding this comment

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

I think this is very nice. Although, I am only using graph.go.

PackageName string
}

// TODO
Copy link
Member

Choose a reason for hiding this comment

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

nit: remove

}, nil
}

// TODO get bundle path and version
Copy link
Member

Choose a reason for hiding this comment

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

nit: remove

"github.com/operator-framework/operator-registry/pkg/registry"
)

func createLoadedTestDb(t *testing.T) (*sql.DB, func()) {
Copy link
Member

Choose a reason for hiding this comment

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

woo nice test 🎉

Comment on lines 19 to 24
ReplacesBundles []OperatorBundle
Replaces []BundleRef
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ReplacesBundles []OperatorBundle
Replaces []BundleRef
Replaces []*OperatorBundle

Why not this?

Copy link
Member

Choose a reason for hiding this comment

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

After reviewing the rest, I think this could also be:

Suggested change
ReplacesBundles []OperatorBundle
Replaces []BundleRef
Replaces map[string]*OperatorBundle

or:

Suggested change
ReplacesBundles []OperatorBundle
Replaces []BundleRef
Replaces map[BundleRef]*OperatorBundle


type BundleRef struct {
BundlePath string
Version string //semver string
Copy link
Member

Choose a reason for hiding this comment

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

Why not type this as a semver field?


type OperatorBundle struct {
BundlePath string
Version string // semver string
Copy link
Member

Choose a reason for hiding this comment

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

Why not typed?

Copy link
Member Author

Choose a reason for hiding this comment

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

great idea

return channels, nil
}

func getBundle(bundles []registry.OperatorBundle, name string) *registry.OperatorBundle {
Copy link
Member

Choose a reason for hiding this comment

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

it really seems like this could be a map?

return nil
}

func getHeadBundleRefForChannel(bundles []registry.OperatorBundle) *registry.BundleRef {
Copy link
Member

Choose a reason for hiding this comment

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

This assumes an already valid graph, which might not be true of the places you're intending to call this

Copy link
Member Author

Choose a reason for hiding this comment

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

This specific implementation is reading from the sql layer. The assumption here is that the graph is valid because we wouldn't persist it in the first place otherwise.

That being said, I can totally as we flesh this out attempting to do some generation validation. Maybe that's what we should tackle next, and when the insert is written we include that as part of this function?

@@ -113,6 +113,76 @@ func (s *SQLQuerier) GetPackage(ctx context.Context, name string) (*registry.Pac
return pkg, nil
}

func (s *SQLQuerier) GetDefaultPackage(ctx context.Context, name string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: should this be GetDefaultChannel?

Copy link
Member

Choose a reason for hiding this comment

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

Also - is the query interface updated with these?

Copy link
Member Author

Choose a reason for hiding this comment

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

latest updated includes the interface update

type OperatorBundle struct {
BundlePath string
Version string // semver string
CsvName string
Copy link
Member

Choose a reason for hiding this comment

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

In some newer parts of this codebase, we have moved away from CsvName to BundleName or Identifier

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the intention of this type is to explicitly be an aggregate identifier. At some point CsvName could be deprecated entirely. For now they are equivalent though, and I think it's more likely that this field would be removed than refer to a different concept. Wdyt?

type OperatorBundle struct {
BundlePath string
Version string // semver string
CsvName string
Copy link
Member

Choose a reason for hiding this comment

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

WDYT if we replace the first 3 fields with bundleRef? This way we define how we refer to a bundle in one place?

*Create new graph type that can describe channel graphs of packages
*Create initial implementation of loading it from existing sqlite db
CsvName string
}

func (b *BundleKey) IsEmpty() bool {
Copy link
Member

Choose a reason for hiding this comment

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

Since we're using the BundleKey struct as a key in the map, should we add another method to check if two bundle keys are identical? From https://blog.golang.org/maps (where KeyType may be any type that is comparable) .

I guess we don't have to for the purposes of defining the map (Go does this for us) but it may be a helpful utility function to have alongside b.IsEmpty(). b.IsEqual(a).

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that's a fair thing to suggest, but perhaps it should just be included when something that needs to do the comparison is written?

@@ -76,6 +76,18 @@ type ChannelEntry struct {
Replaces string
}

// ChannelEntryNode is a denormalized node in a channel graph annotated with additional entry level info
type ChannelEntryNode struct {
Copy link
Member

Choose a reason for hiding this comment

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

I think the naming between ChannelEntry and ChannelEntryNode is a little confusing. Based on the comments they are similar, one just had more details in it. Maybe we can call it ChannelEntryAnnotated?

// GraphLoader generates a graph
// GraphLoader supports multiple different loading schemes
// GraphLoader from SQL, GraphLoader from old format (filesystem), GraphLoader from SQL + input bundles
type GraphLoader interface {
Copy link
Member

@exdx exdx Mar 25, 2020

Choose a reason for hiding this comment

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

Should we move this interface out of this package as part of this PR?


type Channel struct {
Head BundleKey
Replaces map[BundleKey]map[BundleKey]struct{}
Copy link
Member

Choose a reason for hiding this comment

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

What happened here? Can we define map[BundleKey]map[BundleKey]struct{}? like ReplaceMap?

Copy link
Member Author

Choose a reason for hiding this comment

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

What about nodes ?

}

// GraphFromEntries builds the graph from a set of channel entries
func (g *SQLGraphLoader) GraphFromEntries(channelEntries []registry.ChannelEntryNode) (map[string]registry.Channel, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we should haveGraphFromEntries be on the GraphLoader interface as well - we want all the different loaders to be able to provide this functionality as well right

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe we can have a separate Grapher interface 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually think we explicitly don't want other graphloaders to have this method. This is really specific to the sqlite layer, other loaders wouldn't be aware of this aggregation at all.

todo: squash commits
pkg/sqlite/graphloader.go Outdated Show resolved Hide resolved
}

// GraphFromEntries builds the graph from a set of channel entries
func (g *SQLGraphLoader) GraphFromEntries(channelEntries []registry.ChannelEntryAnnotated) (map[string]registry.Channel, error) {
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: can we make this a function instead of a method of the SQLGraphLoader? the function doesn't use any of the SQLGraphLoader data. This makes the func easier to use in other pkgs

Copy link
Member Author

Choose a reason for hiding this comment

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

seems reasonable

@exdx
Copy link
Member

exdx commented Mar 25, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 25, 2020
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Mar 25, 2020
@exdx
Copy link
Member

exdx commented Mar 25, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 25, 2020
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@benluddy
Copy link
Contributor

/lgtm

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: benluddy, exdx, kevinrizza

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

3 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit d2e8855 into operator-framework:master Mar 25, 2020
@openshift-ci-robot
Copy link

@kevinrizza: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/prow/images 7ca004d link /test images

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants