vagrant icon indicating copy to clipboard operation
vagrant copied to clipboard

Update vagrant-go data layer

Open chrisroberts opened this issue 3 years ago • 1 comments

Update the vagrant-go data layer to move off boltdb for data storage and replace with sqlite backed gorm implementation.

Source issue: #12903

chrisroberts avatar Sep 19 '22 15:09 chrisroberts

Found a little bug with running global-status when multiple projects have running machines. Given two Vagrant projects

in ~/project/vagrant

Vagrant.configure("2") do |config|
  config.vm.define "one" do |c|
    c.vm.box = "hashicorp/bionic64"
    c.vm.synced_folder ".", "vagrant", disabled: true
  end
end

in ~/project/two

Vagrant.configure("2") do |config|
  config.vm.define "two" do |c|
    c.vm.box = "hashicorp/bionic64"
    c.vm.synced_folder ".", "vagrant", disabled: true
  end
end
$ export VAGRANT_CWD=~/project/vagrant

$ vagrant up 
.... // machine (one) comes up successfully 

$ vagrant global-status
id         name      provider     state     directory                             
  ------------------------------------------------------------------------
  fe45b01    default   virtualbox   running   /Users/sophia/project/vagrant 

$ export VAGRANT_CWD=~/project/two

$ vagrant up 
.... // machine (two) comes up successfully 

$ vagrant global-status                       
! Running of task global-status failed unexpectedly
! Error: rpc error: code = FailedPrecondition desc = cannot save project (proto reference does not include parent)

Looks like this is caused by the factory creating new targets does not fully load the target (so there is a hanging project without it's basis. A fix is:

diff --git a/internal/core/factory.go b/internal/core/factory.go
index 1163317c1..b32449d87 100644
--- a/internal/core/factory.go
+++ b/internal/core/factory.go
@@ -217,13 +217,8 @@ func (f *Factory) NewTarget(topts ...TargetOption) (*Target, error) {
                t.factory = f
        }
 
-       // If the resource id isn't set, attempt a reload. We
-       // don't care if it fails, at this point. If it is
-       // successful, it will allow us to properly check
-       // the cache
-       if t.target.ResourceId == "" {
-               _ = t.Reload()
-       }
+       // Ensure the most up to date target is available
+       _ = t.Reload()
 
        // Check if we already have an instance loaded
        if t.target.ResourceId != "" {
diff --git a/internal/server/singleprocess/state/target.go b/internal/server/singleprocess/state/target.go
index 2fda76cf8..f2dc22437 100644

soapy1 avatar Oct 05 '22 16:10 soapy1