mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-21 10:45:25 +02:00
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:
@@ -0,0 +1,58 @@
|
||||
package worker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
v1 "github.com/cirruslabs/orchard/pkg/resource/v1"
|
||||
"github.com/samber/mo"
|
||||
)
|
||||
|
||||
type Action string
|
||||
|
||||
const (
|
||||
ActionIgnore Action = "ignore"
|
||||
ActionCreate Action = "create"
|
||||
ActionMonitorPending Action = "monitor-pending"
|
||||
ActionReportRunning Action = "report-running"
|
||||
ActionMonitorRunning Action = "monitor-running"
|
||||
ActionStop Action = "stop"
|
||||
ActionFail Action = "fail"
|
||||
ActionLostTrack Action = "lost-track"
|
||||
ActionImpossible Action = "impossible"
|
||||
ActionDelete Action = "delete"
|
||||
)
|
||||
|
||||
var transitions = map[mo.Option[v1.VMStatus]]map[mo.Option[v1.VMStatus]]Action{
|
||||
mo.None[v1.VMStatus](): {
|
||||
mo.None[v1.VMStatus](): ActionIgnore,
|
||||
mo.Some(v1.VMStatusPending): ActionDelete,
|
||||
mo.Some(v1.VMStatusRunning): ActionDelete,
|
||||
mo.Some(v1.VMStatusFailed): ActionDelete,
|
||||
},
|
||||
mo.Some(v1.VMStatusPending): {
|
||||
mo.None[v1.VMStatus](): ActionCreate,
|
||||
mo.Some(v1.VMStatusPending): ActionMonitorPending,
|
||||
mo.Some(v1.VMStatusRunning): ActionReportRunning,
|
||||
mo.Some(v1.VMStatusFailed): ActionFail,
|
||||
},
|
||||
mo.Some(v1.VMStatusRunning): {
|
||||
mo.None[v1.VMStatus](): ActionLostTrack,
|
||||
mo.Some(v1.VMStatusPending): ActionImpossible,
|
||||
mo.Some(v1.VMStatusRunning): ActionMonitorRunning,
|
||||
mo.Some(v1.VMStatusFailed): ActionFail,
|
||||
},
|
||||
mo.Some(v1.VMStatusFailed): {
|
||||
mo.None[v1.VMStatus](): ActionIgnore,
|
||||
mo.Some(v1.VMStatusPending): ActionStop,
|
||||
mo.Some(v1.VMStatusRunning): ActionStop,
|
||||
mo.Some(v1.VMStatusFailed): ActionIgnore,
|
||||
},
|
||||
}
|
||||
|
||||
func optionToString[T any](option mo.Option[T]) string {
|
||||
if option.IsNone() {
|
||||
return "None"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("Some(%v)", option.MustGet())
|
||||
}
|
||||
Reference in New Issue
Block a user