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

Introduce Masterminds/semver #374

Merged
merged 3 commits into from
Aug 31, 2023
Merged

Conversation

tmshort
Copy link
Contributor

@tmshort tmshort commented Aug 29, 2023

Description

Add support for Masterminds/semver for .spec.Version
This is a bit more entangled into the code than I expected,
most instances of bsemver were replaced.

Fixes #345 and #346.

Includes the regex commit.

Reviewer Checklist

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

@tmshort tmshort requested a review from a team as a code owner August 29, 2023 19:34
@codecov
Copy link

codecov bot commented Aug 29, 2023

Codecov Report

Patch coverage: 85.71% and project coverage change: -0.04% ⚠️

Comparison is base (db08a62) 81.68% compared to head (f005767) 81.64%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #374      +/-   ##
==========================================
- Coverage   81.68%   81.64%   -0.04%     
==========================================
  Files          21       21              
  Lines         928      937       +9     
==========================================
+ Hits          758      765       +7     
- Misses        118      119       +1     
- Partials       52       53       +1     
Flag Coverage Δ
e2e 61.79% <50.00%> (-0.50%) ⬇️
unit 77.23% <85.71%> (+<0.01%) ⬆️

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

Files Changed Coverage Δ
api/v1alpha1/operator_types.go 100.00% <ø> (ø)
internal/resolution/util/predicates/predicates.go 91.83% <77.77%> (-3.17%) ⬇️
internal/controllers/validators/validators.go 100.00% <100.00%> (ø)
...lution/variablesources/bundles_and_dependencies.go 87.09% <100.00%> (ø)
...nal/resolution/variablesources/required_package.go 73.80% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tmshort tmshort changed the title Oprun 3034 Commits on Aug 29, 2023 Introduce Masterminds/semver Aug 29, 2023
@tmshort
Copy link
Contributor Author

tmshort commented Aug 29, 2023

I think it needs more testing, but this is a start.
/hold

@ncdc ncdc changed the title Commits on Aug 29, 2023 Introduce Masterminds/semver Introduce Masterminds/semver Aug 29, 2023
@ncdc
Copy link
Member

ncdc commented Aug 29, 2023

@tmshort we don't have Prow on this repo; if you'd like to "hold" the PR, I'd recommend converting it to draft.

@tmshort tmshort marked this pull request as draft August 29, 2023 20:37
@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Aug 29, 2023
@@ -87,7 +87,7 @@ func (b *BundlesAndDepsVariableSource) getEntityDependencies(ctx context.Context
// todo(perdasilva): disambiguate between not found and actual errors
requiredPackages, _ := bundleEntity.RequiredPackages()
for _, requiredPackage := range requiredPackages {
semverRange, err := bsemver.ParseRange(requiredPackage.VersionRange)
semverRange, err := mmsemver.NewConstraint(requiredPackage.VersionRange)
Copy link
Member

@joelanford joelanford Aug 29, 2023

Choose a reason for hiding this comment

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

Technically, this should remain blang if we don't want to change the meaning of (and possibly break) the olm.package.required constraints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can look at it; changes were only made if they propagated from validation.gos changes. This likely means that it would require intermixing Masterminds and blang code here.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, looks like you'll need to convert a blang version to a masterminds verison somewhere along the line.

It looks like bundles_and_dependencies.go and required_package.go both call predicates.InVersionRange, so it seems like we'll have to break that in two. Perhaps:

  • predicates.InMastermindsVersionRange
  • predicates.InBlangVersionRange

And then predicates.InMasterMindsVersionRange converts the bundle entity blang version to a masterminds version to check against the mastermind constraint?

Copy link
Contributor Author

@tmshort tmshort Aug 30, 2023

Choose a reason for hiding this comment

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

blang.Range is a function and cannot be converted into a MasterMind.Constraints (which is a struct). I'm working out a couple different methods; none of which are pretty...

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 29, 2023
@tmshort tmshort force-pushed the OPRUN-3034 branch 2 times, most recently from 8ca0525 to f63044a Compare August 30, 2023 21:29
@tmshort tmshort marked this pull request as ready for review August 31, 2023 13:24
@tmshort
Copy link
Contributor Author

tmshort commented Aug 31, 2023

@joelanford ready for review

"1.Y",
">1.2.3 && <2.3.4",
">1.2.3;<2.3.4",
"1.2.3 - 2.3.4",
Copy link
Contributor

Choose a reason for hiding this comment

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

worth including the blang '!=' equivalent here? (e.g. "!1.2.3")

Copy link
Contributor Author

@tmshort tmshort Aug 31, 2023

Choose a reason for hiding this comment

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

Probably.

@tmshort
Copy link
Contributor Author

tmshort commented Aug 31, 2023

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 31, 2023
Fixes operator-framework#345

Add positive and negative test cases.

Signed-off-by: Todd Short <tshort@redhat.com>
Fixes operator-framework#346

Add support for Masterminds/semver for .spec.Version
This is a bit more entangled into the code than I expected,
most instances of bsemver were replaced.

Signed-off-by: Todd Short <tshort@redhat.com>
@tmshort
Copy link
Contributor Author

tmshort commented Aug 31, 2023

ping @grokspawn @joelanford this should be ready now

if err := b.loadPackage(); err != nil {
return nil, err
}
return mmsemver.NewVersion(b.bundlePackage.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: the asymmetry of VersionBlang() stuff being parsed during b.loadPackage() and the masterminds version being parsed here every time is maybe a bit unexpected and feels a bit off?

Other potential options:

  • add a new sibling field to b.semVersion, parse both during loadPackage()
  • parse into a blang version and then just build a masterminds.Version struct (either here or in loadPackage) using the blang version fields (this might be nice because its one fewer error to handle)
  • have this Version() method just return a string and expect that caller to do the parsing.

Copy link
Member

Choose a reason for hiding this comment

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

Another option: do the (option 2) conversion from blang version to masterminds version in the InMastermindsVersionRange() function.

Copy link
Contributor Author

@tmshort tmshort Aug 31, 2023

Choose a reason for hiding this comment

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

TL;DR: this is what happens when you try to optimize code coverage!

  1. I had created a new field, but all errors occurred during blang code processing (since it's just a simple version), and subsequently the masterminds error handling code was never executed, lowering code coverage. I could get rid of the error handling code, but that's bad form.
  2. The Masterminds.Version struct has no user-accessible fields, so you can't create the structure that way. It actually makes more sense to do a blang.Version.String() and feed that into Masterminds.NewVersion(), but it's the same error handling problem as option 1.
  3. This causes the version string to be parsed all the time, also non-optimal, and worse performance than option 1.

EDIT: Using just one semver library would make this moot.
EDIT 2: Option 3 is probably the cleanest in terms of API cleanliness, but not efficiency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another option: do the (option 2) conversion from blang version to masterminds version in the InMastermindsVersionRange() function.

AFAICT, this means passing an blang structure into a mastermind-named function, which seems bad form.

Copy link
Member

Choose a reason for hiding this comment

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

this means passing an blang structure into a mastermind-named function, which seems bad form.

I don't think so.

func InMastermindsSemverRange(semverRange *mmsemver.Constraints) input.Predicate {
	return func(entity *input.Entity) bool {
		bundleEntity := olmentity.NewBundleEntity(entity)
		bundleVersion, err := bundleEntity.Version() // this is a blang version
		if err != nil {
			return false
		}
		return semverRange.Check(blangToMasterminds(bundleVersion))
	}
}

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@tmshort tmshort Aug 31, 2023

Choose a reason for hiding this comment

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

Although option 3 might be the cleanest, it is changing the behavior of sortVersion().

Anything I do to try to fix the nit will negatively impact code coverage.

Copy link
Member

Choose a reason for hiding this comment

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

IMO, trying to cover every error path just leads to brittle tests that make refactoring hard. I think as long as we're covering the happy paths, and the coverage "regression" is only happening because of some refactoring of when/how errors are handled, we shouldn't spend time dealing in the 1s or .1s of coverage percentages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a way to specify a (minimum, err maximum? negative) threshold for CodeCov?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I was thinking of this function: https://github.com/Masterminds/semver/blob/2f39fdc11c33c38e8b8b15b1f04334ba84e751f2/version.go#L214

Because of the pre and metadata fields, etc. it's just easier to do all conversions via .String().

Signed-off-by: Todd Short <tshort@redhat.com>
@tmshort tmshort added this pull request to the merge queue Aug 31, 2023
Merged via the queue into operator-framework:main with commit 628ae95 Aug 31, 2023
10 of 11 checks passed
@tmshort tmshort deleted the OPRUN-3034 branch September 1, 2023 13:49
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.

Version Ranges: Update CRD Regex
4 participants