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: support adding local components to seeds #14149

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

alfonsosanchezbeato
Copy link
Member

This is a first PR that adds support for seeding components. The parts targeted by this PR are:

  • Add support for components in options.yaml
  • Add --comp option to snap prepare-image, for local component files of component names
  • Copy local component files to seed

Interactions with the store are not in this PR.

Copy link
Collaborator

@andrewphelpsj andrewphelpsj 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, some initial comments.

seed/seedwriter/seed20.go Outdated Show resolved Hide resolved
@@ -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 {
Copy link
Collaborator

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.

Copy link
Member Author

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.

@@ -105,6 +128,16 @@ type SeedSnap struct {
local bool
modelSnap *asserts.ModelSnap
optionSnap *OptionsSnap

Components []SeedComponent
Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Member Author

@alfonsosanchezbeato alfonsosanchezbeato left a 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/seed20.go Outdated Show resolved Hide resolved
@@ -105,6 +128,16 @@ type SeedSnap struct {
local bool
modelSnap *asserts.ModelSnap
optionSnap *OptionsSnap

Components []SeedComponent
Copy link
Member Author

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.

@@ -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 {
Copy link
Member Author

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.

Copy link
Collaborator

@andrewphelpsj andrewphelpsj left a 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.

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.

did a first pass, some questions

@@ -31,6 +31,14 @@ import (
"github.com/snapcore/snapd/snap/naming"
)

// ComponentOpt are the options for components for grade: dangerous.
type ComponentOpt struct {
Copy link
Collaborator

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?

Copy link
Member Author

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.

delete(pathToLocalComp, path)
}

s.w.AddComponentsToSnap(sn, seedComps)
Copy link
Collaborator

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?

Copy link
Member Author

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.

@@ -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()
Copy link
Collaborator

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

Copy link
Member Author

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.

Copy link
Collaborator

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?

Copy link
Member Author

@alfonsosanchezbeato alfonsosanchezbeato Jul 9, 2024

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.

Copy link
Member Author

@alfonsosanchezbeato alfonsosanchezbeato left a 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

@@ -31,6 +31,14 @@ import (
"github.com/snapcore/snapd/snap/naming"
)

// ComponentOpt are the options for components for grade: dangerous.
type ComponentOpt struct {
Copy link
Member Author

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.

@@ -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()
Copy link
Member Author

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.

delete(pathToLocalComp, path)
}

s.w.AddComponentsToSnap(sn, seedComps)
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants