From c239fd897329c0db91593cd413f06aa8cb2c8683 Mon Sep 17 00:00:00 2001 From: joshsiv-mulga Date: Wed, 30 Sep 2026 15:26:40 +1000 Subject: [PATCH] refactor: colocate ENI allocation with VM runtime --- spinifex/daemon/daemon_handlers_eni_test.go | 5 ++--- spinifex/runtime/compute/vm/eni_hotplug_test.go | 3 +-- spinifex/runtime/compute/vm/eni_reconcile_test.go | 3 +-- .../{types/eni.go => runtime/compute/vm/eni_requests.go} | 2 +- spinifex/runtime/compute/vm/vm.go | 2 +- 5 files changed, 6 insertions(+), 9 deletions(-) rename spinifex/{types/eni.go => runtime/compute/vm/eni_requests.go} (97%) diff --git a/spinifex/daemon/daemon_handlers_eni_test.go b/spinifex/daemon/daemon_handlers_eni_test.go index 66cb5c495..3492e5e80 100644 --- a/spinifex/daemon/daemon_handlers_eni_test.go +++ b/spinifex/daemon/daemon_handlers_eni_test.go @@ -15,7 +15,6 @@ import ( handlers_ec2_vpc "github.com/mulgadc/spinifex/spinifex/handlers/ec2/vpc" "github.com/mulgadc/spinifex/spinifex/runtime/compute/qmp" "github.com/mulgadc/spinifex/spinifex/runtime/compute/vm" - spxtypes "github.com/mulgadc/spinifex/spinifex/types" "github.com/mulgadc/spinifex/spinifex/utils" "github.com/nats-io/nats.go" "github.com/stretchr/testify/assert" @@ -118,7 +117,7 @@ func newENIHotPlugFixture(t *testing.T) *eniHotPlugFixture { ID: "i-hp-test", Status: vm.StateRunning, QMPClient: &qmp.QMPClient{}, - ENIRequests: spxtypes.ENIRequests{ + ENIRequests: vm.ENIRequests{ AvailableSlots: []int{1, 2, 3, 4}, AttachedByENIID: map[string]int{}, }, @@ -352,7 +351,7 @@ func TestHandleDetachNetworkInterface_WrongOwner(t *testing.T) { otherVM := &vm.VM{ ID: "i-other", Status: vm.StateRunning, - ENIRequests: spxtypes.ENIRequests{ + ENIRequests: vm.ENIRequests{ AvailableSlots: []int{1}, AttachedByENIID: map[string]int{}, }, diff --git a/spinifex/runtime/compute/vm/eni_hotplug_test.go b/spinifex/runtime/compute/vm/eni_hotplug_test.go index 85926c4ce..68f94aa9f 100644 --- a/spinifex/runtime/compute/vm/eni_hotplug_test.go +++ b/spinifex/runtime/compute/vm/eni_hotplug_test.go @@ -11,7 +11,6 @@ import ( "time" "github.com/mulgadc/spinifex/spinifex/runtime/compute/qmp" - "github.com/mulgadc/spinifex/spinifex/types" ) // newHotPlugTestVM returns a VM in StateRunning with a non-nil QMPClient @@ -39,7 +38,7 @@ func newHotPlugTestVMWithPlumber(t *testing.T, slots int) (*Manager, *VM, *StubD ID: "i-test", Status: StateRunning, QMPClient: &qmp.QMPClient{}, - ENIRequests: types.ENIRequests{ + ENIRequests: ENIRequests{ AvailableSlots: available, AttachedByENIID: make(map[string]int), }, diff --git a/spinifex/runtime/compute/vm/eni_reconcile_test.go b/spinifex/runtime/compute/vm/eni_reconcile_test.go index b32149b9a..557181672 100644 --- a/spinifex/runtime/compute/vm/eni_reconcile_test.go +++ b/spinifex/runtime/compute/vm/eni_reconcile_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/mulgadc/spinifex/spinifex/runtime/compute/qmp" - "github.com/mulgadc/spinifex/spinifex/types" ) func TestENISlotFromDeviceID(t *testing.T) { @@ -67,7 +66,7 @@ func TestAdoptENISlot(t *testing.T) { } func TestAdoptENISlot_NilMap(t *testing.T) { - v := &VM{ENIRequests: types.ENIRequests{AvailableSlots: []int{1}}} + v := &VM{ENIRequests: ENIRequests{AvailableSlots: []int{1}}} m := &Manager{} m.AdoptENISlot(v, "eni-a", 1) if got := v.ENIRequests.AttachedByENIID["eni-a"]; got != 1 { diff --git a/spinifex/types/eni.go b/spinifex/runtime/compute/vm/eni_requests.go similarity index 97% rename from spinifex/types/eni.go rename to spinifex/runtime/compute/vm/eni_requests.go index 78ab97b30..23c681941 100644 --- a/spinifex/types/eni.go +++ b/spinifex/runtime/compute/vm/eni_requests.go @@ -1,4 +1,4 @@ -package types +package vm import "sync" diff --git a/spinifex/runtime/compute/vm/vm.go b/spinifex/runtime/compute/vm/vm.go index c851abe7e..ae3a0ae71 100644 --- a/spinifex/runtime/compute/vm/vm.go +++ b/spinifex/runtime/compute/vm/vm.go @@ -88,7 +88,7 @@ type VM struct { Config Config `json:"config"` EBSRequests types.EBSRequests `json:"ebs_requests"` - ENIRequests types.ENIRequests `json:"eni_requests"` + ENIRequests ENIRequests `json:"eni_requests"` QMPClient *qmp.QMPClient `json:"-"`