diff --git a/internal/controller/api_vms.go b/internal/controller/api_vms.go index 5a81f47..645046b 100644 --- a/internal/controller/api_vms.go +++ b/internal/controller/api_vms.go @@ -132,6 +132,7 @@ func (controller *Controller) updateVM(ctx *gin.Context) responder.Responder { dbVM.Status = userVM.Status dbVM.StatusMessage = userVM.StatusMessage + dbVM.ImageFQN = userVM.ImageFQN if err := txn.SetVM(*dbVM); err != nil { controller.logger.Errorf("failed to update VM in the DB: %v", err) diff --git a/internal/worker/vmmanager/vm.go b/internal/worker/vmmanager/vm.go index 23cae13..6bc6d79 100644 --- a/internal/worker/vmmanager/vm.go +++ b/internal/worker/vmmanager/vm.go @@ -39,6 +39,9 @@ type VM struct { // "tart run" terminations more correctly stopping atomic.Bool + // Image FQN feature, see https://github.com/cirruslabs/orchard/issues/164 + imageFQN atomic.Pointer[string] + err atomic.Pointer[error] ctx context.Context @@ -147,6 +150,10 @@ func (vm *VM) Started() bool { return vm.started.Load() } +func (vm *VM) ImageFQN() *string { + return vm.imageFQN.Load() +} + func (vm *VM) id() string { return vm.onDiskName.String() } @@ -171,6 +178,13 @@ func (vm *VM) cloneAndConfigure(ctx context.Context) error { return err } + // Image FQN feature, see https://github.com/cirruslabs/orchard/issues/164 + fqnRaw, _, err := tart.Tart(ctx, vm.logger, "fqn", vm.Resource.Image) + if err == nil { + fqn := strings.TrimSpace(fqnRaw) + vm.imageFQN.Store(&fqn) + } + if vm.Resource.Memory != 0 { _, _, err = tart.Tart(ctx, vm.logger, "set", "--memory", strconv.FormatUint(vm.Resource.Memory, 10), vm.id()) diff --git a/internal/worker/worker.go b/internal/worker/worker.go index 52188c6..314c509 100644 --- a/internal/worker/worker.go +++ b/internal/worker/worker.go @@ -185,7 +185,7 @@ func (worker *Worker) updateWorker(ctx context.Context) error { return nil } -//nolint:nestif // nested "if" complexity is tolerable for now +//nolint:nestif,gocognit // nested "if" and cognitive complexity is tolerable for now func (worker *Worker) syncVMs(ctx context.Context) error { remoteVMs, err := worker.client.VMs().FindForWorker(ctx, worker.name) if err != nil { @@ -245,6 +245,12 @@ func (worker *Worker) syncVMs(ctx context.Context) error { // check if the local VM had already started // and update the remote VM as accordingly if vm.Started() { + // Image FQN feature, see https://github.com/cirruslabs/orchard/issues/164 + if imageFQN := vm.ImageFQN(); imageFQN != nil { + vmResource.ImageFQN = *imageFQN + } + + // Mark the remote VM as started vmResource.Status = v1.VMStatusRunning if _, err := worker.client.VMs().Update(ctx, vmResource); err != nil { return err diff --git a/pkg/resource/v1/v1.go b/pkg/resource/v1/v1.go index 32b070c..7d941ad 100644 --- a/pkg/resource/v1/v1.go +++ b/pkg/resource/v1/v1.go @@ -53,6 +53,10 @@ type VM struct { // HostDir is a list of host directories to be mounted to the VM. HostDirs []HostDir `json:"hostDirs"` + // ImageFQN is a fully qualified name of the Image that it is populated + // by the worker using "tart fqn" command after it had pulled the image. + ImageFQN string `json:"image_fqn"` + Meta }