Create cache in manager and set into plugin if available

This commit is contained in:
Chris Roberts 2021-10-15 14:34:09 -07:00 committed by Paul Hinze
parent e6952621d3
commit 891541cd40
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 14 additions and 1 deletions

View File

@ -13,10 +13,11 @@ import (
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/vagrant/internal/serverclient"
"github.com/hashicorp/vagrant-plugin-sdk/component"
"github.com/hashicorp/vagrant-plugin-sdk/helper/path"
"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/cacher"
"github.com/hashicorp/vagrant/internal/serverclient"
)
type PluginRegistration func(hclog.Logger) (*Plugin, error)
@ -33,6 +34,7 @@ type Manager struct {
logger hclog.Logger
m sync.Mutex
parent *Manager
cache cacher.Cache
}
// Create a new plugin manager
@ -42,6 +44,7 @@ func NewManager(ctx context.Context, l hclog.Logger) *Manager {
builtins: NewBuiltins(ctx, l),
ctx: ctx,
logger: l,
cache: cacher.New(),
}
}
@ -58,6 +61,7 @@ func (m *Manager) Sub(name string) *Manager {
legacyLoaded: true,
logger: m.logger.Named(name),
parent: m,
cache: m.cache,
}
m.closer(func() error { return s.Close() })
@ -336,6 +340,7 @@ func (m *Manager) register(
if err != nil {
return
}
plg.Cache = m.cache
for _, t := range plg.Types {
m.logger.Info("registering plugin",

View File

@ -11,6 +11,7 @@ import (
sdk "github.com/hashicorp/vagrant-plugin-sdk"
"github.com/hashicorp/vagrant-plugin-sdk/component"
"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/cacher"
"github.com/hashicorp/vagrant/builtin/myplugin"
"github.com/hashicorp/vagrant/builtin/otherplugin"
)
@ -38,6 +39,7 @@ type Plugin struct {
Location string // Location of the plugin (generally path to binary)
Name string // Name of the plugin
Types []component.Type // Component types supported by this plugin
Cache cacher.Cache
closers []func() error
components map[component.Type]*Instance
@ -144,6 +146,12 @@ func (p *Plugin) InstanceOf(
return nil, fmt.Errorf("unable to extract broker from plugin client")
}
if c, ok := raw.(interface {
SetCache(cacher.Cache)
}); ok {
c.SetCache(p.Cache)
}
i = &Instance{
Component: raw,
Broker: b.GRPCBroker(),