From af7382e224ab13dde0879c99eabc8844396bd005 Mon Sep 17 00:00:00 2001 From: jvassev Date: Thu, 12 Apr 2018 02:51:19 +0300 Subject: [PATCH] Prevent loading config twice in K8S (#3999) When config dir is mounted from configmap, filepath.Walk() finds the same .conf file twice as 20-acme.conf is a link to ..data/20-acme.conf for example. This patch skips all folder names starting with '..' which is pretty uncommon and mainly used by Kubernetes mounts. --- internal/config/config.go | 6 ++++++ .../subconfig/..4984_10_04_08_28_06.119/invalid-config.conf | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 internal/config/testdata/subconfig/..4984_10_04_08_28_06.119/invalid-config.conf diff --git a/internal/config/config.go b/internal/config/config.go index fe8cac5ae..4c6ed5624 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -519,7 +519,13 @@ func (c *Config) LoadDirectory(path string) error { log.Printf("W! Telegraf is not permitted to read %s", thispath) return nil } + if info.IsDir() { + if strings.HasPrefix(info.Name(), "..") { + // skip Kubernetes mounts, prevening loading the same config twice + return filepath.SkipDir + } + return nil } name := info.Name() diff --git a/internal/config/testdata/subconfig/..4984_10_04_08_28_06.119/invalid-config.conf b/internal/config/testdata/subconfig/..4984_10_04_08_28_06.119/invalid-config.conf new file mode 100644 index 000000000..aee9abdfe --- /dev/null +++ b/internal/config/testdata/subconfig/..4984_10_04_08_28_06.119/invalid-config.conf @@ -0,0 +1,4 @@ +# This invalid config file should be skipped during testing +# as it is an ..data folder + +[[outputs.influxdb