Controller: emit lifecycle events when the VM gets restarted or deleted (#208)

* Controller: emit lifecycle events when the VM gets restarted or deleted

* vm_{scheduling,run}_time → vm_{scheduling,run}_duration for clarity

* Update VM endpoint: only update VM started time when zero
This commit is contained in:
Nikolay Edigaryev
2024-09-24 17:53:10 +04:00
committed by GitHub
parent 1730eaf67c
commit 2a2ddea62a
4 changed files with 50 additions and 0 deletions
+7
View File
@@ -2,6 +2,7 @@ package controller
import (
"errors"
"github.com/cirruslabs/orchard/internal/controller/lifecycle"
storepkg "github.com/cirruslabs/orchard/internal/controller/store"
"github.com/cirruslabs/orchard/internal/responder"
"github.com/cirruslabs/orchard/internal/simplename"
@@ -130,6 +131,10 @@ func (controller *Controller) updateVM(ctx *gin.Context) responder.Responder {
NewErrorResponse("cannot update status for a VM in a terminal state"))
}
if userVM.Status == v1.VMStatusRunning && dbVM.StartedAt.IsZero() {
dbVM.StartedAt = time.Now()
}
dbVM.Status = userVM.Status
dbVM.StatusMessage = userVM.StatusMessage
dbVM.ImageFQN = userVM.ImageFQN
@@ -197,6 +202,8 @@ func (controller *Controller) deleteVM(ctx *gin.Context) responder.Responder {
return responder.Error(err)
}
lifecycle.Report(vm, "VM deleted", controller.logger)
return responder.Code(http.StatusOK)
})
}