Skip to content

Commit f152448

Browse files
committed
Add "NoVM" state
Signed-off-by: Yevhen Vydolob <[email protected]>
1 parent 484a0e6 commit f152448

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

cmd/crc/cmd/status.go

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/crc-org/crc/v2/pkg/crc/constants"
1414
"github.com/crc-org/crc/v2/pkg/crc/daemonclient"
1515
crcErrors "github.com/crc-org/crc/v2/pkg/crc/errors"
16+
"github.com/crc-org/crc/v2/pkg/crc/machine/state"
1617
"github.com/crc-org/crc/v2/pkg/crc/machine/types"
1718
"github.com/crc-org/crc/v2/pkg/crc/preset"
1819
"github.com/docker/go-units"
@@ -146,6 +147,9 @@ func getStatus(client *daemonclient.Client, cacheDir string) *status {
146147
}
147148
return &status{Success: false, Error: crcErrors.ToSerializableError(err)}
148149
}
150+
if clusterStatus.CrcStatus == string(state.Novm) {
151+
return &status{Success: false, Error: crcErrors.ToSerializableError(crcErrors.VMNotExist)}
152+
}
149153
var size int64
150154
err = filepath.Walk(cacheDir, func(_ string, info os.FileInfo, err error) error {
151155
if !info.IsDir() {

pkg/crc/api/handlers.go

-8
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ func NewHandler(config *crcConfig.Config, machine machine.Client, logger Logger,
5050
}
5151

5252
func (h *Handler) Status(c *context) error {
53-
exists, err := h.Client.Exists()
54-
if err != nil {
55-
return err
56-
}
57-
if !exists {
58-
return c.String(http.StatusInternalServerError, string(errors.VMNotExist))
59-
}
60-
6153
res, err := h.Client.Status()
6254
if err != nil {
6355
return err

pkg/crc/machine/state/state.go

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const (
1010
Stopped State = "Stopped"
1111
Stopping State = "Stopping"
1212
Starting State = "Starting"
13+
Novm State = "NoVM"
1314
Error State = "Error"
1415
)
1516

pkg/crc/machine/status.go

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ import (
1414
)
1515

1616
func (client *client) Status() (*types.ClusterStatusResult, error) {
17+
exists, err := client.Exists()
18+
if err != nil {
19+
return nil, err
20+
}
21+
if !exists {
22+
return &types.ClusterStatusResult{
23+
CrcStatus: state.Novm,
24+
}, nil
25+
}
26+
1727
vm, err := loadVirtualMachine(client.name, client.useVSock())
1828
if err != nil {
1929
if errors.Is(err, errMissingHost(client.name)) {

0 commit comments

Comments
 (0)