Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Mark verification failures as such
Browse files Browse the repository at this point in the history
  • Loading branch information
squaremo committed May 24, 2018
1 parent 5465716 commit ea14a1f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion release/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ deal with. See
for those limitations.
If your files appear to meet the requirements, it may simply be a bug
in Flux. PLease report it at
in Flux. Please report it at
/~https://github.com/weaveworks/flux/issues
Expand Down
39 changes: 23 additions & 16 deletions release/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/go-kit/kit/log"
"github.com/pkg/errors"

"github.com/weaveworks/flux/resource"
"github.com/weaveworks/flux/update"
Expand Down Expand Up @@ -37,15 +38,18 @@ func Release(rc *ReleaseContext, changes Changes, logger log.Logger) (results up
}

err = ApplyChanges(rc, updates, logger)
if err == nil {
var after map[string]resource.Resource
after, err = rc.manifests.LoadManifests(rc.repo.Dir(), rc.repo.ManifestDir())
if err == nil {
err = VerifyChanges(before, updates, after)
}
if err != nil {
return results, MakeReleaseError(errors.Wrap(err, "applying changes"))
}

after, err := rc.manifests.LoadManifests(rc.repo.Dir(), rc.repo.ManifestDir())
if err != nil {
err = MakeReleaseError(err)
return results, MakeReleaseError(errors.Wrap(err, "loading resources after updates"))
}

err = VerifyChanges(before, updates, after)
if err != nil {
return results, MakeReleaseError(errors.Wrap(err, "verifying changes"))
}
return results, err
}
Expand All @@ -70,14 +74,18 @@ func VerifyChanges(before map[string]resource.Resource, updates []*update.Contro
timer := update.NewStageTimer("verify_changes")
defer timer.ObserveDuration()

verificationError := func(msg string, args ...interface{}) error {
return errors.Wrap(fmt.Errorf(msg, args...), "failed to verify changes")
}

for _, update := range updates {
res, ok := before[update.ResourceID.String()]
if !ok {
return fmt.Errorf("resource %q mentioned in update not found in resources", update.ResourceID.String())
return verificationError("resource %q mentioned in update not found in resources", update.ResourceID.String())
}
wl, ok := res.(resource.Workload)
if !ok {
return fmt.Errorf("resource %q mentioned in update is not a workload", update.ResourceID.String())
return verificationError("resource %q mentioned in update is not a workload", update.ResourceID.String())
}
for _, containerUpdate := range update.Updates {
wl.SetContainerImage(containerUpdate.Container, containerUpdate.Target)
Expand All @@ -87,7 +95,7 @@ func VerifyChanges(before map[string]resource.Resource, updates []*update.Contro
for id, afterRes := range after {
beforeRes, ok := before[id]
if !ok {
return fmt.Errorf("resource %q is new after update")
return verificationError("resource %q is new after update")
}
delete(before, id)

Expand All @@ -98,31 +106,30 @@ func VerifyChanges(before map[string]resource.Resource, updates []*update.Contro
}
afterWorkload, ok := afterRes.(resource.Workload)
if !ok {
return fmt.Errorf("resource %q is no longer a workload (Deployment or DaemonSet, or similar) after update", id)
return verificationError("resource %q is no longer a workload (Deployment or DaemonSet, or similar) after update", id)
}

beforeContainers := beforeWorkload.Containers()
afterContainers := afterWorkload.Containers()
if len(beforeContainers) != len(afterContainers) {
return fmt.Errorf("resource %q has different set of containers after update", id)
return verificationError("resource %q has different set of containers after update", id)
}
for i := range afterContainers {
if beforeContainers[i].Name != afterContainers[i].Name {
return fmt.Errorf("Container in position %d of resource %q has a different name after update: was %q, now %q", i, id, beforeContainers[i].Name, afterContainers[i].Name)
return verificationError("container in position %d of resource %q has a different name after update: was %q, now %q", i, id, beforeContainers[i].Name, afterContainers[i].Name)
}
if beforeContainers[i].Image != afterContainers[i].Image {
return fmt.Errorf("The image for container %q in resource %q should be %q, but is %q", beforeContainers[i].Name, id, beforeContainers[i].Image.String(), afterContainers[i].Image.String())
return verificationError("the image for container %q in resource %q should be %q, but is %q", beforeContainers[i].Name, id, beforeContainers[i].Image.String(), afterContainers[i].Image.String())
}
}

}

var disappeared []string
for id := range before {
disappeared = append(disappeared, fmt.Sprintf("%q", id))
}
if len(disappeared) > 0 {
return fmt.Errorf("resources {%s} present before update but not after", strings.Join(disappeared, ", "))
return verificationError("resources {%s} present before update but not after", strings.Join(disappeared, ", "))
}

return nil
Expand Down

0 comments on commit ea14a1f

Please sign in to comment.