Skip to content

Commit

Permalink
Merge pull request dapr#7272 from JoshVanL/update-kit-contrib-2023-12-05
Browse files Browse the repository at this point in the history
Updates dapr/kit and dapr/components-contrib to HEAD
  • Loading branch information
daixiang0 authored Dec 6, 2023
2 parents 99a00ea + 6e94d73 commit 9758d99
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
11 changes: 8 additions & 3 deletions cmd/sentry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,18 @@ func main() {
}

// Watch for changes in the watchDir
err = mngr.Add(func(ctx context.Context) error {
log.Infof("Starting watch on filesystem directory: %s", watchDir)
return fswatcher.Watch(ctx, watchDir, issuerEvent)
fs, err := fswatcher.New(fswatcher.Options{
Targets: []string{watchDir},
})
if err != nil {
log.Fatal(err)
}
if err = mngr.Add(func(ctx context.Context) error {
log.Infof("Starting watch on filesystem directory: %s", watchDir)
return fs.Run(ctx, issuerEvent)
}); err != nil {
log.Fatal(err)
}

// Healthz server
err = mngr.Add(func(ctx context.Context) error {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require (
github.com/argoproj/argo-rollouts v1.4.1
github.com/cenkalti/backoff/v4 v4.2.1
github.com/cloudevents/sdk-go/v2 v2.14.0
github.com/dapr/components-contrib v1.12.1-0.20231129042434-36a055ebd8d7
github.com/dapr/kit v0.12.2-0.20231031211530-0e1fd37fc4b3
github.com/dapr/components-contrib v1.12.1-0.20231204210358-79adc565c17a
github.com/dapr/kit v0.12.2-0.20231116003620-df64d3a144b3
github.com/evanphx/json-patch/v5 v5.7.0
github.com/go-chi/chi/v5 v5.0.10
github.com/go-chi/cors v1.2.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,10 @@ github.com/dancannon/gorethink v4.0.0+incompatible h1:KFV7Gha3AuqT+gr0B/eKvGhbjm
github.com/dancannon/gorethink v4.0.0+incompatible/go.mod h1:BLvkat9KmZc1efyYwhz3WnybhRZtgF1K929FD8z1avU=
github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0=
github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0=
github.com/dapr/components-contrib v1.12.1-0.20231129042434-36a055ebd8d7 h1:f0n7cuFO2OTdeLwNDsdNs7eLwfIuhKCXi/Aeh/IbYXA=
github.com/dapr/components-contrib v1.12.1-0.20231129042434-36a055ebd8d7/go.mod h1:s4vy1EFMh/9xMoeD0FvIH2D1LI3BHutzRwT1yKxGD+c=
github.com/dapr/kit v0.12.2-0.20231031211530-0e1fd37fc4b3 h1:xsmVK3YOKRMOcaxqo50Ce0apQzq+LzAfWuFapQuu8Ro=
github.com/dapr/kit v0.12.2-0.20231031211530-0e1fd37fc4b3/go.mod h1:c3Z78F+h7UYtb0LmpzJNC/ChT240ycDJFViRUztdpoo=
github.com/dapr/components-contrib v1.12.1-0.20231204210358-79adc565c17a h1:4QIQrWZwcRQR11oUTcoLddxd85xdKG9+/0xpmGCDw1Y=
github.com/dapr/components-contrib v1.12.1-0.20231204210358-79adc565c17a/go.mod h1:s4vy1EFMh/9xMoeD0FvIH2D1LI3BHutzRwT1yKxGD+c=
github.com/dapr/kit v0.12.2-0.20231116003620-df64d3a144b3 h1:fqyFPfsGznKYlqR6jWHd9ZxcedgohkOY2IkLLO4h9pk=
github.com/dapr/kit v0.12.2-0.20231116003620-df64d3a144b3/go.mod h1:c3Z78F+h7UYtb0LmpzJNC/ChT240ycDJFViRUztdpoo=
github.com/dave/jennifer v1.4.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
19 changes: 16 additions & 3 deletions pkg/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ type provider struct {
running atomic.Bool
readyCh chan struct{}
trustAnchorsFile string

// fswatcherInterval is the interval at which the trust anchors file changes
// are batched. Used for testing only, and 500ms otherwise.
fswatcherInterval time.Duration
}

// security implements the Security interface.
Expand Down Expand Up @@ -165,8 +169,9 @@ func New(ctx context.Context, opts Options) (Provider, error) {
}

return &provider{
readyCh: make(chan struct{}),
trustAnchorsFile: opts.TrustAnchorsFile,
fswatcherInterval: time.Millisecond * 500,
readyCh: make(chan struct{}),
trustAnchorsFile: opts.TrustAnchorsFile,
sec: &security{
source: source,
mtls: opts.MTLSEnabled,
Expand Down Expand Up @@ -208,10 +213,18 @@ func (p *provider) Run(ctx context.Context) error {
if len(p.trustAnchorsFile) > 0 {
caEvent := make(chan struct{})

fs, err := fswatcher.New(fswatcher.Options{
Targets: []string{filepath.Dir(p.trustAnchorsFile)},
Interval: &p.fswatcherInterval,
})
if err != nil {
return err
}

err = mngr.Add(
func(ctx context.Context) error {
log.Infof("Watching trust anchors file '%s' for changes", p.trustAnchorsFile)
return fswatcher.Watch(ctx, filepath.Dir(p.trustAnchorsFile), caEvent)
return fs.Run(ctx, caEvent)
},
func(ctx context.Context) error {
for {
Expand Down
3 changes: 3 additions & 0 deletions pkg/security/security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ func Test_Start(t *testing.T) {
})
require.NoError(t, err)

// Override the default of 500ms to 0 to speed up the test.
p.(*provider).fswatcherInterval = 0

ctx, cancel := context.WithCancel(context.Background())

providerStopped := make(chan struct{})
Expand Down

0 comments on commit 9758d99

Please sign in to comment.