Skip to content

Commit

Permalink
Verify logdriver and eventslogger will work together
Browse files Browse the repository at this point in the history
Fixes:containers/podman#12175

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed May 7, 2022
1 parent d8d159c commit b0c6cc6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
31 changes: 31 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/BurntSushi/toml"
"github.com/containers/common/libnetwork/types"
"github.com/containers/common/pkg/capabilities"
"github.com/containers/common/pkg/util"
"github.com/containers/storage/pkg/unshare"
units "github.com/docker/go-units"
selinux "github.com/opencontainers/selinux/go-selinux"
Expand Down Expand Up @@ -640,6 +641,10 @@ func NewConfig(userConfigPath string) (*Config, error) {
return nil, err
}

if err := LoggingValid(config.Containers.LogDriver, config.Engine.EventsLogger); err != nil {
return nil, err
}

return config, nil
}

Expand Down Expand Up @@ -1306,3 +1311,29 @@ func (e eventsLogMaxSize) MarshalText() ([]byte, error) {
}
return []byte(fmt.Sprintf("%d", e)), nil
}

func LoggingValid(logDriver string, eventsLogger string) error {

validLogDriver := []string{"file", "k8s-file", "journald", "none"}
validEventsLogger := []string{"file", "journald", "none"}
if !util.StringInSlice(logDriver, validLogDriver) {
return errors.Errorf("invalid LogDriver %q must be one of %q", logDriver, strings.Join(validLogDriver, ", "))
}
if !util.StringInSlice(eventsLogger, validEventsLogger) {
return errors.Errorf("invalid EventsLogger %q must be one of %q", eventsLogger, strings.Join(validEventsLogger, ", "))
}
logErr := errors.Errorf("invalid logging combination LogDriver %q is not allowed with EventsLogger %q", logDriver, eventsLogger)
switch logDriver {
case "none":
break
case "file", "k8s-file":
if eventsLogger == "journald" {
return logErr
}
case "journald":
if eventsLogger == "file" {
return logErr
}
}
return nil
}
27 changes: 26 additions & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ image_copy_tmp_dir="storage"`
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(config).ToNot(gomega.BeNil())
gomega.Expect(config.Containers.ApparmorProfile).To(gomega.Equal("overridden-default"))
gomega.Expect(config.Containers.LogDriver).To(gomega.Equal("journald"))
gomega.Expect(config.Containers.LogDriver).To(gomega.Equal("file"))
gomega.Expect(config.Containers.LogTag).To(gomega.Equal("{{.Name}}|{{.ID}}"))
gomega.Expect(config.Containers.LogSizeMax).To(gomega.Equal(int64(100000)))
gomega.Expect(config.Engine.ImageParallelCopies).To(gomega.Equal(uint(10)))
Expand Down Expand Up @@ -809,4 +809,29 @@ env=["foo=bar"]`
gomega.Expect(string(b)).To(gomega.
Equal("[containers]\n\n[engine]\n\n[machine]\n\n[network]\n\n[secrets]\n\n[configmaps]\n"))
})

It("test LoggingValid", func() {
err := LoggingValid("bogus", "file")
gomega.Expect(err).To(gomega.HaveOccurred())
gomega.Expect(err.Error()).To(gomega.Equal("invalid LogDriver \"bogus\" must be one of \"file, k8s-file, journald, none\""))
err = LoggingValid("file", "bogus")
gomega.Expect(err).To(gomega.HaveOccurred())
gomega.Expect(err.Error()).To(gomega.Equal("invalid EventsLogger \"bogus\" must be one of \"file, journald, none\""))

for _, logDriver := range []string{"file", "k8s-file", "journald"} {
for _, eventsLogger := range []string{"file", "journald", "none"} {
err := LoggingValid(logDriver, eventsLogger)
switch {
case eventsLogger == "file" && logDriver == "k8s-file":
fallthrough
case eventsLogger == "none", logDriver == "none":
fallthrough
case eventsLogger == logDriver:
gomega.Expect(err).ToNot(gomega.HaveOccurred())
default:
gomega.Expect(err).To(gomega.HaveOccurred())
}
}
}
})
})
2 changes: 1 addition & 1 deletion pkg/config/testdata/containers_override.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[containers]

apparmor_profile = "overridden-default"
log_driver = "journald"
log_driver = "file"
log_tag="{{.Name}}|{{.ID}}"
log_size_max = 100000

Expand Down

0 comments on commit b0c6cc6

Please sign in to comment.