Skip to content
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

Merged

Conversation

AndrewChubatiuk
Copy link
Contributor

@AndrewChubatiuk AndrewChubatiuk commented Mar 8, 2018

// 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) {
Copy link
Collaborator

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")
Copy link
Collaborator

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: "*",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

}

for _, path := range filePaths {
readFile(path, vars)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for errors

}
return nil
}

func (c *Client) watchChanges(watcher *fsnotify.Watcher, stopChan chan bool) ResultError {
outputChannel := make(chan ResultError)
go func() error {
Copy link
Collaborator

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) {
Copy link
Collaborator

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.

@@ -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 {
Copy link
Collaborator

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.

defer close(p.doneChan)
p.reloadConfigs()
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP)
Copy link
Collaborator

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.

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 ||
Copy link
Collaborator

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?

@okushchenko okushchenko added this to the 0.16.0 milestone Mar 18, 2018
@okushchenko okushchenko changed the title File yaml backend fix Fix file backend Mar 18, 2018
Copy link
Collaborator

@okushchenko okushchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@okushchenko okushchenko merged commit 1957caa into kelseyhightower:master Mar 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants