Skip to content

Commit

Permalink
Add "NoVM" state
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <[email protected]>
  • Loading branch information
evidolob committed Nov 1, 2023
1 parent 484a0e6 commit f152448
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions cmd/crc/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand Down
8 changes: 0 additions & 8 deletions pkg/crc/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/machine/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
Stopped State = "Stopped"
Stopping State = "Stopping"
Starting State = "Starting"
Novm State = "NoVM"
Error State = "Error"
)

Expand Down
10 changes: 10 additions & 0 deletions pkg/crc/machine/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit f152448

Please sign in to comment.