-
Notifications
You must be signed in to change notification settings - Fork 49
HOSTEDCP-2035: Use Client Cert Auth for ARO HCP deployments #156
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package filewatcher | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "sync" | ||
|
|
||
| "github.com/fsnotify/fsnotify" | ||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| var watchCertificateFileOnce sync.Once | ||
|
|
||
| // WatchFileForChanges watches the file, fileToWatch, for changes. If the file contents have changed, the pod this | ||
| // function is running on will be restarted. | ||
| func WatchFileForChanges(fileToWatch string) error { | ||
| var err error | ||
|
|
||
| // This starts only one occurrence of the file watcher, which watches the file, fileToWatch. | ||
| watchCertificateFileOnce.Do(func() { | ||
|
bryan-cox marked this conversation as resolved.
|
||
| klog.Infof("Starting the file change watcher on file, %s", fileToWatch) | ||
|
|
||
| // Update the file path to watch in case this is a symlink | ||
| fileToWatch, err = filepath.EvalSymlinks(fileToWatch) | ||
| if err != nil { | ||
| return | ||
| } | ||
| klog.Infof("Watching file, %s", fileToWatch) | ||
|
|
||
| // Start the file watcher to monitor file changes | ||
| go func() { | ||
| err := checkForFileChanges(fileToWatch) | ||
| klog.Errorf("Error checking for file changes: %v", err) | ||
| }() | ||
| }) | ||
| return err | ||
| } | ||
|
|
||
| // checkForFileChanges starts a new file watcher. If the file is changed, the pod running this function will exit. | ||
| func checkForFileChanges(path string) error { | ||
| watcher, err := fsnotify.NewWatcher() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| go func() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you run checkForFileChanges as a go routine but it starts one inside with the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I didn't need the second goroutine so I removed it.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently this is needed. The pod does not restart when I removed this. |
||
| for { | ||
| select { | ||
| case event, ok := <-watcher.Events: | ||
| if ok && (event.Has(fsnotify.Write) || event.Has(fsnotify.Chmod) || event.Has(fsnotify.Remove)) { | ||
| klog.Infof("file, %s, was modified, exiting...", event.Name) | ||
| os.Exit(0) | ||
| } | ||
| case err, ok := <-watcher.Errors: | ||
| if ok { | ||
| klog.Errorf("file watcher error: %v", err) | ||
| } | ||
| } | ||
| } | ||
| }() | ||
|
|
||
| err = watcher.Add(path) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.