api: fix slow version endpoint

This endpoint queried the same package versions twice causing it to be
slower than info. Because it already called info we can just reuse the
package versions from there.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger 2023-07-10 15:30:28 +02:00
parent 7cd1fb77f9
commit 70428baef3
No known key found for this signature in database
GPG key ID: EB145DD938A3CAF2

View file

@ -13,7 +13,6 @@ import (
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/domain/entities/types"
"github.com/containers/podman/v4/version"
"github.com/sirupsen/logrus"
)
func VersionHandler(w http.ResponseWriter, r *http.Request) {
@ -45,30 +44,20 @@ func VersionHandler(w http.ResponseWriter, r *http.Request) {
"MinAPIVersion": version.APIVersion[version.Libpod][version.MinimalAPI].String(),
"Os": goRuntime.GOOS,
},
}, {
Name: "Conmon",
Version: info.Host.Conmon.Version,
Details: map[string]string{
"Package": info.Host.Conmon.Package,
},
}, {
Name: fmt.Sprintf("OCI Runtime (%s)", info.Host.OCIRuntime.Name),
Version: info.Host.OCIRuntime.Version,
Details: map[string]string{
"Package": info.Host.OCIRuntime.Package,
},
}}
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]