mirror of
https://github.com/containers/podman.git
synced 2025-08-26 11:33:07 +08:00
Fix podman inspect
to correctly handle log_size_max
When generating Conmon's command line, we read containers.conf to get log_size_max and used it if the container didn't override it. However, `podman inspect` only reads from the container's own config, and ignores containers.conf. Unify the way we determine maximum log size with a single function and use it for both inspect and containers.conf, and add a test for this behavior. Fixes https://issues.redhat.com/browse/RHEL-96776 Signed-off-by: Matt Heon <mheon@redhat.com>
This commit is contained in:
@ -669,6 +669,14 @@ func (c *Container) LogTag() string {
|
||||
return c.config.LogTag
|
||||
}
|
||||
|
||||
// LogSizeMax returns the maximum size of the container's log file.
|
||||
func (c *Container) LogSizeMax() int64 {
|
||||
if c.config.LogSize > 0 {
|
||||
return c.config.LogSize
|
||||
}
|
||||
return c.runtime.config.Containers.LogSizeMax
|
||||
}
|
||||
|
||||
// RestartPolicy returns the container's restart policy.
|
||||
func (c *Container) RestartPolicy() string {
|
||||
return c.config.RestartPolicy
|
||||
|
@ -378,7 +378,7 @@ type ContainerMiscConfig struct {
|
||||
LogPath string `json:"logPath"`
|
||||
// LogTag is the tag used for logging
|
||||
LogTag string `json:"logTag"`
|
||||
// LogSize is the tag used for logging
|
||||
// LogSize is the maximum size of the container's log file
|
||||
LogSize int64 `json:"logSize"`
|
||||
// LogDriver driver for logs
|
||||
LogDriver string `json:"logDriver"`
|
||||
|
@ -498,7 +498,7 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
|
||||
logConfig := new(define.InspectLogConfig)
|
||||
logConfig.Type = c.config.LogDriver
|
||||
logConfig.Path = c.config.LogPath
|
||||
logConfig.Size = units.HumanSize(float64(c.config.LogSize))
|
||||
logConfig.Size = units.HumanSize(float64(c.LogSizeMax()))
|
||||
logConfig.Tag = c.config.LogTag
|
||||
|
||||
hostConfig.LogConfig = logConfig
|
||||
|
@ -1342,10 +1342,7 @@ func (r *ConmonOCIRuntime) sharedConmonArgs(ctr *Container, cuuid, bundlePath, p
|
||||
logrus.Debugf("%s messages will be logged to syslog", r.conmonPath)
|
||||
args = append(args, "--syslog")
|
||||
|
||||
size := r.logSizeMax
|
||||
if ctr.config.LogSize > 0 {
|
||||
size = ctr.config.LogSize
|
||||
}
|
||||
size := ctr.LogSizeMax()
|
||||
if size > 0 {
|
||||
args = append(args, "--log-size-max", strconv.FormatInt(size, 10))
|
||||
}
|
||||
|
@ -1804,4 +1804,27 @@ RUN umount /etc/hostname; rm /etc/hostname
|
||||
run_podman rmi $randomname
|
||||
}
|
||||
|
||||
@test "podman run --log-opt size= and containers.conf log_size_max" {
|
||||
skip_if_remote "remote does not support CONTAINERS_CONF"
|
||||
|
||||
containersconf=$PODMAN_TMPDIR/containers.conf
|
||||
cat >$containersconf <<EOF
|
||||
[containers]
|
||||
log_driver = "k8s-file"
|
||||
log_size_max = 400000000
|
||||
EOF
|
||||
|
||||
c1name=c1_$(safename)
|
||||
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman create --name $c1name $IMAGE ls /
|
||||
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman inspect --format '{{ .HostConfig.LogConfig.Size }}' $c1name
|
||||
is "$output" "400MB"
|
||||
|
||||
c2name=c2_$(safename)
|
||||
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman create --name $c2name --log-opt max-size=8000 $IMAGE ls /
|
||||
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman inspect --format '{{ .HostConfig.LogConfig.Size }}' $c2name
|
||||
is "$output" "8kB"
|
||||
|
||||
run_podman rm -f $c1name $c2name
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
|
Reference in New Issue
Block a user