mirror of
https://github.com/containers/podman.git
synced 2025-07-17 17:43:23 +08:00
Merge pull request #11286 from jwhonce/issues/11227
Update /version endpoint to add components
This commit is contained in:
@ -951,6 +951,11 @@ func (r *Runtime) GetOCIRuntimePath() string {
|
|||||||
return r.defaultOCIRuntime.Path()
|
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
|
// StorageConfig retrieves the storage options for the container runtime
|
||||||
func (r *Runtime) StorageConfig() storage.StoreOptions {
|
func (r *Runtime) StorageConfig() storage.StoreOptions {
|
||||||
return r.storageConfig
|
return r.storageConfig
|
||||||
|
@ -13,20 +13,19 @@ import (
|
|||||||
"github.com/containers/podman/v3/pkg/domain/entities/types"
|
"github.com/containers/podman/v3/pkg/domain/entities/types"
|
||||||
"github.com/containers/podman/v3/version"
|
"github.com/containers/podman/v3/version"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func VersionHandler(w http.ResponseWriter, r *http.Request) {
|
func VersionHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// 200 ok
|
|
||||||
// 500 internal
|
|
||||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
|
|
||||||
versionInfo, err := define.GetVersion()
|
running, err := define.GetVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
|
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
infoData, err := runtime.Info()
|
info, err := runtime.Info()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrapf(err, "failed to obtain system memory info"))
|
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrapf(err, "failed to obtain system memory info"))
|
||||||
return
|
return
|
||||||
@ -34,20 +33,40 @@ func VersionHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
components := []types.ComponentVersion{{
|
components := []types.ComponentVersion{{
|
||||||
Name: "Podman Engine",
|
Name: "Podman Engine",
|
||||||
Version: versionInfo.Version,
|
Version: running.Version,
|
||||||
Details: map[string]string{
|
Details: map[string]string{
|
||||||
"APIVersion": version.APIVersion[version.Libpod][version.CurrentAPI].String(),
|
"APIVersion": version.APIVersion[version.Libpod][version.CurrentAPI].String(),
|
||||||
"Arch": goRuntime.GOARCH,
|
"Arch": goRuntime.GOARCH,
|
||||||
"BuildTime": time.Unix(versionInfo.Built, 0).Format(time.RFC3339),
|
"BuildTime": time.Unix(running.Built, 0).Format(time.RFC3339),
|
||||||
"Experimental": "true",
|
"Experimental": "false",
|
||||||
"GitCommit": versionInfo.GitCommit,
|
"GitCommit": running.GitCommit,
|
||||||
"GoVersion": versionInfo.GoVersion,
|
"GoVersion": running.GoVersion,
|
||||||
"KernelVersion": infoData.Host.Kernel,
|
"KernelVersion": info.Host.Kernel,
|
||||||
"MinAPIVersion": version.APIVersion[version.Libpod][version.MinimalAPI].String(),
|
"MinAPIVersion": version.APIVersion[version.Libpod][version.MinimalAPI].String(),
|
||||||
"Os": goRuntime.GOOS,
|
"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]
|
apiVersion := version.APIVersion[version.Compat][version.CurrentAPI]
|
||||||
minVersion := version.APIVersion[version.Compat][version.MinimalAPI]
|
minVersion := version.APIVersion[version.Compat][version.MinimalAPI]
|
||||||
|
|
||||||
@ -56,13 +75,13 @@ func VersionHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
Platform: struct {
|
Platform: struct {
|
||||||
Name string
|
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),
|
APIVersion: fmt.Sprintf("%d.%d", apiVersion.Major, apiVersion.Minor),
|
||||||
Arch: components[0].Details["Arch"],
|
Arch: components[0].Details["Arch"],
|
||||||
BuildTime: components[0].Details["BuildTime"],
|
BuildTime: components[0].Details["BuildTime"],
|
||||||
Components: components,
|
Components: components,
|
||||||
Experimental: true,
|
Experimental: false,
|
||||||
GitCommit: components[0].Details["GitCommit"],
|
GitCommit: components[0].Details["GitCommit"],
|
||||||
GoVersion: components[0].Details["GoVersion"],
|
GoVersion: components[0].Details["GoVersion"],
|
||||||
KernelVersion: components[0].Details["KernelVersion"],
|
KernelVersion: components[0].Details["KernelVersion"],
|
||||||
|
@ -70,6 +70,15 @@ class SystemTestCase(APITestCase):
|
|||||||
r = requests.get(self.uri("/version"))
|
r = requests.get(self.uri("/version"))
|
||||||
self.assertEqual(r.status_code, 200, r.text)
|
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):
|
def test_df(self):
|
||||||
r = requests.get(self.podman_url + "/v1.40/system/df")
|
r = requests.get(self.podman_url + "/v1.40/system/df")
|
||||||
self.assertEqual(r.status_code, 200, r.text)
|
self.assertEqual(r.status_code, 200, r.text)
|
||||||
|
Reference in New Issue
Block a user