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
snap: add new type "TypeSnapd" and attach to the snapd snap #5704
Conversation
We use types sort sorting but the snapd snap is handled special (in the sort code and in more places). By adding a new "TypeSnapd" snap type this becomes more uniform. The current approach is to assign the type when reading the snap.yaml. This is mostly to make the transition easier for people who have snapd installed already but the snapd does not have the right type yet. We could omit it given that we have no real core18 systems in the wild yet and that snapd is not installable yet on classic/core16 systems.
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.
+1. I made some suggestions about sorting but those are entirely non-binding. Once this lands we can also simplify other special-casing of the name in the interface manager and the policy checker.
snap/info.go
Outdated
func (r ByType) Len() int { return len(r) } | ||
func (r ByType) Swap(i, j int) { r[i], r[j] = r[j], r[i] } | ||
func (r ByType) Less(i, j int) bool { | ||
return typeOrder[r[i].Type] < typeOrder[r[j].Type] |
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.
❤️
snap/types.go
Outdated
// This is the sort order from least important to most important for | ||
// types. On e.g. firstboot this will be used to order the snaps this | ||
// way. | ||
var typeOrder = map[Type]int{ |
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.
While this is perfectly fine I was thinking about something like this:
func (t Type) sortOrder() int {
return typeOrder[t]
}
snap/info.go
Outdated
func (r ByType) Len() int { return len(r) } | ||
func (r ByType) Swap(i, j int) { r[i], r[j] = r[j], r[i] } | ||
func (r ByType) Less(i, j int) bool { | ||
return typeOrder[r[i].Type] < typeOrder[r[j].Type] |
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.
If you would be interested in taking my advice below this then becomes r[i].Type.sortOrder() , r[j].Type.sortOrder()
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 like that a lot!
c.Assert(err, IsNil) | ||
c.Assert(info.InstanceName(), Equals, "snapd") | ||
c.Assert(info.Version, Equals, "1.0") | ||
c.Assert(info.Type, Equals, snap.TypeSnapd) |
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.
Ha, very nice :)
This failed on something weird:
I've restarted the test but I suspect it will be "back". |
snapcraft.yaml
Outdated
@@ -11,6 +11,7 @@ version: set-by-version-script-thxbye | |||
version-script: | | |||
./mkversion.sh --output-only | |||
grade: devel | |||
type: snapd |
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.
we should ask review-tools and the store to add this new type
Codecov Report
@@ Coverage Diff @@
## master #5704 +/- ##
==========================================
+ Coverage 78.97% 78.98% +<.01%
==========================================
Files 524 524
Lines 40003 40003
==========================================
+ Hits 31594 31596 +2
+ Misses 5841 5839 -2
Partials 2568 2568
Continue to review full report at Codecov.
|
snap/info.go
Outdated
return false | ||
} | ||
return typeOrder[r[i].Type] < typeOrder[r[j].Type] | ||
return r[i].Type.sortOrder() < r[j].Type.sortOrder() |
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'd capture this in a helper of Type so that the caller does not need to know if sorting order is low -> hi or hi -> low.
func (m Type) SortsBefore(other Type) bool {
return m.sortOrder() < m.sortOrder()
}
Then the code here becomes:
func (r ByType) Less(i, j int) bool {
return r[i].Type.SortsBefore(r[j].Type)
}
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.
LGTM
A bit of an RFC - but I think we want this as it makes sorting easier
and once we have the type we can cleanup a bunch more.
We use types sort sorting but the snapd snap is handled special
(in the sort code and in more places). By adding a new "TypeSnapd"
snap type this becomes more uniform.
The current approach is to assign the type when reading the
snap.yaml. This is mostly to make the transition easier for
people who have snapd installed already but the snapd does
not have the right type yet. We could omit it given that we
have no real core18 systems in the wild yet and that snapd
is not installable yet on classic/core16 systems.
Based on #5702