-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Client Cert Auth for ARO HCP deployments
Use Client Certificate Authentication for ARO HCP deployments. HyperShift will pass the needed environment variables for this authentication method: ARO_HCP_MI_CLIENT_ID, ARO_HCP_TENANT_ID, and ARO_HCP_CLIENT_CERTIFICATE_PATH. Signed-off-by: Bryan Cox <[email protected]>
- Loading branch information
Showing
3 changed files
with
104 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package filewatcher | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/fsnotify/fsnotify" | ||
logf "github.com/openshift/cluster-ingress-operator/pkg/log" | ||
) | ||
|
||
var log = logf.Logger.WithName("filewatcher") | ||
|
||
// 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 { | ||
log.Info("Starting the file change watcher") | ||
|
||
// Update the file path to watch in case this is a symlink | ||
fileToWatch, err := filepath.EvalSymlinks(fileToWatch) | ||
if err != nil { | ||
return err | ||
} | ||
log.Info("Watching file", "file", fileToWatch) | ||
|
||
// Start the file watcher to monitor file changes | ||
go func() { | ||
if err := checkForFileChanges(fileToWatch); err != nil { | ||
log.Error(err, "Error checking for file changes") | ||
} | ||
}() | ||
|
||
return nil | ||
} | ||
|
||
// 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() { | ||
for { | ||
select { | ||
case event, ok := <-watcher.Events: | ||
if ok && (event.Has(fsnotify.Write) || event.Has(fsnotify.Chmod) || event.Has(fsnotify.Remove)) { | ||
log.Info("file was modified, exiting...", "file", event.Name) | ||
os.Exit(0) | ||
} | ||
case err, ok := <-watcher.Errors: | ||
if ok { | ||
log.Error(err, "file watcher error") | ||
} else { | ||
log.Error(err, "failed to retrieve watcher error") | ||
} | ||
} | ||
} | ||
}() | ||
|
||
if err = watcher.Add(path); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |