Skip to content

Conversation

@perdasilva
Copy link
Contributor

This PR is the first in a series of PRs that bring bundle resolution to the operator-controller.
This PR adds:

  • a BundleEntity struct that makes it easier to deal with the deppy entities we'll be processing
  • Predicates to search for particular entities based on the bundle properties
  • Sort functions to order the entities based on their bundle properties (Note: default channel is not yet handled properly)

Signed-off-by: perdasilva <perdasilva@redhat.com>
Signed-off-by: perdasilva <perdasilva@redhat.com>
Signed-off-by: perdasilva <perdasilva@redhat.com>
@perdasilva perdasilva force-pushed the bundle_entity branch 2 times, most recently from 9017ba0 to a55a00f Compare January 24, 2023 11:50
@perdasilva perdasilva changed the title [resolution Pt. 1] - Bundle entity [resolution Pt1] - Bundle entity Jan 24, 2023
@perdasilva perdasilva changed the title [resolution Pt1] - Bundle entity [resolution pt.1] - bundle entity Jan 24, 2023
@perdasilva perdasilva changed the title [resolution pt.1] - bundle entity [resolution pt.1] bundle entity Jan 24, 2023
}

func (b *BundleEntity) loadPackage() error {
if b.bundlePackage == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there no mutex lock required here unlike the other loadX funcs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!! Fixed

if b.semVersion == nil {
semVer, err := semver.Parse(b.bundlePackage.Version)
if err != nil {
return fmt.Errorf("could not parse semver (%s) for entity '%s': %s", b.bundlePackage.Version, b.ID, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: use %w when wrapping errors in fmt.Errorf().
Here and below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! Fixed =D

Copy link
Member

Choose a reason for hiding this comment

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

In case anyone is wondering why you should use %w when wrapping errors in fmt.Errorf(), checkout this blog.

if errComp != 0 {
// the sign gets inverted because version is sorted
// from highest to lowest
return -1 * errComp
Copy link
Contributor

Choose a reason for hiding this comment

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

So, this will put all non-valid versions at the end?

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this case get tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does, but your comment compelled me to 1) make sure 2) improve it =D

func (b *BundleEntity) loadProvidedGVKs() error {
b.mu.Lock()
defer b.mu.Unlock()
if b.providedGVKs == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible for these values to become out-of-date? If so, if the value in the map was ever updated, this would continue to return the old value right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great observation and question!!
This is read only and just serves to wrap around the Entity, which it doesn't expect to change during its lifetime.

Copy link
Member

@awgreene awgreene Jan 25, 2023

Choose a reason for hiding this comment

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

which it doesn't expect to change during its lifetime.

We may want to document any assumptions that we make. Do we prevent cache changes when deppy is solving?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it == BundleEntity. The corresponding entity can change, but only on the source of truth (e.g. catalog source). But from the time you pull the entity down from source until resolution, it shouldn't change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for answering! Makes perfect sense to me.

Copy link
Contributor

@dtfranz dtfranz left a comment

Choose a reason for hiding this comment

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

No blocking issues for me, just a couple questions 😃

@tmshort
Copy link
Contributor

tmshort commented Jan 24, 2023

Getting failures now.

Signed-off-by: perdasilva <perdasilva@redhat.com>
Copy link
Contributor

@tmshort tmshort left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 24, 2023
@tmshort
Copy link
Contributor

tmshort commented Jan 24, 2023

You will need to rebase your other PRs.

bundleEntity := olmentity.NewBundleEntity(entity)
name, err := bundleEntity.PackageName()
if err != nil {
return false
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking nit: should we add debug logs to these messages?

})

Describe("InChannel", func() {
It("should return true when the entity has the has version in the right range", func() {
Copy link
Member

@awgreene awgreene Jan 25, 2023

Choose a reason for hiding this comment

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

Non-blocking nit, but something we should fix.

Suggested change
It("should return true when the entity has the has version in the right range", func() {
It("should return true when the entity comes from the specified channel", func() {

Copy link
Member

@awgreene awgreene left a comment

Choose a reason for hiding this comment

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

Looks great Per, I appreciate all the test cases that you wrote!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants