feat: make inspect compatible with docker v1.44

Signed-off-by: Florian Bezannier <florian.bezannier@hotmail.fr>
This commit is contained in:
Florian Bezannier 2024-02-10 12:33:07 +01:00
parent 031e7a15b0
commit de845a5b42
3 changed files with 16 additions and 6 deletions

View File

@ -5,10 +5,13 @@ package libpod
import ( import (
"errors" "errors"
"fmt" "fmt"
"strconv"
"strings" "strings"
"syscall"
"github.com/containers/podman/v5/libpod/define" "github.com/containers/podman/v5/libpod/define"
"github.com/containers/podman/v5/libpod/driver" "github.com/containers/podman/v5/libpod/driver"
"github.com/containers/podman/v5/pkg/signal"
"github.com/containers/podman/v5/pkg/util" "github.com/containers/podman/v5/pkg/util"
"github.com/containers/storage/types" "github.com/containers/storage/types"
"github.com/docker/go-units" "github.com/docker/go-units"
@ -388,7 +391,7 @@ func (c *Container) generateInspectContainerConfig(spec *spec.Spec) *define.Insp
// Leave empty if not explicitly overwritten by user // Leave empty if not explicitly overwritten by user
if len(c.config.Entrypoint) != 0 { if len(c.config.Entrypoint) != 0 {
ctrConfig.Entrypoint = strings.Join(c.config.Entrypoint, " ") ctrConfig.Entrypoint = c.config.Entrypoint
} }
if len(c.config.Labels) != 0 { if len(c.config.Labels) != 0 {
@ -404,8 +407,11 @@ func (c *Container) generateInspectContainerConfig(spec *spec.Spec) *define.Insp
ctrConfig.Annotations[k] = v ctrConfig.Annotations[k] = v
} }
} }
var signal, err = signal.ParseSysSignalToName(syscall.Signal(c.config.StopSignal))
ctrConfig.StopSignal = c.config.StopSignal if err != nil {
signal = strconv.FormatUint(uint64(c.config.StopSignal), 10)
}
ctrConfig.StopSignal = fmt.Sprintf("SIG%s", signal)
// TODO: should JSON deep copy this to ensure internal pointers don't // TODO: should JSON deep copy this to ensure internal pointers don't
// leak. // leak.
ctrConfig.Healthcheck = c.config.HealthCheckConfig ctrConfig.Healthcheck = c.config.HealthCheckConfig

View File

@ -44,7 +44,7 @@ type InspectContainerConfig struct {
// Container working directory // Container working directory
WorkingDir string `json:"WorkingDir"` WorkingDir string `json:"WorkingDir"`
// Container entrypoint // Container entrypoint
Entrypoint string `json:"Entrypoint"` Entrypoint []string `json:"Entrypoint"`
// On-build arguments - presently unused. More of Buildah's domain. // On-build arguments - presently unused. More of Buildah's domain.
OnBuild *string `json:"OnBuild"` OnBuild *string `json:"OnBuild"`
// Container labels // Container labels
@ -52,7 +52,7 @@ type InspectContainerConfig struct {
// Container annotations // Container annotations
Annotations map[string]string `json:"Annotations"` Annotations map[string]string `json:"Annotations"`
// Container stop signal // Container stop signal
StopSignal uint `json:"StopSignal"` StopSignal string `json:"StopSignal"`
// Configured healthcheck for the container // Configured healthcheck for the container
Healthcheck *manifest.Schema2HealthConfig `json:"Healthcheck,omitempty"` Healthcheck *manifest.Schema2HealthConfig `json:"Healthcheck,omitempty"`
// HealthcheckOnFailureAction defines an action to take once the container turns unhealthy. // HealthcheckOnFailureAction defines an action to take once the container turns unhealthy.

View File

@ -235,8 +235,12 @@ func makeInspectPorts(bindings []types.PortMapping, expose map[uint16][]string)
for i := uint16(0); i < port.Range; i++ { for i := uint16(0); i < port.Range; i++ {
key := fmt.Sprintf("%d/%s", port.ContainerPort+i, protocol) key := fmt.Sprintf("%d/%s", port.ContainerPort+i, protocol)
hostPorts := portBindings[key] hostPorts := portBindings[key]
var host = port.HostIP
if len(port.HostIP) == 0 {
host = "0.0.0.0"
}
hostPorts = append(hostPorts, define.InspectHostPort{ hostPorts = append(hostPorts, define.InspectHostPort{
HostIP: port.HostIP, HostIP: host,
HostPort: strconv.FormatUint(uint64(port.HostPort+i), 10), HostPort: strconv.FormatUint(uint64(port.HostPort+i), 10),
}) })
portBindings[key] = hostPorts portBindings[key] = hostPorts