From f1524486fb0c51f0da22109c3ebd2289f196c780 Mon Sep 17 00:00:00 2001 From: Yevhen Vydolob Date: Wed, 1 Nov 2023 09:48:11 +0200 Subject: [PATCH] Add "NoVM" state Signed-off-by: Yevhen Vydolob --- cmd/crc/cmd/status.go | 4 ++++ pkg/crc/api/handlers.go | 8 -------- pkg/crc/machine/state/state.go | 1 + pkg/crc/machine/status.go | 10 ++++++++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cmd/crc/cmd/status.go b/cmd/crc/cmd/status.go index 90d6d8a5a8..2b65aa71ca 100644 --- a/cmd/crc/cmd/status.go +++ b/cmd/crc/cmd/status.go @@ -13,6 +13,7 @@ import ( "github.com/crc-org/crc/v2/pkg/crc/constants" "github.com/crc-org/crc/v2/pkg/crc/daemonclient" crcErrors "github.com/crc-org/crc/v2/pkg/crc/errors" + "github.com/crc-org/crc/v2/pkg/crc/machine/state" "github.com/crc-org/crc/v2/pkg/crc/machine/types" "github.com/crc-org/crc/v2/pkg/crc/preset" "github.com/docker/go-units" @@ -146,6 +147,9 @@ func getStatus(client *daemonclient.Client, cacheDir string) *status { } return &status{Success: false, Error: crcErrors.ToSerializableError(err)} } + if clusterStatus.CrcStatus == string(state.Novm) { + return &status{Success: false, Error: crcErrors.ToSerializableError(crcErrors.VMNotExist)} + } var size int64 err = filepath.Walk(cacheDir, func(_ string, info os.FileInfo, err error) error { if !info.IsDir() { diff --git a/pkg/crc/api/handlers.go b/pkg/crc/api/handlers.go index 0ac9fd4ece..42a5d188b4 100644 --- a/pkg/crc/api/handlers.go +++ b/pkg/crc/api/handlers.go @@ -50,14 +50,6 @@ func NewHandler(config *crcConfig.Config, machine machine.Client, logger Logger, } func (h *Handler) Status(c *context) error { - exists, err := h.Client.Exists() - if err != nil { - return err - } - if !exists { - return c.String(http.StatusInternalServerError, string(errors.VMNotExist)) - } - res, err := h.Client.Status() if err != nil { return err diff --git a/pkg/crc/machine/state/state.go b/pkg/crc/machine/state/state.go index 60bdfc2707..ca9b2940a3 100644 --- a/pkg/crc/machine/state/state.go +++ b/pkg/crc/machine/state/state.go @@ -10,6 +10,7 @@ const ( Stopped State = "Stopped" Stopping State = "Stopping" Starting State = "Starting" + Novm State = "NoVM" Error State = "Error" ) diff --git a/pkg/crc/machine/status.go b/pkg/crc/machine/status.go index 3f5bc9cb9a..f3218deafe 100644 --- a/pkg/crc/machine/status.go +++ b/pkg/crc/machine/status.go @@ -14,6 +14,16 @@ import ( ) func (client *client) Status() (*types.ClusterStatusResult, error) { + exists, err := client.Exists() + if err != nil { + return nil, err + } + if !exists { + return &types.ClusterStatusResult{ + CrcStatus: state.Novm, + }, nil + } + vm, err := loadVirtualMachine(client.name, client.useVSock()) if err != nil { if errors.Is(err, errMissingHost(client.name)) {