diff --git a/release/errors.go b/release/errors.go index 5348a83f8..314bc1516 100644 --- a/release/errors.go +++ b/release/errors.go @@ -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 diff --git a/release/releaser.go b/release/releaser.go index 47b679a45..e54f3bc39 100644 --- a/release/releaser.go +++ b/release/releaser.go @@ -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" @@ -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 } @@ -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) @@ -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) @@ -98,23 +106,22 @@ 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 @@ -122,7 +129,7 @@ func VerifyChanges(before map[string]resource.Resource, updates []*update.Contro 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