Skip to content

Commit

Permalink
Merge pull request #843 from dgageot/dont-redeploy
Browse files Browse the repository at this point in the history
Don’t redeploy twice the same manifest in a dev loop
  • Loading branch information
dgageot authored Jul 25, 2018
2 parents 26f58ef + 8d303a6 commit 44b1fc6
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions pkg/skaffold/deploy/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ var warner Warner = &logrusWarner{}
type KubectlDeployer struct {
*v1alpha2.KubectlDeploy

workingDir string
kubeContext string
workingDir string
kubeContext string
previousDeployment manifestList
}

// NewKubectlDeployer returns a new KubectlDeployer for a DeployConfig filled
Expand Down Expand Up @@ -79,12 +80,18 @@ func (k *KubectlDeployer) Deploy(ctx context.Context, out io.Writer, builds []bu
return nil, errors.Wrap(err, "replacing images in manifests")
}

err = kubectl(manifests.reader(), out, k.kubeContext, k.Flags.Global, "apply", k.Flags.Apply, "-f", "-")
// Only redeploy modified or new manifests
// TODO(dgageot): should we delete a manifest that was deployed and is not anymore?
updated := k.previousDeployment.diff(manifests)
logrus.Debugln(len(manifests), "manifests to deploy.", len(manifests), "are updated or new")
k.previousDeployment = manifests

err = kubectl(updated.reader(), out, k.kubeContext, k.Flags.Global, "apply", k.Flags.Apply, "-f", "-")
if err != nil {
return nil, errors.Wrap(err, "deploying manifests")
}

return parseManifestsForDeploys(manifests)
return parseManifestsForDeploys(updated)
}

// Cleanup deletes what was deployed by calling Deploy.
Expand Down Expand Up @@ -223,6 +230,27 @@ func (l *manifestList) Empty() bool {
return len(*l) == 0
}

func (l *manifestList) diff(manifests manifestList) manifestList {
if l == nil {
return manifests
}

oldManifests := map[string]bool{}
for _, oldManifest := range *l {
oldManifests[string(oldManifest)] = true
}

var updated manifestList

for _, manifest := range manifests {
if !oldManifests[string(manifest)] {
updated = append(updated, manifest)
}
}

return updated
}

func (l *manifestList) reader() io.Reader {
return strings.NewReader(l.String())
}
Expand Down

0 comments on commit 44b1fc6

Please sign in to comment.