Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Nov 6, 2018
1 parent ee79ab8 commit 7f0d914
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 9 additions & 13 deletions pkg/skaffold/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,13 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*la
// Create watcher and register artifacts to build current state of files.
changed := changes{}
onChange := func() error {
hasError := true

logger.Mute()
defer func() {
changed.reset()
r.Trigger.WatchForChanges(out)
if !hasError {
logger.Unmute()
}
}()

logger.Mute()

for _, a := range changed.dirtyArtifacts {
s, err := sync.NewItem(a.artifact, a.events, r.builds)
if err != nil {
Expand All @@ -290,23 +287,23 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*la
color.Default.Fprintf(out, "Syncing %d files for %s\n", len(s.Copy)+len(s.Delete), s.Image)

if err := r.Syncer.Sync(ctx, s); err != nil {
logrus.Warnln("Skipping build and deploy due to sync error:", err)
logrus.Warnln("Skipping deploy due to sync error:", err)
return nil
}
}
case len(changed.needsRebuild) > 0:
if err := r.buildTestDeploy(ctx, out, changed.needsRebuild); err != nil {
logrus.Warnln("Skipping deploy due to errors:", err)
logrus.Warnln("Skipping deploy due to error:", err)
return nil
}
case changed.needsRedeploy:
if _, err := r.Deploy(ctx, out, r.builds); err != nil {
logrus.Warnln("Skipping Deploy due to error:", err)
logrus.Warnln("Skipping deploy due to error:", err)
return nil
}
}

hasError = false
logger.Unmute()
return nil
}

Expand All @@ -315,7 +312,6 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*la
// Watch artifacts
for i := range artifacts {
artifact := artifacts[i]

if !r.shouldWatch(artifact) {
continue
}
Expand All @@ -330,15 +326,15 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*la

// Watch test configuration
if err := watcher.Register(
func() ([]string, error) { return r.TestDependencies() },
r.TestDependencies,
func(watch.Events) { changed.needsRedeploy = true },
); err != nil {
return nil, errors.Wrap(err, "watching test files")
}

// Watch deployment configuration
if err := watcher.Register(
func() ([]string, error) { return r.Dependencies() },
r.Dependencies,
func(watch.Events) { changed.needsRedeploy = true },
); err != nil {
return nil, errors.Wrap(err, "watching files for deployer")
Expand Down
2 changes: 2 additions & 0 deletions pkg/skaffold/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ func TestDev(t *testing.T) {
builder: &TestBuilder{
errors: []error{errors.New("")},
},
tester: &TestTester{},
deployer: &TestDeployer{},
watcherFactory: NewWatcherFactory(nil, nil),
shouldErr: true,
Expand All @@ -354,6 +355,7 @@ func TestDev(t *testing.T) {
tester: &TestTester{
errors: []error{errors.New("")},
},
deployer: &TestDeployer{},
watcherFactory: NewWatcherFactory(nil, nil),
shouldErr: true,
},
Expand Down

0 comments on commit 7f0d914

Please sign in to comment.