mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-18 22:48:57 +02:00
Implement restart policy for VMs (#83)
* Implement restart policy for VMs * Do not update VM.Resource, we only use it as a read-only specification * Err()/setErr(): use atomic.Pointer instead of sync.Mutex
This commit is contained in:
@@ -37,6 +37,8 @@ func (controller *Controller) createVM(ctx *gin.Context) responder.Responder {
|
||||
|
||||
vm.Status = v1.VMStatusPending
|
||||
vm.CreatedAt = time.Now()
|
||||
vm.RestartedAt = time.Time{}
|
||||
vm.RestartCount = 0
|
||||
vm.UID = uuid.New().String()
|
||||
|
||||
// Provide resource defaults
|
||||
@@ -47,6 +49,16 @@ func (controller *Controller) createVM(ctx *gin.Context) responder.Responder {
|
||||
vm.Resources[v1.ResourceTartVMs] = 1
|
||||
}
|
||||
|
||||
// Validate restart policy and provide a default value if it's missing
|
||||
if vm.RestartPolicy != "" {
|
||||
if _, err := v1.NewRestartPolicyFromString(string(vm.RestartPolicy)); err != nil {
|
||||
return responder.JSON(http.StatusPreconditionFailed,
|
||||
NewErrorResponse("unsupported restart policy: %q", vm.RestartPolicy))
|
||||
}
|
||||
} else {
|
||||
vm.RestartPolicy = v1.RestartPolicyNever
|
||||
}
|
||||
|
||||
response := controller.storeUpdate(func(txn storepkg.Transaction) responder.Responder {
|
||||
// Does the VM resource with this name already exists?
|
||||
_, err := txn.GetVM(vm.Name)
|
||||
|
||||
Reference in New Issue
Block a user