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
Graph Loader initial implementation #224
Conversation
There was a problem hiding this 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.
pkg/sqlite/graphloader.go
Outdated
PackageName string | ||
} | ||
|
||
// TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove
pkg/sqlite/graphloader.go
Outdated
}, nil | ||
} | ||
|
||
// TODO get bundle path and version |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woo nice test 🎉
pkg/registry/graph.go
Outdated
ReplacesBundles []OperatorBundle | ||
Replaces []BundleRef |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReplacesBundles []OperatorBundle | |
Replaces []BundleRef | |
Replaces []*OperatorBundle |
Why not this?
There was a problem hiding this comment.
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:
ReplacesBundles []OperatorBundle | |
Replaces []BundleRef | |
Replaces map[string]*OperatorBundle |
or:
ReplacesBundles []OperatorBundle | |
Replaces []BundleRef | |
Replaces map[BundleRef]*OperatorBundle |
|
||
type BundleRef struct { | ||
BundlePath string | ||
Version string //semver string |
There was a problem hiding this comment.
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?
pkg/registry/graph.go
Outdated
|
||
type OperatorBundle struct { | ||
BundlePath string | ||
Version string // semver string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not typed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great idea
pkg/sqlite/graphloader.go
Outdated
return channels, nil | ||
} | ||
|
||
func getBundle(bundles []registry.OperatorBundle, name string) *registry.OperatorBundle { |
There was a problem hiding this comment.
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?
pkg/sqlite/graphloader.go
Outdated
return nil | ||
} | ||
|
||
func getHeadBundleRefForChannel(bundles []registry.OperatorBundle) *registry.BundleRef { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
pkg/registry/graph.go
Outdated
type OperatorBundle struct { | ||
BundlePath string | ||
Version string // semver string | ||
CsvName string |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
pkg/registry/graph.go
Outdated
type OperatorBundle struct { | ||
BundlePath string | ||
Version string // semver string | ||
CsvName string |
There was a problem hiding this comment.
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
d5d9944
to
ff4daf8
Compare
CsvName string | ||
} | ||
|
||
func (b *BundleKey) IsEmpty() bool { |
There was a problem hiding this comment.
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)
.
There was a problem hiding this comment.
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?
pkg/registry/types.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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
?
pkg/sqlite/graphloader.go
Outdated
// 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 { |
There was a problem hiding this comment.
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?
pkg/registry/graph.go
Outdated
|
||
type Channel struct { | ||
Head BundleKey | ||
Replaces map[BundleKey]map[BundleKey]struct{} |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about nodes
?
pkg/sqlite/graphloader.go
Outdated
} | ||
|
||
// GraphFromEntries builds the graph from a set of channel entries | ||
func (g *SQLGraphLoader) GraphFromEntries(channelEntries []registry.ChannelEntryNode) (map[string]registry.Channel, error) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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
} | ||
|
||
// GraphFromEntries builds the graph from a set of channel entries | ||
func (g *SQLGraphLoader) GraphFromEntries(channelEntries []registry.ChannelEntryAnnotated) (map[string]registry.Channel, error) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems reasonable
/lgtm |
/lgtm |
/retest Please review the full test history for this PR and help us cut down flakes. |
/lgtm |
[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 |
/retest Please review the full test history for this PR and help us cut down flakes. |
3 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
@kevinrizza: The following test failed, say
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. |
*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