Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Signed-off-by: lubronzhan <[email protected]>

Signed-off-by: lubronzhan <[email protected]>
  • Loading branch information
lubronzhan committed Feb 19, 2024
1 parent 58361f3 commit 05ade08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/contour/filewatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func initializeWatch(path string, log logrus.FieldLogger) (*fsnotify.Watcher, er
log.Warningf("watcher receives err: %v\n", err)
case event := <-watch.Events:
if event.Op != fsnotify.Chmod {
log.Fatalf("restarting contour because received event %v on file %s\n", event.Op, path)
log.Fatalf("restarting contour because received event %v on file %s\n", event.Op.String(), path)
} else {
log.Printf("watcher receives %s on the mounted file %s\n", event.Op.String(), event.Name)
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package main

import (
"context"
"errors"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -753,7 +754,7 @@ func (s *Server) doServe() error {

// Start a process to monitor the path of mounted configMap `/config`
// so that it can restart contour if the configMap gets updated.
if _, err := os.Stat(defaultConfigPath); !os.IsNotExist(err) {
if _, err := os.Stat(defaultConfigPath); err == nil {
s.log.WithField("context", "fsnotify-watcher").Infof("starting fsnotify-watcher to monitor path %s", defaultConfigPath)
watch, err := initializeWatch(defaultConfigPath, s.log.WithField("context", "fsnotify-watcher"))
if err != nil {
Expand All @@ -762,7 +763,9 @@ func (s *Server) doServe() error {
defer func(watch *fsnotify.Watcher) {
_ = watch.Close() // ignore explicitly when the watch closes
}(watch)
} else if err != nil {
} else if !errors.Is(err, os.ErrNotExist) {
// other kind of error other than file doesn't exist
s.log.WithField("context", "fsnotify-watcher").Infof("failed to check whether %s exist", defaultConfigPath)
return err
}

Expand Down

0 comments on commit 05ade08

Please sign in to comment.