-
Notifications
You must be signed in to change notification settings - Fork 564
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: support adding local components to seeds #14149
base: master
Are you sure you want to change the base?
many: support adding local components to seeds #14149
Conversation
1cc6121
to
4cf73ca
Compare
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.
Thank you, some initial comments.
seed/seedwriter/writer.go
Outdated
@@ -655,13 +715,14 @@ func (w *Writer) InfoDerived() error { | |||
|
|||
// SetInfo sets Info of the SeedSnap and possibly computes its | |||
// destination Path. | |||
func (w *Writer) SetInfo(sn *SeedSnap, info *snap.Info) error { | |||
func (w *Writer) SetInfo(sn *SeedSnap, info *snap.Info, seedComps []SeedComponent) 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.
This is maybe a little strange? Passing in a param to just set a field on the SeedSnap
.
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 the end I decided to add a new method, Writer.AddComponentsToSnap
to avoid mixing concerns with SetInfo
. Although it just sets a variable.
seed/seedwriter/writer.go
Outdated
@@ -105,6 +128,16 @@ type SeedSnap struct { | |||
local bool | |||
modelSnap *asserts.ModelSnap | |||
optionSnap *OptionsSnap | |||
|
|||
Components []SeedComponent |
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 reading the code some more, I see why this is you used SetInfo
to initialize this field, since there is already this deferred initialization of parts of this type. Maybe a comment here on this field, and move this next to the Info
field that is in the same boat.
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've moved and added a comment.
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.
@andrewphelpsj thanks for the review, I've addressed your comments now.
seed/seedwriter/writer.go
Outdated
@@ -105,6 +128,16 @@ type SeedSnap struct { | |||
local bool | |||
modelSnap *asserts.ModelSnap | |||
optionSnap *OptionsSnap | |||
|
|||
Components []SeedComponent |
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've moved and added a comment.
seed/seedwriter/writer.go
Outdated
@@ -655,13 +715,14 @@ func (w *Writer) InfoDerived() error { | |||
|
|||
// SetInfo sets Info of the SeedSnap and possibly computes its | |||
// destination Path. | |||
func (w *Writer) SetInfo(sn *SeedSnap, info *snap.Info) error { | |||
func (w *Writer) SetInfo(sn *SeedSnap, info *snap.Info, seedComps []SeedComponent) 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.
In the end I decided to add a new method, Writer.AddComponentsToSnap
to avoid mixing concerns with SetInfo
. Although it just sets a variable.
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.
Thanks for the changes, looks good to me.
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.
did a first pass, some questions
seed/internal/options20.go
Outdated
@@ -31,6 +31,14 @@ import ( | |||
"github.com/snapcore/snapd/snap/naming" | |||
) | |||
|
|||
// ComponentOpt are the options for components for grade: dangerous. | |||
type ComponentOpt 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.
why Opt in the name?
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.
Change to Component
as I see that we have also internal.Snap20
.
image/image_linux.go
Outdated
delete(pathToLocalComp, path) | ||
} | ||
|
||
s.w.AddComponentsToSnap(sn, seedComps) |
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 also a bit unsure about this API, shouldn't some of these checks be done by the writer instead?
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.
Agreed, I've moved some checks to the writer.
image/image_linux.go
Outdated
@@ -451,14 +451,15 @@ func (s *imageSeeder) validateSnapArchs(snaps []*seedwriter.SeedSnap) error { | |||
|
|||
type localSnapRefs map[*seedwriter.SeedSnap][]*asserts.Ref | |||
|
|||
func (s *imageSeeder) deriveInfoForLocalSnaps(f seedwriter.SeedAssertionFetcher, db *asserts.Database) (localSnapRefs, error) { | |||
func (s *imageSeeder) deriveInfoForLocalSnaps(f seedwriter.SeedAssertionFetcher, db *asserts.Database, pathToLocalComp map[string]*snap.ComponentInfo) (localSnapRefs, error) { | |||
localSnaps, err := s.w.LocalSnaps() |
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 there be something like LocalComponents() as well? we will symmetrically also be told what components to download to follow how the non-local case work? There's a symmetry between LocalSnaps() and SnapsToDownload that we should try to follow
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 am trying to include information about the components in the snap structures, so LocalSnaps()
should be enough as SeedSnap
contains a slice of SeedComponent
. The problem that I have here is that to fill that slice I have to do it in deriveInfoForLocalSnaps
as in w.SetOptionsSnaps
I cannot match local components to local snaps as I do not know the snap name until later, and I am trying to avoid a double read of the squashfs file.
This could be solved by some refactoring of the writer stages (running w.Start
before w.SetOptionsSnap
), but I did not want to put this in this PR as it was big enough.
The []*SeedSnap
returned by SnapsToDownload
would also include needed components inside as required.
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.
my point is a bit different is not clear that we shouldn't let the writer manage something like pathToLocalComp internally? and let it do a bit more of the matching work as well, while letting the caller do a smaller part of the work. What I'm saying is that maybe SetOptionsSnaps should also take a list of OptionsComponent?
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.
Ok, I've pushed now more things to the writer and passed down pathToLocalComp so it can be used when we know the names of the local snap files. I think that passing as OptionComponent would complicate things a bit as then we would need to get back the local components to image
to read the files, and also, we have already consumed the non-local related component options so it would not be the full options actually.
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.
@pedronis thanks for the review, I've addressed your comments now
seed/internal/options20.go
Outdated
@@ -31,6 +31,14 @@ import ( | |||
"github.com/snapcore/snapd/snap/naming" | |||
) | |||
|
|||
// ComponentOpt are the options for components for grade: dangerous. | |||
type ComponentOpt 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.
Change to Component
as I see that we have also internal.Snap20
.
image/image_linux.go
Outdated
@@ -451,14 +451,15 @@ func (s *imageSeeder) validateSnapArchs(snaps []*seedwriter.SeedSnap) error { | |||
|
|||
type localSnapRefs map[*seedwriter.SeedSnap][]*asserts.Ref | |||
|
|||
func (s *imageSeeder) deriveInfoForLocalSnaps(f seedwriter.SeedAssertionFetcher, db *asserts.Database) (localSnapRefs, error) { | |||
func (s *imageSeeder) deriveInfoForLocalSnaps(f seedwriter.SeedAssertionFetcher, db *asserts.Database, pathToLocalComp map[string]*snap.ComponentInfo) (localSnapRefs, error) { | |||
localSnaps, err := s.w.LocalSnaps() |
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 am trying to include information about the components in the snap structures, so LocalSnaps()
should be enough as SeedSnap
contains a slice of SeedComponent
. The problem that I have here is that to fill that slice I have to do it in deriveInfoForLocalSnaps
as in w.SetOptionsSnaps
I cannot match local components to local snaps as I do not know the snap name until later, and I am trying to avoid a double read of the squashfs file.
This could be solved by some refactoring of the writer stages (running w.Start
before w.SetOptionsSnap
), but I did not want to put this in this PR as it was big enough.
The []*SeedSnap
returned by SnapsToDownload
would also include needed components inside as required.
image/image_linux.go
Outdated
delete(pathToLocalComp, path) | ||
} | ||
|
||
s.w.AddComponentsToSnap(sn, seedComps) |
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.
Agreed, I've moved some checks to the writer.
This is a first PR that adds support for seeding components. The parts targeted by this PR are:
Interactions with the store are not in this PR.