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

many: expose component constraints from validation sets #14592

Merged

Conversation

andrewphelpsj
Copy link
Member

This refactor enables us to get component constraints out of snapasserts.ValidationSets. I also removed some of the old methods that can be replaced by these new ones.

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 85.18519% with 16 lines in your changes missing coverage. Please review.

Project coverage is 78.96%. Comparing base (96ea7b0) to head (28fe47e).
Report is 24 commits behind head on master.

Files with missing lines Patch % Lines
asserts/snapasserts/validation_sets.go 84.93% 7 Missing and 4 partials ⚠️
image/image_linux.go 50.00% 2 Missing and 1 partial ⚠️
overlord/snapstate/snapstate.go 87.50% 1 Missing ⚠️
overlord/snapstate/target.go 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #14592      +/-   ##
==========================================
+ Coverage   78.95%   78.96%   +0.01%     
==========================================
  Files        1084     1085       +1     
  Lines      146638   147146     +508     
==========================================
+ Hits       115773   116192     +419     
- Misses      23667    23725      +58     
- Partials     7198     7229      +31     
Flag Coverage Δ
unittests 78.96% <85.18%> (+0.01%) ⬆️

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

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

@andrewphelpsj andrewphelpsj force-pushed the expose-component-constraints branch 2 times, most recently from 6bbfc3b to 3c91b0b Compare October 10, 2024 17:02
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

I suggest the first commit here should be its own PR, thanks

@andrewphelpsj andrewphelpsj force-pushed the expose-component-constraints branch 2 times, most recently from 407b591 to ddb3518 Compare October 15, 2024 13:06
@andrewphelpsj
Copy link
Member Author

andrewphelpsj commented Oct 15, 2024

Based on #14352 for now, working on getting that merged now. First commit in this PR is 7515505.

Copy link
Contributor

@miguelpires miguelpires left a comment

Choose a reason for hiding this comment

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

lgtm, just one question

asserts/snapasserts/validation_sets.go Outdated Show resolved Hide resolved
@@ -413,14 +414,12 @@ func completeStoreAction(action *store.SnapAction, revOpts RevisionOptions, igno

// if the caller didn't provide any validation sets, make sure that
// the snap is allowed by all of the enforced validation sets
invalidSets, err := vsets.CheckPresenceInvalid(naming.Snap(action.InstanceName))
pres, err := vsets.Presence(naming.Snap(action.InstanceName))
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this get the right presence if we use an instance name?

Copy link
Member Author

@andrewphelpsj andrewphelpsj Oct 16, 2024

Choose a reason for hiding this comment

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

Good catch, thank you. Seems this has been wrong.

Copy link
Member Author

@andrewphelpsj andrewphelpsj Oct 16, 2024

Choose a reason for hiding this comment

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

This is fixed in 52db459 and 4d28fda.

After talking with @pedronis, we should explicitly ignore validation sets when working with parallel installs. This wasn't really codified before, we were just getting lucky with how the snapasserts API handled instance names.

@andrewphelpsj
Copy link
Member Author

This is now based on #14621, the validation sets changes will end up needing this new code.

Copy link
Contributor

@miguelpires miguelpires left a comment

Choose a reason for hiding this comment

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

thank you

// TODO: figure out the best way to handle parallel installs and
// validation sets. right now, we just ignore them.
if isParallelInstall {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's worth logging something in case we hit this unexpectedly?

@andrewphelpsj
Copy link
Member Author

@pedronis this is ready for your review again.

@andrewphelpsj andrewphelpsj force-pushed the expose-component-constraints branch 2 times, most recently from f922b67 to 7664aa9 Compare October 28, 2024 10:10
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

thank you, did a pass

overlord/snapstate/snapstate.go Outdated Show resolved Hide resolved

// RequiredComponents returns a set of all of the components that are required
// to be installed when this snap is installed.
func (s *SnapPresence) RequiredComponents() map[string]presence {
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's strange to have a public method that has a return that uses an unexported type?

asserts/snapasserts/validation_sets.go Outdated Show resolved Hide resolved
// The method assumes that validation sets are not in conflict.
func (v *ValidationSets) CheckPresenceInvalid(snapRef naming.SnapRef) ([]ValidationSetKey, error) {
cstrs := v.constraintsForSnap(snapRef)
type presence struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

wouldn't it be a bit clearer if this was exported?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, probably. I was having a hard time naming it, since Presence technically already has a meaning.

asserts/snapasserts/validation_sets.go Show resolved Hide resolved
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

couple of naming suggestions

cstrs := v.constraintsForSnap(snapRef)
// ContainerPresence represents the allowed presence of a snap or component with
// respect to a set of validation sets that it was derived from.
type ContainerPresence struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

we have a PresenceConstraintError alread,y maybe this should be called PresenceContraint ?


// SnapPresence contains information about a snap's allowed presence with
// respect to a set of validation sets.
type SnapPresence struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

SnapPresenceConstraint(s) ?

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, thanks.

Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

thank you

func NewSnapPresence(p ContainerPresence, comps map[string]ContainerPresence) SnapPresence {
return SnapPresence{
ContainerPresence: p,
func NewSnapPresence(p PresenceContraint, comps map[string]PresenceContraint) SnapPresenceConstraints {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this also be renamed for consistency?

@andrewphelpsj
Copy link
Member Author

The arch failures are a known issue due to arch releasing the 6.12 over the weekend. A fix is being worked on.

@alfonsosanchezbeato alfonsosanchezbeato merged commit beac918 into canonical:master Nov 26, 2024
50 of 54 checks passed
@andrewphelpsj andrewphelpsj deleted the expose-component-constraints branch November 26, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants