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

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
- Renames `IgnoreFailedController` to `IgnoreMismatches`
- IgnoreMismatches now ignores any non-matching spec (also if controller
  cannot be found)
- Allows empty image spec `Current` value to disable precondition check
  • Loading branch information
rndstr committed Jul 11, 2018
1 parent e160b8a commit 37268d2
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 119 deletions.
188 changes: 101 additions & 87 deletions release/releaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package release

import (
"encoding/json"
"fmt"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -532,62 +531,6 @@ func Test_UpdateList(t *testing.T) {
}
}

func Test_UpdateContainers_someFail(t *testing.T) {
cluster := mockCluster(hwSvc, testSvc)
checkout, cleanup := setup(t)
defer cleanup()

ctx := &ReleaseContext{
cluster: cluster,
manifests: mockManifests,
repo: checkout,
registry: mockRegistry,
}
spec := update.ContainerSpecs{
ContainerSpecs: map[flux.ResourceID][]update.ContainerUpdate{
hwSvcID: { // success
{
Container: helloContainer,
Current: oldRef,
Target: newHwRef,
},
},
testSvcID: { // fail
{
Container: testContainer,
Current: oldRef,
Target: oldRef,
},
},
},
Kind: update.ReleaseKindExecute,
}

_, err := Release(ctx, spec, log.NewNopLogger())
assert.Error(t, err)

spec.IgnoreFailedControllers = true
results, err := Release(ctx, spec, log.NewNopLogger())
assert.NoError(t, err)

expected := update.Result{
hwSvcID: update.ControllerResult{
Status: update.ReleaseStatusSuccess,
PerContainer: []update.ContainerUpdate{{
Container: helloContainer,
Current: oldRef,
Target: newHwRef,
}},
},
testSvcID: update.ControllerResult{
Status: update.ReleaseStatusFailed,
Error: fmt.Sprintf(update.ContainerTagMismatch, testContainer),
},
}
assert.Equal(t, expected[hwSvcID], results[hwSvcID])
assert.Equal(t, expected[testSvcID], results[testSvcID])
}

func Test_UpdateContainers(t *testing.T) {
cluster := mockCluster(hwSvc, lockedSvc)
checkout, cleanup := setup(t)
Expand All @@ -599,10 +542,13 @@ func Test_UpdateContainers(t *testing.T) {
registry: mockRegistry,
}
for _, tst := range []struct {
Name string
Spec []update.ContainerUpdate
Expected update.ControllerResult
Commit string
Name string
Spec []update.ContainerUpdate

// true|false for `IgnoreMismatches`
Commit map[bool]string
Expected map[bool]update.ControllerResult
Err map[bool]error
}{
{
Name: "multiple containers",
Expand All @@ -618,19 +564,36 @@ func Test_UpdateContainers(t *testing.T) {
Target: newSidecarRef,
},
},
Expected: update.ControllerResult{
Status: update.ReleaseStatusSuccess,
PerContainer: []update.ContainerUpdate{{
Container: helloContainer,
Current: oldRef,
Target: newHwRef,
}, {
Container: sidecarContainer,
Current: sidecarRef,
Target: newSidecarRef,
}},
Expected: map[bool]update.ControllerResult{
true: {
Status: update.ReleaseStatusSuccess,
PerContainer: []update.ContainerUpdate{{
Container: helloContainer,
Current: oldRef,
Target: newHwRef,
}, {
Container: sidecarContainer,
Current: sidecarRef,
Target: newSidecarRef,
}},
},
false: {
Status: update.ReleaseStatusSuccess,
PerContainer: []update.ContainerUpdate{{
Container: helloContainer,
Current: oldRef,
Target: newHwRef,
}, {
Container: sidecarContainer,
Current: sidecarRef,
Target: newSidecarRef,
}},
},
},
Commit: map[bool]string{
true: "Release containers\n\ndefault:deployment/helloworld\n- quay.io/weaveworks/helloworld:master-a000002\n- weaveworks/sidecar:master-a000002\n",
false: "Release containers\n\ndefault:deployment/helloworld\n- quay.io/weaveworks/helloworld:master-a000002\n- weaveworks/sidecar:master-a000002\n",
},
Commit: "Release containers\n\ndefault:deployment/helloworld\n- quay.io/weaveworks/helloworld:master-a000002\n- weaveworks/sidecar:master-a000002\n",
},
{
Name: "container tag mismatch",
Expand All @@ -646,37 +609,88 @@ func Test_UpdateContainers(t *testing.T) {
Target: newSidecarRef,
},
},
Expected: update.ControllerResult{
Status: update.ReleaseStatusFailed,
Error: fmt.Sprintf(update.ContainerTagMismatch, helloContainer),
Expected: map[bool]update.ControllerResult{
true: {
Status: update.ReleaseStatusSuccess,
PerContainer: []update.ContainerUpdate{
{
Container: sidecarContainer,
Current: sidecarRef,
Target: newSidecarRef,
},
},
},
false: {}, // Errors.
},
Commit: map[bool]string{
true: "Release containers\n\ndefault:deployment/helloworld\n- weaveworks/sidecar:master-a000002\n",
},
Commit: "Release containers\n\ndefault:deployment/helloworld failed: container tag mismatch: greeter",
},
{
Name: "container not found",
Spec: []update.ContainerUpdate{
{
Container: "foo",
Container: helloContainer,
Current: oldRef,
Target: newHwRef,
},
{
Container: "foo", // not found
Current: oldRef,
Target: newHwRef,
},
},
Expected: update.ControllerResult{
Status: update.ReleaseStatusFailed,
Error: fmt.Sprintf(update.ContainerNotFound, "foo"),
Expected: map[bool]update.ControllerResult{
true: {
Status: update.ReleaseStatusSuccess,
PerContainer: []update.ContainerUpdate{
{
Container: helloContainer,
Current: oldRef,
Target: newHwRef,
},
},
},
false: {}, // Errors.
},
Commit: map[bool]string{
true: "Release containers\n\ndefault:deployment/helloworld\n- quay.io/weaveworks/helloworld:master-a000002\n",
},
},
{
Name: "no changes",
Spec: []update.ContainerUpdate{
{
Container: helloContainer,
Current: newHwRef, // mismatch
Target: newHwRef,
},
},
Expected: map[bool]update.ControllerResult{
true: {},
false: {},
},
Commit: "Release containers\n\ndefault:deployment/helloworld failed: container not found: foo",
},
} {
specs := update.ContainerSpecs{
ContainerSpecs: map[flux.ResourceID][]update.ContainerUpdate{hwSvcID: tst.Spec},
Kind: update.ReleaseKindExecute,
IgnoreFailedControllers: true,
}
results, err := Release(ctx, specs, log.NewNopLogger())
assert.NoError(t, err, tst.Name)
assert.Equal(t, tst.Expected, results[hwSvcID], tst.Name)
assert.Equal(t, tst.Commit, specs.CommitMessage(results), tst.Name)

for _, ignoreMismatches := range []bool{true, false} {
name := tst.Name
if ignoreMismatches {
name += " (IgnoreMismatches)"
}
specs.IgnoreMismatches = ignoreMismatches
results, err := Release(ctx, specs, log.NewNopLogger())
if tst.Expected[ignoreMismatches].Status != "" {
assert.Equal(t, tst.Expected[ignoreMismatches], results[hwSvcID], name)
assert.Equal(t, tst.Commit[ignoreMismatches], specs.CommitMessage(results), name)
} else {
assert.Error(t, err, name)
}
}
}
}

Expand Down
Loading

0 comments on commit 37268d2

Please sign in to comment.