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.
This commit is contained in:
jvassev 2018-04-12 02:51:19 +03:00 committed by Daniel Nelson
parent 3f4e1af222
commit 2c19d74829
2 changed files with 10 additions and 0 deletions

View File

@ -519,7 +519,13 @@ func (c *Config) LoadDirectory(path string) error {
log.Printf("W! Telegraf is not permitted to read %s", thispath) log.Printf("W! Telegraf is not permitted to read %s", thispath)
return nil return nil
} }
if info.IsDir() { if info.IsDir() {
if strings.HasPrefix(info.Name(), "..") {
// skip Kubernetes mounts, prevening loading the same config twice
return filepath.SkipDir
}
return nil return nil
} }
name := info.Name() name := info.Name()

View File

@ -0,0 +1,4 @@
# This invalid config file should be skipped during testing
# as it is an ..data folder
[[outputs.influxdb