libpod: Validate that log tag requires journald driver

Currently validation that log tag requires journald driver is done in several
places and emits only warning. Making it an error and moving to
`(c *Container) validate()` is a more correct approach.

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
This commit is contained in:
Povilas Kanapickas
2026-03-04 14:12:33 +02:00
parent 8aad8d72e0
commit 9872cbd756
4 changed files with 17 additions and 21 deletions

View File

@@ -20,7 +20,6 @@ import (
"github.com/containers/podman/v6/pkg/signal"
"github.com/containers/podman/v6/pkg/specgen"
"github.com/openshift/imagebuilder"
"github.com/sirupsen/logrus"
"go.podman.io/common/libimage"
"go.podman.io/common/pkg/config"
"go.podman.io/image/v5/manifest"
@@ -332,16 +331,11 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
s.LogConfiguration.Driver = rtc.Containers.LogDriver
}
if len(rtc.Containers.LogTag) > 0 {
if s.LogConfiguration.Driver != define.JSONLogging {
if s.LogConfiguration.Options == nil {
s.LogConfiguration.Options = make(map[string]string)
}
if _, exists := s.LogConfiguration.Options["tag"]; !exists {
s.LogConfiguration.Options["tag"] = rtc.Containers.LogTag
}
} else {
logrus.Warnf("log_tag %q is not allowed with %q log_driver", rtc.Containers.LogTag, define.JSONLogging)
if s.LogConfiguration.Options == nil {
s.LogConfiguration.Options = make(map[string]string)
}
if _, exists := s.LogConfiguration.Options["tag"]; !exists {
s.LogConfiguration.Options["tag"] = rtc.Containers.LogTag
}
}

View File

@@ -31,7 +31,6 @@ import (
"github.com/docker/docker/pkg/meminfo"
"github.com/docker/go-units"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"go.podman.io/common/libimage"
"go.podman.io/common/libnetwork/types"
"go.podman.io/common/pkg/config"
@@ -265,17 +264,10 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
}
s.LogConfiguration.Size = logSize
default:
switch len(val) {
case 0:
if len(val) == 0 {
return nil, fmt.Errorf("invalid log option: %w", define.ErrInvalidArg)
default:
// tags for journald only
if s.LogConfiguration.Driver == "" || s.LogConfiguration.Driver == define.JournaldLogging {
s.LogConfiguration.Options[opt] = val
} else {
logrus.Warnf("Can only set tags with journald log driver but driver is %q", s.LogConfiguration.Driver)
}
}
s.LogConfiguration.Options[opt] = val
}
}