Skip to content

Commit

Permalink
Version: Add podman bundle version to version command/api
Browse files Browse the repository at this point in the history
```
✗ ./crc version
CodeReady Containers version: 1.99.1+d6808d02
OpenShift version: 4.9.12 (not embedded in executable)
Podman version: 3.4.4

✗ ./crc version -ojson
{
  "version": "1.99.1",
  "commit": "d6808d02",
  "openshiftVersion": "4.9.12",
  "podmanVersion": "3.4.4"
}

✗ curl --unix-socket ~/.crc/crc-http.sock http:/c/api/version  | jq .
{
  "CrcVersion": "1.99.1",
  "CommitSha": "d6808d02",
  "OpenshiftVersion": "4.9.12",
  "PodmanVersion": "3.4.4"
}
```
  • Loading branch information
praveenkumar committed Mar 3, 2022
1 parent 66660ff commit 181954f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/crc/cmd/version.go
Expand Up @@ -37,6 +37,7 @@ type version struct {
Version string `json:"version"`
Commit string `json:"commit"`
OpenshiftVersion string `json:"openshiftVersion"`
PodmanVersion string `json:"podmanVersion"`
InstalledBundlePath string `json:"installedBundlePath,omitempty"`
}

Expand All @@ -49,6 +50,7 @@ func defaultVersion() *version {
Version: crcversion.GetCRCVersion(),
Commit: crcversion.GetCommitSha(),
OpenshiftVersion: crcversion.GetBundleVersion(),
PodmanVersion: crcversion.GetPodmanVersion(),
InstalledBundlePath: installedBundlePath,
}
}
Expand All @@ -73,5 +75,6 @@ func (v *version) lines() []string {
return []string{
fmt.Sprintf("CodeReady Containers version: %s+%s\n", v.Version, v.Commit),
fmt.Sprintf("OpenShift version: %s (%s)\n", v.OpenshiftVersion, bundleStatus),
fmt.Sprintf("Podman version: %s\n", v.PodmanVersion),
}
}
5 changes: 4 additions & 1 deletion cmd/crc/cmd/version_test.go
Expand Up @@ -13,10 +13,12 @@ func TestPlainVersion(t *testing.T) {
Version: "1.13",
Commit: "aabbcc",
OpenshiftVersion: "4.5.4",
PodmanVersion: "3.4.4",
InstalledBundlePath: "",
}, ""))
assert.Equal(t, `CodeReady Containers version: 1.13+aabbcc
OpenShift version: 4.5.4 (not embedded in executable)
Podman version: 3.4.4
`, out.String())
}

Expand All @@ -26,9 +28,10 @@ func TestJsonVersion(t *testing.T) {
Version: "1.13",
Commit: "aabbcc",
OpenshiftVersion: "4.5.4",
PodmanVersion: "3.4.4",
InstalledBundlePath: "",
}, "json"))

expected := `{"version": "1.13", "commit": "aabbcc", "openshiftVersion": "4.5.4"}`
expected := `{"version": "1.13", "commit": "aabbcc", "openshiftVersion": "4.5.4", "podmanVersion": "3.4.4"}`
assert.JSONEq(t, expected, out.String())
}
1 change: 1 addition & 0 deletions pkg/crc/api/api_client_test.go
Expand Up @@ -52,6 +52,7 @@ func TestVersion(t *testing.T) {
CrcVersion: version.GetCRCVersion(),
OpenshiftVersion: version.GetBundleVersion(),
CommitSha: version.GetCommitSha(),
PodmanVersion: version.GetPodmanVersion(),
},
vr,
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/api/api_http_test.go
Expand Up @@ -265,7 +265,7 @@ var testCases = []testCase{
// version
{
request: get("version"),
response: jSon(fmt.Sprintf(`{"CrcVersion":"%s","CommitSha":"%s","OpenshiftVersion":"%s"}`, version.GetCRCVersion(), version.GetCommitSha(), version.GetBundleVersion())),
response: jSon(fmt.Sprintf(`{"CrcVersion":"%s","CommitSha":"%s","OpenshiftVersion":"%s","PodmanVersion":"%s"}`, version.GetCRCVersion(), version.GetCommitSha(), version.GetBundleVersion(), version.GetPodmanVersion())),
},

// version never fails
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/api/client/types.go
Expand Up @@ -9,6 +9,7 @@ type VersionResult struct {
CrcVersion string
CommitSha string
OpenshiftVersion string
PodmanVersion string
}

type StartResult struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/crc/api/handlers.go
Expand Up @@ -124,6 +124,7 @@ func (h *Handler) GetVersion(c *context) error {
CrcVersion: version.GetCRCVersion(),
CommitSha: version.GetCommitSha(),
OpenshiftVersion: version.GetBundleVersion(),
PodmanVersion: version.GetPodmanVersion(),
})
}

Expand Down

0 comments on commit 181954f

Please sign in to comment.