Skip to content

Commit

Permalink
Merge pull request GoogleContainerTools#2815 from dgageot/simplify-dodev
Browse files Browse the repository at this point in the history
Simplify doDev()
  • Loading branch information
balopat authored Sep 6, 2019
2 parents d331e4b + efe903b commit a977c83
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions pkg/skaffold/runner/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,30 @@ import (
var ErrorConfigurationChanged = errors.New("configuration changed")

func (r *SkaffoldRunner) doDev(ctx context.Context, out io.Writer) error {
actionPerformed := false
if r.changeSet.needsReload {
return ErrorConfigurationChanged
}

// acquire the intents
buildIntent, syncIntent, deployIntent := r.intents.GetIntents()

if (r.changeSet.needsRedeploy && deployIntent) ||
(len(r.changeSet.needsRebuild) > 0 && buildIntent) ||
(len(r.changeSet.needsResync) > 0 && syncIntent) {
r.logger.Mute()
// if any action is going to be performed, reset the monitor's changed component tracker for debouncing
defer r.monitor.Reset()
defer r.listener.LogWatchToUser(out)
needsSync := syncIntent && len(r.changeSet.needsResync) > 0
needsBuild := buildIntent && len(r.changeSet.needsRebuild) > 0
needsDeploy := deployIntent && r.changeSet.needsRedeploy
if !needsSync && !needsBuild && !needsDeploy {
return nil
}

r.logger.Mute()
// if any action is going to be performed, reset the monitor's changed component tracker for debouncing
defer r.monitor.Reset()
defer r.listener.LogWatchToUser(out)

switch {
case r.changeSet.needsReload:
r.changeSet.resetReload()
return ErrorConfigurationChanged
case len(r.changeSet.needsResync) > 0 && syncIntent:
case needsSync:
defer func() {
r.changeSet.resetSync()
r.intents.resetSync()
}()
actionPerformed = true

for _, s := range r.changeSet.needsResync {
color.Default.Fprintf(out, "Syncing %d files for %s\n", len(s.Copy)+len(s.Delete), s.Image)

Expand All @@ -67,45 +67,41 @@ func (r *SkaffoldRunner) doDev(ctx context.Context, out io.Writer) error {
return nil
}
}
case len(r.changeSet.needsRebuild) > 0 && buildIntent:

case needsBuild:
defer func() {
r.changeSet.resetBuild()
r.intents.resetBuild()
}()
// this linter apparently doesn't understand fallthroughs
//nolint:ineffassign
actionPerformed = true

if _, err := r.BuildAndTest(ctx, out, r.changeSet.needsRebuild); err != nil {
r.changeSet.reset()
logrus.Warnln("Skipping deploy due to error:", err)
return nil
}
r.changeSet.needsRedeploy = true
fallthrough // always try a redeploy after a successful build
case r.changeSet.needsRedeploy && deployIntent:
if !deployIntent {
// in case we fell through, but haven't received the go ahead to deploy
r.logger.Unmute()
return nil
break
}
actionPerformed = true
r.forwarderManager.Stop()
fallthrough // redeploy after a successful build

case needsDeploy:
defer func() {
r.changeSet.reset()
r.intents.resetDeploy()
}()

r.forwarderManager.Stop()
if err := r.Deploy(ctx, out, r.builds); err != nil {
logrus.Warnln("Skipping deploy due to error:", err)
return nil
}
if err := r.forwarderManager.Start(ctx); err != nil {
logrus.Warnln("Port forwarding failed due to error:", err)
logrus.Warnln("Port forwarding failed:", err)
}
}

if actionPerformed {
r.logger.Unmute()
}
r.logger.Unmute()
return nil
}

Expand Down

0 comments on commit a977c83

Please sign in to comment.