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

Vagrant legacy plugin uninstall #12920

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
13 changes: 11 additions & 2 deletions internal/client/basis.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/hashicorp/vagrant-plugin-sdk/config"
"github.com/hashicorp/vagrant-plugin-sdk/helper/path"
"github.com/hashicorp/vagrant-plugin-sdk/helper/paths"
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
Expand Down Expand Up @@ -44,9 +45,14 @@ func (b *Basis) DetectProject() (p *Project, err error) {
if err != nil && status.Code(err) != codes.NotFound {
return
}
dataPath, err := paths.VagrantData()
if err != nil {
return
}

if err == nil {
p.vagrantfile = v
b.client.LoadLocalProjectPlugins(dataPath.Join(b.basis.Name, "project", p.project.Name).String())
return
}

Expand All @@ -64,7 +70,7 @@ func (b *Basis) DetectProject() (p *Project, err error) {
return
}

return &Project{
projectClient := &Project{
basis: b,
client: b.client,
ctx: b.ctx,
Expand All @@ -73,7 +79,10 @@ func (b *Basis) DetectProject() (p *Project, err error) {
ui: b.ui,
vagrant: b.vagrant,
vagrantfile: v,
}, nil
}
b.client.LoadLocalProjectPlugins(dataPath.Join(b.basis.Name, "project", projectClient.project.Name).String())

return projectClient, nil
}

func (b *Basis) LoadProject(n string) (*Project, error) {
Expand Down
4 changes: 4 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ func (c *Client) UI() terminal.UI {
return c.ui
}

func (c *Client) LoadLocalProjectPlugins(path string) error {
return c.runner.LoadLocalProjectPlugins(path)
}

type clientConfig struct {
connectOpts []serverclient.ConnectOption
}
Expand Down
38 changes: 36 additions & 2 deletions internal/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/cacher"
"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/cleanup"
"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/protomappers"
"github.com/hashicorp/vagrant/internal/server/proto/ruby_vagrant"
"github.com/hashicorp/vagrant/internal/serverclient"
)

Expand Down Expand Up @@ -137,7 +138,32 @@ func (m *Manager) LegacyEnabled() bool {

// Load legacy Ruby based Vagrant plugins using a
// running Vagrant runtime
func (m *Manager) LoadLegacyPlugins(
func (m *Manager) LoadLocalLegacyPlugins(
c *serverclient.RubyVagrantClient, // Client connection to the Legacy Ruby Vagrant server
r plugin.ClientProtocol, // go-plugin client connection to Ruby plugin server
path string, // project plugin path
) (err error) {
m.m.Lock()
defer m.m.Unlock()

m.logger.Trace("loading ruby based legacy vagrant plugins")

plugins, err := c.GetLocalPlugins(path)
if err != nil {
m.logger.Trace("failed to fetch ruby based legacy vagrant plugin information",
"error", err,
)

return
}

err = m.RegisterLegacyPlugins(c, r, plugins)
return
}

// Load legacy Ruby based Vagrant plugins using a
// running Vagrant runtime
func (m *Manager) LoadGlobalLegacyPlugins(
c *serverclient.RubyVagrantClient, // Client connection to the Legacy Ruby Vagrant server
r plugin.ClientProtocol, // go-plugin client connection to Ruby plugin server
) (err error) {
Expand All @@ -151,15 +177,23 @@ func (m *Manager) LoadLegacyPlugins(

m.logger.Trace("loading ruby based legacy vagrant plugins")

plugins, err := c.GetPlugins()
plugins, err := c.GetGlobalPlugins()
if err != nil {
m.logger.Trace("failed to fetch ruby based legacy vagrant plugin information",
"error", err,
)

return
}
err = m.RegisterLegacyPlugins(c, r, plugins)
return
}

func (m *Manager) RegisterLegacyPlugins(
c *serverclient.RubyVagrantClient,
r plugin.ClientProtocol,
plugins []*ruby_vagrant.Plugin,
) (err error) {
for _, p := range plugins {
m.logger.Info("loading ruby based legacy vagrant plugin",
"name", p.Name,
Expand Down
9 changes: 8 additions & 1 deletion internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func New(opts ...Option) (*Runner, error) {
return nil, err
}

if err := runner.plugins.LoadLegacyPlugins(
if err := runner.plugins.LoadGlobalLegacyPlugins(
runner.vagrantRubyClient, runner.vagrantRubyRuntime); err != nil {
return nil, err
}
Expand Down Expand Up @@ -156,6 +156,13 @@ func New(opts ...Option) (*Runner, error) {
return runner, nil
}

func (r *Runner) LoadLocalProjectPlugins(path string) error {
// TODO: should this check if the runner is local?
err := r.plugins.LoadLocalLegacyPlugins(
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'm not too sure about this approach. If the runner is local then it should be able to load local project plugins. Not sure how to resolve the situation where the runner is remote?

r.vagrantRubyClient, r.vagrantRubyRuntime, path)
return err
}

// Id returns the runner ID.
func (r *Runner) Id() string {
return r.id
Expand Down
121 changes: 64 additions & 57 deletions internal/server/proto/ruby_vagrant/ruby-server.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion internal/server/proto/ruby_vagrant/ruby-server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import "plugin.proto";
// The service that is implemented for the server backend.
service RubyVagrant {
// Gets available ruby plugins
rpc GetPlugins(GetPluginsRequest) returns (GetPluginsResponse);
rpc GetLocalPlugins(GetPluginsRequest) returns (GetPluginsResponse);
rpc GetGlobalPlugins(google.protobuf.Empty) returns (GetPluginsResponse);
rpc ParseVagrantfile(ParseVagrantfileRequest) returns (ParseVagrantfileResponse);
rpc ParseVagrantfileProc(ParseVagrantfileProcRequest) returns (ParseVagrantfileResponse);
rpc ParseVagrantfileSubvm(ParseVagrantfileSubvmRequest) returns (ParseVagrantfileResponse);
Expand Down
Loading