Skip to content

Commit

Permalink
Add "NoVM" state
Browse files Browse the repository at this point in the history
This would simplify podman-desktop ext status handling

Signed-off-by: Yevhen Vydolob <[email protected]>
  • Loading branch information
evidolob committed Feb 1, 2024
1 parent 0b8ec64 commit 6d61cbf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 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 @@ -152,6 +153,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
3 changes: 1 addition & 2 deletions pkg/crc/machine/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ func (client *client) Status() (*types.ClusterStatusResult, error) {
if err != nil {
if errors.Is(err, errMissingHost(client.name)) {
return &types.ClusterStatusResult{
CrcStatus: state.Stopped,
OpenshiftStatus: types.OpenshiftStopped,
CrcStatus: state.NoVM,
}, nil
}
return nil, errors.Wrap(err, fmt.Sprintf("Cannot load '%s' virtual machine", client.name))
Expand Down
8 changes: 8 additions & 0 deletions pkg/crc/machine/virtualmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ func (err *MissingHostError) Error() string {
return fmt.Sprintf("no such libmachine vm: %s", err.name)
}

func (err *MissingHostError) Is(target error) bool {
var x *MissingHostError
if errors.As(target, &x) && x.name == err.name {
return true
}
return false
}

var errInvalidBundleMetadata = errors.New("Error loading bundle metadata")

func loadVirtualMachine(name string, useVSock bool) (*virtualMachine, error) {
Expand Down

0 comments on commit 6d61cbf

Please sign in to comment.