Skip to content

Commit

Permalink
overlord: add implicit slots to just snapd, if installed on startup
Browse files Browse the repository at this point in the history
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
  • Loading branch information
zyga committed Jul 6, 2018
1 parent ca53976 commit 09bf3fb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
9 changes: 9 additions & 0 deletions overlord/ifacestate/helpers.go
Expand Up @@ -104,6 +104,15 @@ func (m *InterfaceManager) addSnaps() error {
if err != nil {
return err
}
// Before adding any snap scan the set of snaps we know about. If any of
// those is snapd then for the duration of this process always add
// implicit slots to snapd and not to any other type: os snap.
for _, snapInfo := range snaps {
if snapInfo.SnapName() == "snapd" {
implicitSlotsOnSnapd = true
break
}
}
for _, snapInfo := range snaps {
addImplicitSlots(snapInfo)
if err := m.repo.AddSnap(snapInfo); err != nil {
Expand Down
25 changes: 23 additions & 2 deletions overlord/ifacestate/implicit.go
Expand Up @@ -26,17 +26,38 @@ import (
"github.com/snapcore/snapd/snap"
)

// Flag indicating if implicit slots should be added to "snapd" snap. This
// is here because the interface manager is the only entity adding such
// slots and must ensure that: ubuntu-core -> core transition can run as
// before (both snaps have the implicit slots but that case is handled
// directly) and so that once "snapd" snap is installed only one snap in
// the system will hold implicit interfaces.
//
// This is set on startup of the interface manager, based on the presence
// of "snapd" snap in the state.
var implicitSlotsOnSnapd bool

// addImplicitSlots adds implicitly defined slots to a given snap.
//
// Only the OS snap has implicit slots.
//
// It is assumed that slots have names matching the interface name. Existing
// slots are not changed, only missing slots are added.
func addImplicitSlots(snapInfo *snap.Info) {
if snapInfo.Type != snap.TypeOS {
// Implicit slots can be added to the special "snapd" snap or to snaps with
// type "os". Currently there are no other snaps that gain implicit
// interfaces.
if snapInfo.Type != snap.TypeOS && snapInfo.InstanceName() != "snapd" {
return
}

// If the manager has chosen to put implicit slots on the "snapd" snap
// then stop adding them to any other core snaps.
if implicitSlotsOnSnapd && snapInfo.InstanceName() != "snapd" {
return
}
// Ask each interface if it wants to be implcitly added.

// Ask each interface if it wants to be implicitly added.
for _, iface := range builtin.Interfaces() {
si := interfaces.StaticInfoOf(iface)
if (release.OnClassic && si.ImplicitOnClassic) || (!release.OnClassic && si.ImplicitOnCore) {
Expand Down

0 comments on commit 09bf3fb

Please sign in to comment.