Simplify doDev()
@@ -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()
+ 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
+ }
- 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)
- }
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)
@@ -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()
- }
return nil
}
