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

snap: add new type "TypeSnapd" and attach to the snapd snap #5704

Merged
merged 7 commits into from Aug 28, 2018

Conversation

mvo5
Copy link
Contributor

@mvo5 mvo5 commented Aug 22, 2018

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

@mvo5 mvo5 added the Core18 label Aug 22, 2018
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.
Copy link
Collaborator

@zyga zyga left a 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]
Copy link
Collaborator

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{
Copy link
Collaborator

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]
Copy link
Collaborator

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()

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

Choose a reason for hiding this comment

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

Ha, very nice :)

@zyga
Copy link
Collaborator

zyga commented Aug 22, 2018

This failed on something weird:

+ echo 'Wait for firstboot change to be ready'
Wait for firstboot change to be ready
+ grep Done
+ snap changes
/home/gopath/src/github.com/snapcore/snapd/tests/lib/prepare.sh: line 586: snap: command not found
+ snap changes
/home/gopath/src/github.com/snapcore/snapd/tests/lib/prepare.sh: line 587: snap: command not found
+ true

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
Copy link
Collaborator

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-io
Copy link

codecov-io commented Aug 23, 2018

Codecov Report

Merging #5704 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
snap/info.go 84.51% <100%> (-0.17%) ⬇️
snap/types.go 83.33% <100%> (+0.98%) ⬆️
snap/info_snap_yaml.go 93.37% <100%> (+0.04%) ⬆️
overlord/ifacestate/handlers.go 63.89% <0%> (+0.31%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 368b957...3de0c7d. Read the comment docs.

snap/info.go Outdated
return false
}
return typeOrder[r[i].Type] < typeOrder[r[j].Type]
return r[i].Type.sortOrder() < r[j].Type.sortOrder()
Copy link
Collaborator

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)
}

Copy link
Collaborator

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

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

LGTM

@mvo5 mvo5 merged commit 0ac4993 into snapcore:master Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants