-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix file backend #686
Fix file backend #686
Conversation
AndrewChubatiuk
commented
Mar 8, 2018
•
edited
Loading
edited
- Fixes YML-file backend does not honor Keys list from toml file #667. Fixes confd fails to read non-string keys when using file backend #640
- Added support for multiple yaml files and directories
- Added -filter flag for files/directories filtering
- Added recursive file watcher
…ty to specify multiple file backends
aa61feb
to
2611c46
Compare
util/filestat_windows.go
Outdated
// fileStat return a fileInfo describing the named file. | ||
func fileStat(name string) (fi fileInfo, err error) { | ||
// filestat return a FileInfo describing the named file. | ||
func filestat(name string) (fi FileInfo, err error) { | ||
if isFileExist(name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one should be uppercase.
config.go
Outdated
@@ -97,7 +99,8 @@ func init() { | |||
flag.StringVar(&clientKey, "client-key", "", "the client key") | |||
flag.StringVar(&confdir, "confdir", "/etc/confd", "confd conf directory") | |||
flag.StringVar(&configFile, "config-file", "", "the confd config file") | |||
flag.StringVar(&yamlFile, "file", "", "the YAML/JSON file to watch for changes") | |||
flag.Var(&yamlFile, "file", "the YAML file to watch for changes") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment to indicate that this var is only used by file backend.
config_test.go
Outdated
@@ -23,6 +23,7 @@ func TestInitConfigDefaultConfig(t *testing.T) { | |||
Scheme: "http", | |||
SecretKeyring: "", | |||
Table: "", | |||
Filter: "*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting
backends/file/client.go
Outdated
} | ||
|
||
for _, path := range filePaths { | ||
readFile(path, vars) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for errors
backends/file/client.go
Outdated
} | ||
return nil | ||
} | ||
|
||
func (c *Client) watchChanges(watcher *fsnotify.Watcher, stopChan chan bool) ResultError { | ||
outputChannel := make(chan ResultError) | ||
go func() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one will cause goroutine leak. WatchPrefix
function is actually called in a loop in the main function. WatchPrefix
should block until it receives an event and exit afterward.
util/util.go
Outdated
return false, nil | ||
} | ||
|
||
func Lookup(root string, pattern string) ([]string, []string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lookup
is very ambiguous. Rename it to recursiveFindFiles
or something more appropriate.
resource/template/resource.go
Outdated
@@ -345,7 +346,7 @@ func runCommand(cmd string) error { | |||
// from the store, then we stage a candidate configuration file, and finally sync | |||
// things up. | |||
// It returns an error if any. | |||
func (t *TemplateResource) process() error { | |||
func (t *TemplateResource) generateConfigs() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process
is actually a better name for this method because it is a method of a TemplateResource
and we process
a template.
resource/template/processor.go
Outdated
defer close(p.doneChan) | ||
p.reloadConfigs() | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, syscall.SIGHUP) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move the sighup handling / config reloading into a separate PR.
backends/file/client.go
Outdated
if event.Op&fsnotify.Write == fsnotify.Write || | ||
event.Op&fsnotify.Remove == fsnotify.Remove || | ||
event.Op&fsnotify.Create == fsnotify.Create || | ||
event.Op&fsnotify.Rename == fsnotify.Rename || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of handling Rename and Chmod events?
2611c46
to
27428bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm