Skip to content

Commit

Permalink
Update /version endpoint to add components
Browse files Browse the repository at this point in the history
* Include OCI and conmon information as components

Fixes containers#11227

Signed-off-by: Jhon Honce <[email protected]>
  • Loading branch information
jwhonce committed Aug 19, 2021
1 parent f988cfe commit fd32c73
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
5 changes: 5 additions & 0 deletions libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,11 @@ func (r *Runtime) GetOCIRuntimePath() string {
return r.defaultOCIRuntime.Path()
}

// DefaultOCIRuntime return copy of Default OCI Runtime
func (r *Runtime) DefaultOCIRuntime() OCIRuntime {
return r.defaultOCIRuntime
}

// StorageConfig retrieves the storage options for the container runtime
func (r *Runtime) StorageConfig() storage.StoreOptions {
return r.storageConfig
Expand Down
43 changes: 31 additions & 12 deletions pkg/api/handlers/compat/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,60 @@ import (
"github.com/containers/podman/v3/pkg/domain/entities/types"
"github.com/containers/podman/v3/version"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

func VersionHandler(w http.ResponseWriter, r *http.Request) {
// 200 ok
// 500 internal
runtime := r.Context().Value("runtime").(*libpod.Runtime)

versionInfo, err := define.GetVersion()
running, err := define.GetVersion()
if err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
return
}

infoData, err := runtime.Info()
info, err := runtime.Info()
if err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrapf(err, "failed to obtain system memory info"))
return
}

components := []types.ComponentVersion{{
Name: "Podman Engine",
Version: versionInfo.Version,
Version: running.Version,
Details: map[string]string{
"APIVersion": version.APIVersion[version.Libpod][version.CurrentAPI].String(),
"Arch": goRuntime.GOARCH,
"BuildTime": time.Unix(versionInfo.Built, 0).Format(time.RFC3339),
"Experimental": "true",
"GitCommit": versionInfo.GitCommit,
"GoVersion": versionInfo.GoVersion,
"KernelVersion": infoData.Host.Kernel,
"BuildTime": time.Unix(running.Built, 0).Format(time.RFC3339),
"Experimental": "false",
"GitCommit": running.GitCommit,
"GoVersion": running.GoVersion,
"KernelVersion": info.Host.Kernel,
"MinAPIVersion": version.APIVersion[version.Libpod][version.MinimalAPI].String(),
"Os": goRuntime.GOOS,
},
}}

if conmon, oci, err := runtime.DefaultOCIRuntime().RuntimeInfo(); err != nil {
logrus.Warnf("Failed to retrieve Conmon and OCI Information: %q", err.Error())
} else {
additional := []types.ComponentVersion{
{
Name: "Conmon",
Version: conmon.Version,
Details: map[string]string{
"Package": conmon.Package,
}},
{
Name: fmt.Sprintf("OCI Runtime (%s)", oci.Name),
Version: oci.Version,
Details: map[string]string{
"Package": oci.Package,
}},
}
components = append(components, additional...)
}

apiVersion := version.APIVersion[version.Compat][version.CurrentAPI]
minVersion := version.APIVersion[version.Compat][version.MinimalAPI]

Expand All @@ -56,13 +75,13 @@ func VersionHandler(w http.ResponseWriter, r *http.Request) {
Platform: struct {
Name string
}{
Name: fmt.Sprintf("%s/%s/%s-%s", goRuntime.GOOS, goRuntime.GOARCH, infoData.Host.Distribution.Distribution, infoData.Host.Distribution.Version),
Name: fmt.Sprintf("%s/%s/%s-%s", goRuntime.GOOS, goRuntime.GOARCH, info.Host.Distribution.Distribution, info.Host.Distribution.Version),
},
APIVersion: fmt.Sprintf("%d.%d", apiVersion.Major, apiVersion.Minor),
Arch: components[0].Details["Arch"],
BuildTime: components[0].Details["BuildTime"],
Components: components,
Experimental: true,
Experimental: false,
GitCommit: components[0].Details["GitCommit"],
GoVersion: components[0].Details["GoVersion"],
KernelVersion: components[0].Details["KernelVersion"],
Expand Down
9 changes: 9 additions & 0 deletions test/apiv2/python/rest_api/test_v2_0_0_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def test_version(self):
r = requests.get(self.uri("/version"))
self.assertEqual(r.status_code, 200, r.text)

body = r.json()
names = [d.get("Name", "") for d in body["Components"]]

self.assertIn("Conmon", names)
for n in names:
if n.startswith("OCI Runtime"):
oci_name = n
self.assertIsNotNone(oci_name, "OCI Runtime not found in version components.")

def test_df(self):
r = requests.get(self.podman_url + "/v1.40/system/df")
self.assertEqual(r.status_code, 200, r.text)
Expand Down

0 comments on commit fd32c73

Please sign in to comment.