Simplify state reconciliation and support changing Softnet settings (#364)

* Simplify state reconciliation and support changing Softnet settings

* Remove unused "updateFunc" parameter from syncOnDiskVMs()

* Don't take an address of a loop variable

* ensure → ensures

* updateVMState(): don't forget to update VMState

* Introduce TestSpecUpdateSoftnet integration test

* Update OpenAPI specification to include generation/observedGeneration
This commit is contained in:
Nikolay Edigaryev
2025-11-06 20:56:31 +04:00
committed by GitHub
parent 00d27d1fa0
commit bafcf6fac2
16 changed files with 690 additions and 166 deletions
+37
View File
@@ -0,0 +1,37 @@
package worker
import (
"testing"
"github.com/cirruslabs/orchard/internal/worker/ondiskname"
"github.com/cirruslabs/orchard/internal/worker/vmmanager"
v1 "github.com/cirruslabs/orchard/pkg/resource/v1"
"github.com/samber/lo"
"github.com/stretchr/testify/require"
)
func TestSortNonExistentAndFailedFirst(t *testing.T) {
newVMTuple := func(name string, vmResource *v1.VM) lo.Tuple3[ondiskname.OnDiskName, *v1.VM, *vmmanager.VM] {
return lo.T3(ondiskname.New(name, name, 0), vmResource, &vmmanager.VM{})
}
target := []lo.Tuple3[ondiskname.OnDiskName, *v1.VM, *vmmanager.VM]{
newVMTuple("test1", &v1.VM{Status: v1.VMStatusFailed}),
newVMTuple("test2", &v1.VM{Status: v1.VMStatusPending}),
newVMTuple("test3", &v1.VM{Status: v1.VMStatusRunning}),
newVMTuple("test5", nil),
newVMTuple("test4", &v1.VM{Status: v1.VMStatusFailed}),
}
sortNonExistentAndFailedFirst(target)
expected := []lo.Tuple3[ondiskname.OnDiskName, *v1.VM, *vmmanager.VM]{
newVMTuple("test5", nil),
newVMTuple("test1", &v1.VM{Status: v1.VMStatusFailed}),
newVMTuple("test4", &v1.VM{Status: v1.VMStatusFailed}),
newVMTuple("test2", &v1.VM{Status: v1.VMStatusPending}),
newVMTuple("test3", &v1.VM{Status: v1.VMStatusRunning}),
}
require.Equal(t, expected, target)
}