-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from bojand/poll_watcher
Add support for polling watcher
- Loading branch information
Showing
10 changed files
with
480 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
FROM golang:1.13.6-alpine3.11 as buildergo | ||
RUN mkdir -p /fluent-bit | ||
COPY cmd/fluent-bit-watcher/main.go go.mod /fluent-bit/ | ||
WORKDIR /fluent-bit | ||
RUN CGO_ENABLED=0 go build -i -ldflags '-w -s' -o fluent-bit main.go | ||
RUN mkdir -p /code | ||
COPY . /code/ | ||
WORKDIR /code | ||
RUN echo $(ls -al /code) | ||
RUN CGO_ENABLED=0 go build -i -ldflags '-w -s' -o /fluent-bit/fluent-bit /code/cmd/fluent-bit-watcher/main.go | ||
|
||
# FROM gcr.io/distroless/cc-debian10 | ||
FROM fluent/fluent-bit:1.8.3 | ||
MAINTAINER KubeSphere <kubesphere@yunify.com> | ||
LABEL Description="Fluent Bit docker image" Vendor="KubeSphere" Version="1.0" | ||
|
||
COPY conf/fluent-bit.conf conf/parsers.conf /fluent-bit/etc/ | ||
COPY --from=buildergo /fluent-bit/fluent-bit /fluent-bit/bin/fluent-bit-watcher | ||
|
||
# | ||
EXPOSE 2020 | ||
|
||
# Entry point | ||
CMD ["/fluent-bit/bin/fluent-bit-watcher", "-c", "/fluent-bit/etc/fluent-bit.conf"] | ||
ENTRYPOINT ["/fluent-bit/bin/fluent-bit-watcher"] |
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
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,53 @@ | ||
// Adapted from https://github.com/gohugoio/hugo | ||
// Apache License 2.0 | ||
// Copyright Hugo Authors | ||
// | ||
// Package filenotify provides a mechanism for watching file(s) for changes. | ||
// Generally leans on fsnotify, but provides a poll-based notifier which fsnotify does not support. | ||
// These are wrapped up in a common interface so that either can be used interchangeably in your code. | ||
// | ||
// This package is adapted from https://github.com/moby/moby/tree/master/pkg/filenotify, Apache-2.0 License. | ||
// Hopefully this can be replaced with an external package sometime in the future, see https://github.com/fsnotify/fsnotify/issues/9 | ||
package filenotify | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/fsnotify/fsnotify" | ||
) | ||
|
||
// FileWatcher is an interface for implementing file notification watchers | ||
type FileWatcher interface { | ||
Events() <-chan fsnotify.Event | ||
Errors() <-chan error | ||
Add(name string) error | ||
Remove(name string) error | ||
Close() error | ||
} | ||
|
||
// New tries to use an fs-event watcher, and falls back to the poller if there is an error | ||
func New(interval time.Duration) (FileWatcher, error) { | ||
if watcher, err := NewEventWatcher(); err == nil { | ||
return watcher, nil | ||
} | ||
return NewPollingWatcher(interval), nil | ||
} | ||
|
||
// NewPollingWatcher returns a poll-based file watcher | ||
func NewPollingWatcher(interval time.Duration) FileWatcher { | ||
return &filePoller{ | ||
interval: interval, | ||
done: make(chan struct{}), | ||
events: make(chan fsnotify.Event), | ||
errors: make(chan error), | ||
} | ||
} | ||
|
||
// NewEventWatcher returns an fs-event based file watcher | ||
func NewEventWatcher() (FileWatcher, error) { | ||
watcher, err := fsnotify.NewWatcher() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &fsNotifyWatcher{watcher}, nil | ||
} |
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,24 @@ | ||
// Adapted from https://github.com/gohugoio/hugo | ||
// Apache License 2.0 | ||
// Copyright Hugo Authors | ||
// | ||
// Package filenotify is adapted from https://github.com/moby/moby/tree/master/pkg/filenotify, Apache-2.0 License. | ||
// Hopefully this can be replaced with an external package sometime in the future, see https://github.com/fsnotify/fsnotify/issues/9 | ||
package filenotify | ||
|
||
import "github.com/fsnotify/fsnotify" | ||
|
||
// fsNotifyWatcher wraps the fsnotify package to satisfy the FileNotifier interface | ||
type fsNotifyWatcher struct { | ||
*fsnotify.Watcher | ||
} | ||
|
||
// Events returns the fsnotify event channel receiver | ||
func (w *fsNotifyWatcher) Events() <-chan fsnotify.Event { | ||
return w.Watcher.Events | ||
} | ||
|
||
// Errors returns the fsnotify error channel receiver | ||
func (w *fsNotifyWatcher) Errors() <-chan error { | ||
return w.Watcher.Errors | ||
} |
Oops, something went wrong.