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

Implement upgrade edges support #275

Merged
merged 2 commits into from
Aug 3, 2023

Conversation

jmprusi
Copy link
Member

@jmprusi jmprusi commented Jun 27, 2023

Description

Adds upgrade edges support to operator-controller

  • Annotates bundleDeployments with the original operator information (packageName, Channel, Version)
  • Adds a new constraint that uses the packages "replaces" value to ensure that the upgrade path between the previous version and the new one is valid.

Closes #268
Closes #267

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 27, 2023
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 27, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 27, 2023
@jmprusi jmprusi changed the title WIP - Implement upgrade edges support Implement upgrade edges support Jun 27, 2023
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 29, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 3, 2023
@jmprusi jmprusi force-pushed the jmprusi/upgrade-edges branch 6 times, most recently from fff05ac to a6205a7 Compare July 6, 2023 12:15
@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Merging #275 (552f129) into main (949c06a) will decrease coverage by 18.12%.
The diff coverage is 72.34%.

@@             Coverage Diff             @@
##             main     #275       +/-   ##
===========================================
- Coverage   80.69%   62.58%   -18.12%     
===========================================
  Files          18       21        +3     
  Lines         803      890       +87     
===========================================
- Hits          648      557       -91     
- Misses        112      241      +129     
- Partials       43       92       +49     
Flag Coverage Δ
e2e 62.58% <72.34%> (+6.79%) ⬆️
unit ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
internal/resolution/variablesources/operator.go 68.42% <ø> (-10.53%) ⬇️
...al/resolution/variablesources/installed_package.go 62.06% <62.06%> (ø)
internal/resolution/util/predicates/predicates.go 40.00% <66.66%> (-31.43%) ⬇️
internal/resolution/entities/bundle_entity.go 56.77% <68.75%> (-38.55%) ⬇️
...al/resolution/variablesources/bundle_deployment.go 71.42% <71.42%> (ø)
internal/controllers/variable_source.go 100.00% <100.00%> (ø)
...nternal/resolution/entitysources/catalogdsource.go 59.70% <100.00%> (+1.23%) ⬆️
internal/resolution/util/sort/sort.go 54.28% <100.00%> (-40.00%) ⬇️
internal/resolution/variables/installed_package.go 100.00% <100.00%> (ø)
...lution/variablesources/bundles_and_dependencies.go 50.00% <100.00%> (-36.67%) ⬇️

... and 6 files with indirect coverage changes

@jmprusi jmprusi force-pushed the jmprusi/upgrade-edges branch 6 times, most recently from fd5be1f to 2da8d70 Compare July 12, 2023 11:36
@jmprusi jmprusi marked this pull request as ready for review July 12, 2023 11:36
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 12, 2023
@@ -269,6 +265,27 @@ var _ = Describe("BundleEntity", func() {
})
})

Describe("Replaces", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

@@ -106,6 +110,9 @@ func getEntities(ctx context.Context, client client.Client) (input.EntityList, e
if catalogScopedEntryName == bundle.Name {
channelValue, _ := json.Marshal(property.Channel{ChannelName: ch.Name, Priority: 0})
props[property.TypeChannel] = string(channelValue)
// TODO(jmprusi): Add the proper PropertyType for this
Copy link
Contributor

Choose a reason for hiding this comment

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

should we address this todo?

Copy link
Member

Choose a reason for hiding this comment

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

I know the following suggestion is a bigger refactor, and I'm not suggesting we do it now, but I think we should refactor things such that there are:

  • variable source for bundles
  • variable source for channels

Bundle entities would no longer carry upgrade edge or channel membership information. Rather, channel variables would incorporate bundle membership and upgrade edges.

Copy link
Member

Choose a reason for hiding this comment

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

IMO, something like my suggestion should happen almost immediately after this PR lands so that we set ourselves up for a more extensible future where different channel implementations can exist and we don't have to keep adding synthetic properties to bundles (which might have undesirable effects if/when we support more arbitrary contraint definitions in the future)

return r.bundleEntities
}

func NewInstalledPackageVariable(bundleImage string, bundleEntities []*olmentity.BundleEntity) *InstalledPackageVariable {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add a unit test for this function?

Copy link
Member

Choose a reason for hiding this comment

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

Seems like a unit test was added here.

}
}

func (o *BundleDeploymentVariableSource) GetVariables(ctx context.Context, entitySource input.EntitySource) ([]deppy.Variable, error) {
Copy link
Contributor

@perdasilva perdasilva Jul 17, 2023

Choose a reason for hiding this comment

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

we should probably have good test coverage of this function, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

done, CI failing due to codecov issues..

}

// sort by channel and version
// TODO: this is a bit of a hack and it assumes a well formed catalog.
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please create issue/s for these todos and link them in the comments here?

Copy link
Contributor

@perdasilva perdasilva left a comment

Choose a reason for hiding this comment

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

Looks really good ^^ Thank you for this! I know it was tough. I think we just need to address a couple of the todos, add issue/s for the others, and maybe a little bit more unit test coverage. Great work!

@jmprusi jmprusi requested a review from a team as a code owner July 18, 2023 13:03
@jmprusi jmprusi force-pushed the jmprusi/upgrade-edges branch 9 times, most recently from e87975d to d6084e3 Compare July 25, 2023 10:50
Signed-off-by: Joaquim Moreno Prusi <joaquim@redhat.com>
Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com>

Co-authored-by: Per Goncalves da Silva <pegoncal@redhat.com>
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.

/approve

@@ -296,4 +313,46 @@ var _ = Describe("BundleEntity", func() {
Expect(err.Error()).To(Equal("error determining bundle mediatype for entity 'operatorhub/prometheus/0.14.0': property 'olm.bundle.mediatype' ('badtype') could not be parsed: invalid character 'b' looking for beginning of value"))
})
})

// Increase test coverage
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I would remove this or add a TODO if this is meant to be done in the future, non-blocking though.

return r.bundleEntities
}

func NewInstalledPackageVariable(bundleImage string, bundleEntities []*olmentity.BundleEntity) *InstalledPackageVariable {
Copy link
Member

Choose a reason for hiding this comment

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

Seems like a unit test was added here.

@@ -106,6 +110,9 @@ func getEntities(ctx context.Context, client client.Client) (input.EntityList, e
if catalogScopedEntryName == bundle.Name {
channelValue, _ := json.Marshal(property.Channel{ChannelName: ch.Name, Priority: 0})
props[property.TypeChannel] = string(channelValue)
// TODO(jmprusi): Add the proper PropertyType for this
replacesValue, _ := json.Marshal(replacesProperty{Replaces: b.Replaces})
props["olm.replaces"] = string(replacesValue)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we move this to a constant? (olm.replaces)

Copy link
Contributor

@perdasilva perdasilva left a comment

Choose a reason for hiding this comment

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

lgtm - small non-blocking issue around a magic string. But we can tackle that on in the next PR ^^

@awgreene awgreene added this pull request to the merge queue Aug 3, 2023
Merged via the queue into operator-framework:main with commit c145c46 Aug 3, 2023
7 of 9 checks passed
Comment on lines +23 to +32
id := deppy.IdentifierFromString(fmt.Sprintf("installed package %s", bundleImage))
entityIDs := make([]deppy.Identifier, 0, len(bundleEntities))
for _, bundle := range bundleEntities {
entityIDs = append(entityIDs, bundle.ID)
}
return &InstalledPackageVariable{
SimpleVariable: input.NewSimpleVariable(id, constraint.Mandatory(), constraint.Dependency(entityIDs...)),
bundleEntities: bundleEntities,
}
}
Copy link
Member

Choose a reason for hiding this comment

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

@jmprusi what is the difference between this and RequiredPackageVariable?

Copy link
Contributor

Choose a reason for hiding this comment

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

They are semantically different concepts that get translated to the same sort of structure (variable with mandatory and dependency constraints). I guess we could separate that out as a concept if we want to simplify the code here a bit. wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

They are semantically different concepts that get translated to the same sort of structure (variable with mandatory and dependency constraints).

@perdasilva Is it just semantic difference? Or are they/will they be processed differently? As far as I understnad - they are exactly the same today.

I guess we could separate that out as a concept if we want to simplify the code here a bit. wdyt?

For now I'm just trying to understand how it works. But I don't follow - what do you mean by separating? They are already separate structures.

Copy link
Contributor

Choose a reason for hiding this comment

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

For now it is. It could be that these two evolve on different paths. I meant separate out the pattern of a Variable with a Mandatory and Dependency constraints. I think it could be a common pattern. Then we can just typedef the required and installed package variables as that.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the clarification.

I meant separate out the pattern of a Variable with a Mandatory and Dependency constraints. I think it could be a common pattern. Then we can just typedef the required and installed package variables as that.

Sounds like a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Solver: Introduce variable sources for installed bundles Solver: Introduce constraints for "upgrade edges"
6 participants