Skip to content

Commit

Permalink
cmd/Status: Add podman version as part of crc status
Browse files Browse the repository at this point in the history
This patch adds podman version to status command and output the
following.
```
$ ./crc status
CRC VM:          Running
OpenShift:
Podman:          3.3.1
Disk Usage:      2.731GB of 63.88GB (Inside the CRC VM)
Cache Usage:     31.99GB
Cache Directory: /home/prkumar/.crc/cache

$ ./crc status
CRC VM:          Stopped
OpenShift:
Podman:          3.3.1
Disk Usage:      0B of 0B (Inside the CRC VM)
Cache Usage:     31.99GB
Cache Directory: /home/prkumar/.crc/cache

$ ./crc status -ojson
{
  "success": true,
  "crcStatus": "Running",
  "diskUsage": 2061398016,
  "diskSize": 63876083712,
  "cacheUsage": 31985188364,
  "cacheDir": "/home/prkumar/.crc/cache"
}
```
  • Loading branch information
praveenkumar committed Nov 15, 2021
1 parent 14ce2fc commit acd5fb4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions cmd/crc/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type status struct {
CrcStatus string `json:"crcStatus,omitempty"`
OpenShiftStatus types.OpenshiftStatus `json:"openshiftStatus,omitempty"`
OpenShiftVersion string `json:"openshiftVersion,omitempty"`
PodmanVersion string `json:"podmanVersion,omitempty"`
DiskUsage int64 `json:"diskUsage,omitempty"`
DiskSize int64 `json:"diskSize,omitempty"`
CacheUsage int64 `json:"cacheUsage,omitempty"`
Expand Down Expand Up @@ -71,6 +72,7 @@ func getStatus(client machine.Client, cacheDir string) *status {
CrcStatus: string(clusterStatus.CrcStatus),
OpenShiftStatus: clusterStatus.OpenshiftStatus,
OpenShiftVersion: clusterStatus.OpenshiftVersion,
PodmanVersion: clusterStatus.PodmanVersion,
DiskUsage: clusterStatus.DiskUse,
DiskSize: clusterStatus.DiskSize,
CacheUsage: size,
Expand All @@ -89,6 +91,7 @@ func (s *status) prettyPrintTo(writer io.Writer) error {
}{
{"CRC VM", s.CrcStatus},
{"OpenShift", openshiftStatus(s)},
{"Podman", s.PodmanVersion},
{"Disk Usage", fmt.Sprintf(
"%s of %s (Inside the CRC VM)",
units.HumanSize(float64(s.DiskUsage)),
Expand Down
2 changes: 2 additions & 0 deletions cmd/crc/cmd/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestPlainStatus(t *testing.T) {

expected := `CRC VM: Running
OpenShift: Running (v4.5.1)
Podman: 3.3.1
Disk Usage: 10GB of 20GB (Inside the CRC VM)
Cache Usage: 10kB
Cache Directory: %s
Expand All @@ -49,6 +50,7 @@ func TestJsonStatus(t *testing.T) {
"crcStatus": "Running",
"openshiftStatus": "Running",
"openshiftVersion": "4.5.1",
"podmanVersion": "3.3.1",
"diskUsage": 10000000000,
"diskSize": 20000000000,
"cacheUsage": 10000,
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/machine/fakemachine/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (c *Client) Status() (*types.ClusterStatusResult, error) {
CrcStatus: state.Running,
OpenshiftStatus: types.OpenshiftRunning,
OpenshiftVersion: "4.5.1",
PodmanVersion: "3.3.1",
DiskUse: 10_000_000_000,
DiskSize: 20_000_000_000,
}, nil
Expand Down
17 changes: 12 additions & 5 deletions pkg/crc/machine/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ func (client *client) Status() (*types.ClusterStatusResult, error) {
}

if vmStatus != libmachinestate.Running {
return &types.ClusterStatusResult{
CrcStatus: state.FromMachine(vmStatus),
OpenshiftStatus: types.OpenshiftStopped,
OpenshiftVersion: crcBundleMetadata.GetOpenshiftVersion(),
}, nil
clusterStatusResult := &types.ClusterStatusResult{
CrcStatus: state.FromMachine(vmStatus),
}
if crcBundleMetadata.GetBundleType() == bundle.OpenShift {
clusterStatusResult.OpenshiftStatus = types.OpenshiftStopped
clusterStatusResult.OpenshiftVersion = crcBundleMetadata.GetOpenshiftVersion()
} else {
clusterStatusResult.PodmanVersion = crcBundleMetadata.GetPodmanVersion()
}
return clusterStatusResult, nil
}

ip, err := getIP(host, client.useVSock())
Expand All @@ -65,6 +70,8 @@ func (client *client) Status() (*types.ClusterStatusResult, error) {
if crcBundleMetadata.IsOpenShift() {
clusterStatusResult.OpenshiftStatus = getOpenShiftStatus(context.Background(), ip)
clusterStatusResult.OpenshiftVersion = crcBundleMetadata.GetOpenshiftVersion()
} else {
clusterStatusResult.PodmanVersion = crcBundleMetadata.GetPodmanVersion()
}
return clusterStatusResult, nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/machine/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type ClusterStatusResult struct {
CrcStatus state.State
OpenshiftStatus OpenshiftStatus
OpenshiftVersion string
PodmanVersion string
DiskUse int64
DiskSize int64
}
Expand Down

0 comments on commit acd5fb4

Please sign in to comment.