Skip to content

Commit

Permalink
update wait time
Browse files Browse the repository at this point in the history
  • Loading branch information
britaniar committed Jul 18, 2024
1 parent 31a2288 commit 96165df
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 53 deletions.
17 changes: 9 additions & 8 deletions pkg/controllers/rollout/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,24 @@ func (r *Reconciler) Reconcile(ctx context.Context, req runtime.Request) (runtim
r.updateBindings(ctx, toBeUpdatedBindings)
}

// `waitForFirstAppliedButNotReadyBinding` returns the minimum amount of time that needs to elapse before the first
// waitForFirstAppliedButNotReadyBinding returns the minimum amount of time that needs to elapse before the first
// binding that has been applied but not yet marked as ready becomes ready.
func waitForFirstAppliedButNotReadyBinding(bindings []*fleetv1beta1.ClusterResourceBinding, readyTimeCutOff time.Time) time.Duration {
minValue := time.Duration(math.MaxInt64)
minWaitTime := time.Duration(math.MaxInt64)
for _, binding := range bindings {
appliedCondition := binding.GetCondition(string(fleetv1beta1.ResourceBindingApplied))
if condition.IsConditionStatusTrue(appliedCondition, binding.Generation) {
waitTime, bindingReady := isBindingReady(binding, readyTimeCutOff)
if !bindingReady {
if waitTime < minValue {
minValue = waitTime
}
if !bindingReady && waitTime < minWaitTime && waitTime >= 0 {
minWaitTime = waitTime
}
}
}
klog.V(2).InfoS("Picked the first applied but ready binding", "waitTime", minValue)
return minValue * time.Second
if minWaitTime == time.Duration(math.MaxInt64) {
return 0
}
klog.V(2).InfoS("Selected the first applied but not ready binding", "waitTime", minWaitTime)
return minWaitTime
}

func (r *Reconciler) checkAndUpdateStaleBindingsStatus(ctx context.Context, bindings []*fleetv1beta1.ClusterResourceBinding) error {
Expand Down
90 changes: 45 additions & 45 deletions pkg/controllers/rollout/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package rollout
import (
"context"
"errors"
"math"
"testing"
"time"

Expand Down Expand Up @@ -736,154 +735,155 @@ func TestWaitForFirstAppliedButNotReadyBinding(t *testing.T) {
"all bindings ready": {
bindings: []*fleetv1beta1.ClusterResourceBinding{
{
ObjectMeta: metav1.ObjectMeta{
Generation: 1,
},
Status: fleetv1beta1.ResourceBindingStatus{
Conditions: []metav1.Condition{
{
Type: string(fleetv1beta1.ResourceBindingApplied),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
Reason: "any",
},
{
Type: string(fleetv1beta1.ResourceBindingAvailable),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
Reason: "any",
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Generation: 1,
},
Status: fleetv1beta1.ResourceBindingStatus{
Conditions: []metav1.Condition{
{
Type: string(fleetv1beta1.ResourceBindingApplied),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
Reason: "any",
},
{
Type: string(fleetv1beta1.ResourceBindingAvailable),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
Reason: "any",
},
},
},
},
},
readyTimeCutOff: time.Now(),
wantWaitDuration: time.Duration(math.MaxInt64),
readyTimeCutOff: now,
wantWaitDuration: 0,
},
"one binding not ready": {
bindings: []*fleetv1beta1.ClusterResourceBinding{
{
ObjectMeta: metav1.ObjectMeta{
Generation: 1,
},
Status: fleetv1beta1.ResourceBindingStatus{
Conditions: []metav1.Condition{
{
Type: string(fleetv1beta1.ResourceBindingApplied),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
Reason: "any",
},
{
Type: string(fleetv1beta1.ResourceBindingAvailable),
Status: metav1.ConditionFalse,
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
LastTransitionTime: metav1.Time{
Time: now.Add(time.Millisecond),
},
Reason: work.WorkNotTrackableReason,
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Generation: 1,
},
Status: fleetv1beta1.ResourceBindingStatus{
Conditions: []metav1.Condition{
{
Type: string(fleetv1beta1.ResourceBindingApplied),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
Reason: "any",
},
{
Type: string(fleetv1beta1.ResourceBindingAvailable),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
Reason: "any",
},
},
},
},
},
readyTimeCutOff: time.Now(),
wantWaitDuration: 0,
readyTimeCutOff: now,
wantWaitDuration: time.Millisecond,
},
"multiple bindings not ready": {
bindings: []*fleetv1beta1.ClusterResourceBinding{
{
Status: fleetv1beta1.ResourceBindingStatus{
Conditions: []metav1.Condition{
{
Type: string(fleetv1beta1.ResourceBindingApplied),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
},
{
Type: string(fleetv1beta1.ResourceBindingAvailable),
Status: metav1.ConditionFalse,
ObservedGeneration: 1,
},
},
ObjectMeta: metav1.ObjectMeta{
Generation: 1,
},
},
{
Status: fleetv1beta1.ResourceBindingStatus{
Conditions: []metav1.Condition{
{
Type: string(fleetv1beta1.ResourceBindingApplied),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
},
{
Type: string(fleetv1beta1.ResourceBindingAvailable),
Status: metav1.ConditionFalse,
ObservedGeneration: 1,
},
},
},
},
},
readyTimeCutOff: time.Now(),
wantWaitDuration: time.Duration(math.MaxInt64),
},
"one binding not applied": {
bindings: []*fleetv1beta1.ClusterResourceBinding{
{
Status: fleetv1beta1.ResourceBindingStatus{
Conditions: []metav1.Condition{
{
Type: string(fleetv1beta1.ResourceBindingApplied),
Status: metav1.ConditionFalse,
ObservedGeneration: 1,
Reason: "any",
},
{
Type: string(fleetv1beta1.ResourceBindingAvailable),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
LastTransitionTime: metav1.Time{
Time: now.Add(15 * time.Millisecond),
},
Reason: work.WorkNotTrackableReason,
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Generation: 1,
},
Status: fleetv1beta1.ResourceBindingStatus{
Conditions: []metav1.Condition{
{
Type: string(fleetv1beta1.ResourceBindingApplied),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
Reason: "any",
},
{
Type: string(fleetv1beta1.ResourceBindingAvailable),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
LastTransitionTime: metav1.Time{
Time: now.Add(5 * time.Millisecond),
},
Reason: work.WorkNotTrackableReason,
},
},
},
},
},
readyTimeCutOff: time.Now(),
wantWaitDuration: time.Duration(math.MaxInt64),
readyTimeCutOff: now,
wantWaitDuration: 5 * time.Millisecond,
},
}

Expand Down

0 comments on commit 96165df

Please sign in to comment.