Skip to content

Commit

Permalink
Godoc, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pebrc committed Apr 4, 2022
1 parent befec6a commit 49064df
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 48 deletions.
76 changes: 38 additions & 38 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -305,44 +305,6 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/go-ucfg@v0.8.4/
limitations under the License.


--------------------------------------------------------------------------------
Module : github.com/fsnotify/fsnotify
Version : v1.5.1
Time : 2021-08-24T19:33:57Z
Licence : BSD-3-Clause

Contents of probable licence file $GOMODCACHE/github.com/fsnotify/fsnotify@v1.5.1/LICENSE:

Copyright (c) 2012 The Go Authors. All rights reserved.
Copyright (c) 2012-2019 fsnotify Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
Module : github.com/ghodss/yaml
Version : v1.0.0
Expand Down Expand Up @@ -6204,6 +6166,44 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


--------------------------------------------------------------------------------
Module : github.com/fsnotify/fsnotify
Version : v1.5.1
Time : 2021-08-24T19:33:57Z
Licence : BSD-3-Clause

Contents of probable licence file $GOMODCACHE/github.com/fsnotify/fsnotify@v1.5.1/LICENSE:

Copyright (c) 2012 The Go Authors. All rights reserved.
Copyright (c) 2012-2019 fsnotify Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
Module : github.com/go-logr/zapr
Version : v1.2.0
Expand Down
8 changes: 4 additions & 4 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"errors"
"fmt"
"github.com/elastic/cloud-on-k8s/pkg/utils/fs"
"net/http"
"net/http/pprof"
"os"
Expand Down Expand Up @@ -83,6 +82,7 @@ import (
"github.com/elastic/cloud-on-k8s/pkg/dev/portforward"
licensing "github.com/elastic/cloud-on-k8s/pkg/license"
"github.com/elastic/cloud-on-k8s/pkg/telemetry"
"github.com/elastic/cloud-on-k8s/pkg/utils/fs"
"github.com/elastic/cloud-on-k8s/pkg/utils/k8s"
logconf "github.com/elastic/cloud-on-k8s/pkg/utils/log"
"github.com/elastic/cloud-on-k8s/pkg/utils/metrics"
Expand Down Expand Up @@ -124,7 +124,6 @@ func Command() *cobra.Command {
if err := viper.ReadInConfig(); err != nil {
return fmt.Errorf("failed to read config file %s: %w", configFile, err)
}

}

logconf.ChangeVerbosity(viper.GetInt(logconf.FlagName))
Expand Down Expand Up @@ -340,9 +339,10 @@ func doRun(_ *cobra.Command, _ []string) error {
)
}

watcher := fs.NewFileWatcher(ctx, toWatch, func(_ []string) {
onConfChange := func(_ []string) {
confUpdateChan <- struct{}{}
}, 15*time.Second)
}
watcher := fs.NewFileWatcher(ctx, toWatch, onConfChange, 15*time.Second)
go watcher.Run()

// set up channels and context for the operator
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/dependencies.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ This page lists the third-party dependencies used to build {n}.
| link:https://github.com/blang/semver[$$github.com/blang/semver/v4$$] | v4.0.0 | MIT
| link:https://github.com/davecgh/go-spew[$$github.com/davecgh/go-spew$$] | v1.1.1 | ISC
| link:https://github.com/elastic/go-ucfg[$$github.com/elastic/go-ucfg$$] | v0.8.4 | Apache-2.0
| link:https://github.com/fsnotify/fsnotify[$$github.com/fsnotify/fsnotify$$] | v1.5.1 | BSD-3-Clause
| link:https://github.com/ghodss/yaml[$$github.com/ghodss/yaml$$] | v1.0.0 | MIT
| link:https://github.com/go-logr/logr[$$github.com/go-logr/logr$$] | v1.2.3 | Apache-2.0
| link:https://github.com/go-test/deep[$$github.com/go-test/deep$$] | v1.0.8 | MIT
Expand Down Expand Up @@ -90,6 +89,7 @@ This page lists the third-party dependencies used to build {n}.
| link:https://github.com/fatih/color[$$github.com/fatih/color$$] | v1.13.0 | MIT
| link:https://github.com/fatih/structs[$$github.com/fatih/structs$$] | v1.1.0 | MIT
| link:https://github.com/frankban/quicktest[$$github.com/frankban/quicktest$$] | v1.13.0 | MIT
| link:https://github.com/fsnotify/fsnotify[$$github.com/fsnotify/fsnotify$$] | v1.5.1 | BSD-3-Clause
| link:https://github.com/go-logr/zapr[$$github.com/go-logr/zapr$$] | v1.2.0 | Apache-2.0
| link:https://github.com/gogo/protobuf[$$github.com/gogo/protobuf$$] | v1.3.2 | BSD-3-Clause
| link:https://github.com/golang/groupcache[$$github.com/golang/groupcache$$] | v0.0.0-20210331224755-41bb18bfe9da | Apache-2.0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/blang/semver/v4 v4.0.0
github.com/davecgh/go-spew v1.1.1
github.com/elastic/go-ucfg v0.8.4
github.com/fsnotify/fsnotify v1.5.1
github.com/ghodss/yaml v1.0.0
github.com/go-logr/logr v1.2.3
github.com/go-test/deep v1.0.8
Expand Down Expand Up @@ -61,6 +60,7 @@ require (
github.com/elazarl/goproxy v0.0.0-20190711103511-473e67f1d7d2 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/zapr v1.2.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand Down
19 changes: 15 additions & 4 deletions pkg/utils/fs/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,34 @@ import (
"context"
"os"
"time"

logf "sigs.k8s.io/controller-runtime/pkg/log"
)

type fileWatcher struct {
var log = logf.Log.WithName("fs-watcher")

// FileWatcher watches a given set of file paths, not directories, for changes based on the file's mtime.
type FileWatcher struct {
ctx context.Context
onChange func([]string)
period time.Duration
cache fileModTimeCache
}

func NewFileWatcher(ctx context.Context, paths []string, onChange func([]string), period time.Duration) *fileWatcher {
return &fileWatcher{
// NewFileWatcher creates a new file watcher, use ctx context for cancellation, paths to specify the files to watch.
// onChange is a callback to be invoked when changes are detected, a list of affected files will be passed as argument.
// period determines how often the file watcher will try to detect changes to the files of interest.
func NewFileWatcher(ctx context.Context, paths []string, onChange func([]string), period time.Duration) *FileWatcher {
return &FileWatcher{
ctx: ctx,
onChange: onChange,
period: period,
cache: newFileModTimeCache(paths),
}
}

func (fw *fileWatcher) Run() {
// Run starts the file watcher. Should be typically run inside a go routine.
func (fw *FileWatcher) Run() {
ticker := time.NewTicker(fw.period)
defer ticker.Stop()
for {
Expand Down Expand Up @@ -62,6 +71,8 @@ func (fmc fileModTimeCache) Update() []string {
// file was deleted
updated = append(updated, f)
fmc[f] = time.Time{}
} else {
log.Error(err, "while getting file info", "file", f, "err", err.Error())
}
continue
}
Expand Down

0 comments on commit 49064df

Please sign in to comment.