Skip to content
This repository was archived by the owner on May 3, 2022. It is now read-only.

Release controller exposes executor problems fixes #174 #178

Merged
merged 1 commit into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/conditions/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
FetchReleaseFailed = "FetchReleaseFailed"
BrokenReleaseGeneration = "BrokenReleaseGeneration"
BrokenApplicationObservedGeneration = "BrokenApplicationObservedGeneration"
StrategyExecutionFailed = "StrategyExecutionFailed"

ChartError = "ChartError"
ClientError = "ClientError"
Expand Down
14 changes: 14 additions & 0 deletions pkg/controller/release/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
"k8s.io/klog"

shipper "github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1"
"github.com/bookingcom/shipper/pkg/conditions"
shippercontroller "github.com/bookingcom/shipper/pkg/controller"
shippererrors "github.com/bookingcom/shipper/pkg/errors"
apputil "github.com/bookingcom/shipper/pkg/util/application"
releaseutil "github.com/bookingcom/shipper/pkg/util/release"
)

Expand Down Expand Up @@ -101,6 +103,18 @@ func (c *Controller) syncOneApplicationHandler(key string) error {
klog.V(4).Infof("Executing the strategy on Application %q", key)
patches, transitions, err := strategyExecutor.Execute()
if err != nil {
releaseSyncedCond := apputil.NewApplicationCondition(
shipper.ApplicationConditionTypeReleaseSynced,
corev1.ConditionFalse,
conditions.StrategyExecutionFailed,
fmt.Sprintf("failed to execute application strategy: %q", err),
)
apputil.SetApplicationCondition(&app.Status, *releaseSyncedCond)
_, err = c.clientset.ShipperV1alpha1().Applications(app.Namespace).Update(app)
if err != nil {
return shippererrors.NewKubeclientUpdateError(app, err).
WithShipperKind("Application")
}
return err
}

Expand Down
73 changes: 73 additions & 0 deletions pkg/controller/release/release_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import (
shipperinformers "github.com/bookingcom/shipper/pkg/client/informers/externalversions"
"github.com/bookingcom/shipper/pkg/conditions"
shippertesting "github.com/bookingcom/shipper/pkg/testing"
apputil "github.com/bookingcom/shipper/pkg/util/application"
releaseutil "github.com/bookingcom/shipper/pkg/util/release"
"github.com/bookingcom/shipper/pkg/util/replicas"
)

func init() {
apputil.ConditionsShouldDiscardTimestamps = true
releaseutil.ConditionsShouldDiscardTimestamps = true
conditions.StrategyConditionsShouldDiscardTimestamps = true
}
Expand Down Expand Up @@ -2419,6 +2421,77 @@ func TestContenderReleaseIsInstalled(t *testing.T) {
}
}

func TestApplicationExposesStrategyFailure(t *testing.T) {
namespace := "test-namespace"
incumbentName, contenderName := "test-incumbent", "test-contender"
app := buildApplication(namespace, "test-app")

cluster := buildCluster("minikube")

f := newFixture(t, app.DeepCopy(), cluster.DeepCopy())

totalReplicaCount := int32(1)
contender := f.buildContender(namespace, contenderName, totalReplicaCount)
incumbent := f.buildIncumbent(namespace, incumbentName, totalReplicaCount)

expectedApp := app.DeepCopy()
expectedApp.Status.Conditions = []shipper.ApplicationCondition{
{
Type: shipper.ApplicationConditionTypeReleaseSynced,
Status: corev1.ConditionFalse,
Reason: conditions.StrategyExecutionFailed,
Message: fmt.Sprintf("failed to execute application strategy: \"no step 2 in strategy for Release \\\"%s/%s\\\"\"", contender.release.Namespace, contender.release.Name),
},
}

contender.release.Annotations[shipper.ReleaseClustersAnnotation] = cluster.GetName()
cond := releaseutil.NewReleaseCondition(shipper.ReleaseConditionTypeScheduled, corev1.ConditionTrue, "", "")
releaseutil.SetReleaseCondition(&contender.release.Status, *cond)

// We define 2 steps and will intentionally set target step index out of this bound
strategy := shipper.RolloutStrategy{
Steps: []shipper.RolloutStrategyStep{
{
Name: "staging",
Capacity: shipper.RolloutStrategyStepValue{Incumbent: 100, Contender: 1},
Traffic: shipper.RolloutStrategyStepValue{Incumbent: 100, Contender: 0},
},
{
Name: "full on",
Capacity: shipper.RolloutStrategyStepValue{Incumbent: 0, Contender: 100},
Traffic: shipper.RolloutStrategyStepValue{Incumbent: 0, Contender: 100},
},
},
}

contender.release.Spec.Environment.Strategy = &strategy
contender.release.Spec.TargetStep = 2 // out of bound index

f.addObjects(
contender.release.DeepCopy(),
contender.installationTarget.DeepCopy(),
contender.capacityTarget.DeepCopy(),
contender.trafficTarget.DeepCopy(),

incumbent.release.DeepCopy(),
incumbent.installationTarget.DeepCopy(),
incumbent.capacityTarget.DeepCopy(),
incumbent.trafficTarget.DeepCopy(),
)

f.actions = append(f.actions, kubetesting.NewUpdateAction(
shipper.SchemeGroupVersion.WithResource("applications"),
app.GetNamespace(),
expectedApp))

f.filter = f.filter.Extend(actionfilter{
[]string{"update"},
[]string{"applications"},
})

f.run()
}

func workingOnContenderCapacity(percent int, wg *sync.WaitGroup, t *testing.T) {
namespace := "test-namespace"
incumbentName, contenderName := "test-incumbent", "test-contender"
Expand Down