Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove --watch mode #585

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion doc/ko_apply.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ ko apply -f FILENAME [flags]
--token string Bearer token for authentication to the API server (DEPRECATED)
--user string The name of the kubeconfig user to use (DEPRECATED)
--username string Username for basic authentication to the API server (DEPRECATED)
-W, --watch Continuously monitor the transitive dependencies of the passed yaml files, and redeploy whenever anything changes. (DEPRECATED)
```

### Options inherited from parent commands
Expand Down
1 change: 0 additions & 1 deletion doc/ko_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ ko create -f FILENAME [flags]
--token string Bearer token for authentication to the API server (DEPRECATED)
--user string The name of the kubeconfig user to use (DEPRECATED)
--username string Username for basic authentication to the API server (DEPRECATED)
-W, --watch Continuously monitor the transitive dependencies of the passed yaml files, and redeploy whenever anything changes. (DEPRECATED)
```

### Options inherited from parent commands
Expand Down
1 change: 0 additions & 1 deletion doc/ko_resolve.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ ko resolve -f FILENAME [flags]
--tag-only Include tags but not digests in resolved image references. Useful when digests are not preserved when images are repopulated.
-t, --tags strings Which tags to use for the produced image instead of the default 'latest' tag (may not work properly with --base-import-paths or --bare). (default [latest])
--tarball string File to save images tarballs
-W, --watch Continuously monitor the transitive dependencies of the passed yaml files, and redeploy whenever anything changes. (DEPRECATED)
```

### Options inherited from parent commands
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ require (
github.com/containerd/stargz-snapshotter/estargz v0.11.1
github.com/docker/docker v20.10.12+incompatible
github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960
github.com/fsnotify/fsnotify v1.5.1
github.com/go-training/helloworld v0.0.0-20200225145412-ba5f4379d78b
github.com/google/go-cmp v0.5.7
github.com/google/go-containerregistry v0.8.1-0.20220209165246-a44adc326839
github.com/mattmoor/dep-notify v0.0.0-20190205035814-a45dec370a17
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198
github.com/sigstore/cosign v1.3.2-0.20211120003522-90e2dcfe7b92
github.com/spf13/cobra v1.3.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1310,8 +1310,6 @@ github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kN
github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho=
github.com/matoous/godox v0.0.0-20210227103229-6504466cf951/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mattmoor/dep-notify v0.0.0-20190205035814-a45dec370a17 h1:P91eDVgVzvF2EmA6fmGCyR2VQFlmo2nsmS2DbHoGAco=
github.com/mattmoor/dep-notify v0.0.0-20190205035814-a45dec370a17/go.mod h1:qWnF4u+oS4UWOZMwZcBQXrt5IQIdWc6XVJLDdxGIfdQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down
55 changes: 0 additions & 55 deletions pkg/commands/options/filestuff.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,13 @@ import (
"os"
"path/filepath"

"github.com/fsnotify/fsnotify"
"github.com/spf13/cobra"
)

const deprecation412 = `NOTICE!
-----------------------------------------------------------------
Watch mode is deprecated and unsupported, and will be removed in
a future release.

For more information see:
https://github.com/google/ko/issues/412
-----------------------------------------------------------------
`

// FilenameOptions is from pkg/kubectl.
type FilenameOptions struct {
Filenames []string
Recursive bool
Watch bool
}

func AddFileArg(cmd *cobra.Command, fo *FilenameOptions) {
Expand All @@ -46,8 +34,6 @@ func AddFileArg(cmd *cobra.Command, fo *FilenameOptions) {
"Filename, directory, or URL to files to use to create the resource")
cmd.Flags().BoolVarP(&fo.Recursive, "recursive", "R", fo.Recursive,
"Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.")
cmd.Flags().BoolVarP(&fo.Watch, "watch", "W", fo.Watch,
"Continuously monitor the transitive dependencies of the passed yaml files, and redeploy whenever anything changes. (DEPRECATED)")
}

// Based heavily on pkg/kubectl
Expand All @@ -56,19 +42,6 @@ func EnumerateFiles(fo *FilenameOptions) chan string {
go func() {
// When we're done enumerating files, close the channel
defer close(files)
// When we are in --watch mode, we set up watches on the filesystem locations
// that we are supplied and continuously stream files, until we are sent an
// interrupt.
var watcher *fsnotify.Watcher
if fo.Watch {
log.Print(deprecation412)
var err error
watcher, err = fsnotify.NewWatcher()
if err != nil {
log.Fatalf("Unexpected error initializing fsnotify: %v", err)
}
defer watcher.Close()
}
for _, paths := range fo.Filenames {
// Just pass through '-' as it is indicative of stdin.
if paths == "-" {
Expand All @@ -90,9 +63,6 @@ func EnumerateFiles(fo *FilenameOptions) chan string {
if path != paths && !fo.Recursive {
return filepath.SkipDir
}
if watcher != nil {
watcher.Add(path)
}
// We don't stream back directories, we just decide to skip them, or not.
return nil
}
Expand All @@ -105,14 +75,6 @@ func EnumerateFiles(fo *FilenameOptions) chan string {
default:
return nil
}
// We weren't passed this explicitly, so elide the watch as we
// are already watching the directory.
} else {
// We were passed this directly, and so we may not be watching the
// directory, so watch this file explicitly.
if watcher != nil {
watcher.Add(path)
}
}

files <- path
Expand All @@ -122,23 +84,6 @@ func EnumerateFiles(fo *FilenameOptions) chan string {
log.Fatalf("Error enumerating files: %v", err)
}
}

// We're done watching the files we were passed and setting up watches.
// Now listen for change events from the watches we set up and resend
// files that change as if we just saw them (so they can be reprocessed).
if watcher != nil {
for {
select {
case event := <-watcher.Events:
switch filepath.Ext(event.Name) {
case ".json", ".yaml":
files <- event.Name
}
case err := <-watcher.Errors:
log.Fatalf("Error watching: %v", err)
}
}
}
}()
return files
}
64 changes: 1 addition & 63 deletions pkg/commands/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path"
"strings"
"sync"

"github.com/google/go-containerregistry/pkg/name"
"github.com/mattmoor/dep-notify/pkg/graph"
"golang.org/x/sync/errgroup"
"gopkg.in/yaml.v3"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -150,9 +148,6 @@ func makeBuilder(ctx context.Context, bo *options.BuildOptions) (*build.Caching,
// - if a valid Build future exists at the time of the request,
// then block on it.
// - if it does not, then initiate and record a Build future.
// - When import paths are "affected" by filesystem changes during a
// Watch, then invalidate their build futures *before* we put the
// affected yaml files onto the channel
//
// This will benefit the following key cases:
// 1. When the same import path is referenced across multiple yaml files
Expand Down Expand Up @@ -295,38 +290,6 @@ func resolveFilesToWriter(
// This tracks filename -> []importpath
var sm sync.Map

var g graph.Interface
var errCh chan error
var err error
if fo.Watch {
// Start a dep-notify process that on notifications scans the
// file-to-recorded-build map and for each affected file resends
// the filename along the channel.
g, errCh, err = graph.New(func(ss graph.StringSet) {
sm.Range(func(k, v interface{}) bool {
key := k.(string)
value := v.([]string)

for _, ip := range value {
// dep-notify doesn't understand the ko:// prefix
ip := strings.TrimPrefix(ip, build.StrictScheme)
if ss.Has(ip) {
// See the comment above about how "builder" works.
// Always use ko:// for the builder.
builder.Invalidate(build.StrictScheme + ip)
fs <- key
}
}
return true
})
})
if err != nil {
return fmt.Errorf("creating dep-notify graph: %w", err)
}
// Cleanup the fsnotify hooks when we're done.
defer g.Shutdown()
}

// This tracks resolution errors and ensures we cancel other builds if an
// individual build fails.
errs, ctx := errgroup.WithContext(ctx)
Expand Down Expand Up @@ -376,33 +339,11 @@ func resolveFilesToWriter(
if err != nil {
// This error is sometimes expected during watch mode, so this
// isn't fatal. Just print it and keep the watch open.
err := fmt.Errorf("error processing import paths in %q: %w", f, err)
if fo.Watch {
log.Print(err)
return nil
}
return err
return fmt.Errorf("error processing import paths in %q: %w", f, err)
}
// Associate with this file the collection of binary import paths.
sm.Store(f, recordingBuilder.ImportPaths)
ch <- b
if fo.Watch {
for _, ip := range recordingBuilder.ImportPaths {
// dep-notify doesn't understand the ko:// prefix
ip := strings.TrimPrefix(ip, build.StrictScheme)

// Technically we never remove binary targets from the graph,
// which will increase our graph's watch load, but the
// notifications that they change will result in no affected
// yamls, and no new builds or deploys.
if err := g.Add(ip); err != nil {
// If we're in watch mode, just fail.
err := fmt.Errorf("adding importpath %q to dep graph: %w", ip, err)
errCh <- err
return err
}
}
}
return nil
})

Expand All @@ -418,9 +359,6 @@ func resolveFilesToWriter(
// be applied.
out.Write(append(b, []byte("\n---\n")...))
}

case err := <-errCh:
return fmt.Errorf("watching dependencies: %w", err)
}
}

Expand Down
Loading