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

Commit

Permalink
Return partial mismatches in result
Browse files Browse the repository at this point in the history
This means that the result is a Success but it still contains the error.
  • Loading branch information
rndstr committed Jul 12, 2018
1 parent a0d93a2 commit 38071a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 4 additions & 2 deletions release/releaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package release

import (
"encoding/json"
"fmt"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -612,6 +613,7 @@ func Test_UpdateContainers(t *testing.T) {
Expected: map[bool]update.ControllerResult{
true: {
Status: update.ReleaseStatusSuccess,
Error: fmt.Sprintf(update.ContainerTagMismatch, helloContainer),
PerContainer: []update.ContainerUpdate{
{
Container: sidecarContainer,
Expand All @@ -623,7 +625,7 @@ func Test_UpdateContainers(t *testing.T) {
false: {}, // Errors.
},
Commit: map[bool]string{
true: "Release containers\n\ndefault:deployment/helloworld\n- weaveworks/sidecar:master-a000002\n",
true: "Release containers\n\ndefault:deployment/helloworld\n- weaveworks/sidecar:master-a000002\n",
},
},
{
Expand All @@ -641,7 +643,7 @@ func Test_UpdateContainers(t *testing.T) {
},
},
Expected: map[bool]update.ControllerResult{
true: {}, // Errors.
true: {}, // Errors.
false: {}, // Errors.
},
},
Expand Down
21 changes: 17 additions & 4 deletions update/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,44 @@ func (s ContainerSpecs) controllerUpdates(results Result, all []*ControllerUpdat

mismatchError := fmt.Sprintf(ContainerTagMismatch, strings.Join(mismatch, ", "))

var rerr string
skippedMismatches := s.SkipMismatches && len(mismatch) > 0
switch {
case len(notfound) > 0:
// Always fail if container disappeared or was misspelled
results[u.ResourceID] = ControllerResult{
Status: ReleaseStatusFailed,
Error: fmt.Sprintf(ContainerNotFound, strings.Join(notfound, ", ")),
}
case !s.SkipMismatches && len(mismatch) > 0:
// Only fail if we do not skip for mismatches. Otherwise we either succeed
// with partial updates or then mark it as skipped because no precondition
// fulfilled.
results[u.ResourceID] = ControllerResult{
Status: ReleaseStatusFailed,
Error: mismatchError,
}
case len(containerUpdates) == 0:
err := ImageUpToDate
if s.SkipMismatches && len(mismatch) > 0 {
err = mismatchError
rerr = ImageUpToDate
if skippedMismatches {
rerr = mismatchError
}
results[u.ResourceID] = ControllerResult{
Status: ReleaseStatusSkipped,
Error: err,
Error: rerr,
}
default:
rerr = ""
if skippedMismatches {
// While we succeed here, we still want the client to know that some
// container mismatched.
rerr = mismatchError
}
u.Updates = containerUpdates
updates = append(updates, u)
results[u.ResourceID] = ControllerResult{
Status: ReleaseStatusSuccess,
Error: rerr,
PerContainer: u.Updates,
}
}
Expand Down

0 comments on commit 38071a9

Please sign in to comment.