From 181954f43b40ffc294295ee74074efedb5fdca11 Mon Sep 17 00:00:00 2001 From: praveenkumar Date: Fri, 4 Feb 2022 14:09:39 +0530 Subject: [PATCH] Version: Add podman bundle version to version command/api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` ✗ ./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" } ``` --- cmd/crc/cmd/version.go | 3 +++ cmd/crc/cmd/version_test.go | 5 ++++- pkg/crc/api/api_client_test.go | 1 + pkg/crc/api/api_http_test.go | 2 +- pkg/crc/api/client/types.go | 1 + pkg/crc/api/handlers.go | 1 + 6 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/crc/cmd/version.go b/cmd/crc/cmd/version.go index fdaa24e326..1744fe49f8 100644 --- a/cmd/crc/cmd/version.go +++ b/cmd/crc/cmd/version.go @@ -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"` } @@ -49,6 +50,7 @@ func defaultVersion() *version { Version: crcversion.GetCRCVersion(), Commit: crcversion.GetCommitSha(), OpenshiftVersion: crcversion.GetBundleVersion(), + PodmanVersion: crcversion.GetPodmanVersion(), InstalledBundlePath: installedBundlePath, } } @@ -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), } } diff --git a/cmd/crc/cmd/version_test.go b/cmd/crc/cmd/version_test.go index de449fb982..1650d28b1f 100644 --- a/cmd/crc/cmd/version_test.go +++ b/cmd/crc/cmd/version_test.go @@ -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()) } @@ -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()) } diff --git a/pkg/crc/api/api_client_test.go b/pkg/crc/api/api_client_test.go index 497e53f509..696d8da0e2 100644 --- a/pkg/crc/api/api_client_test.go +++ b/pkg/crc/api/api_client_test.go @@ -52,6 +52,7 @@ func TestVersion(t *testing.T) { CrcVersion: version.GetCRCVersion(), OpenshiftVersion: version.GetBundleVersion(), CommitSha: version.GetCommitSha(), + PodmanVersion: version.GetPodmanVersion(), }, vr, ) diff --git a/pkg/crc/api/api_http_test.go b/pkg/crc/api/api_http_test.go index 38aef659ac..a3637981d7 100644 --- a/pkg/crc/api/api_http_test.go +++ b/pkg/crc/api/api_http_test.go @@ -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 diff --git a/pkg/crc/api/client/types.go b/pkg/crc/api/client/types.go index 07f751bf6e..5d78050e94 100644 --- a/pkg/crc/api/client/types.go +++ b/pkg/crc/api/client/types.go @@ -9,6 +9,7 @@ type VersionResult struct { CrcVersion string CommitSha string OpenshiftVersion string + PodmanVersion string } type StartResult struct { diff --git a/pkg/crc/api/handlers.go b/pkg/crc/api/handlers.go index 6521c02e50..d356b5afa6 100644 --- a/pkg/crc/api/handlers.go +++ b/pkg/crc/api/handlers.go @@ -124,6 +124,7 @@ func (h *Handler) GetVersion(c *context) error { CrcVersion: version.GetCRCVersion(), CommitSha: version.GetCommitSha(), OpenshiftVersion: version.GetBundleVersion(), + PodmanVersion: version.GetPodmanVersion(), }) }