Skip to content

Commit

Permalink
Calculate requeue time in rollout
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Qiu <[email protected]>
  • Loading branch information
qiujian16 committed Dec 21, 2023
1 parent a2f58d6 commit 4cc2fb0
Show file tree
Hide file tree
Showing 2 changed files with 319 additions and 200 deletions.
31 changes: 30 additions & 1 deletion cluster/v1alpha1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type RolloutResult struct {
ClustersRemoved []ClusterRolloutStatus
// MaxFailureBreach is a boolean signaling whether the rollout was cut short because of failed clusters.
MaxFailureBreach bool
// RecheckAfter is the time duration to recheck the rollout status.
RecheckAfter *time.Duration
}

// ClusterRolloutStatusFunc defines a function that return the rollout status for a given workload.
Expand Down Expand Up @@ -307,6 +309,7 @@ func progressivePerCluster(
ClustersToRollout: rolloutClusters,
ClustersTimeOut: timeoutClusters,
MaxFailureBreach: failureBreach,
RecheckAfter: minRecheckAfter(rolloutClusters, minSuccessTime),
}
}
}
Expand All @@ -316,6 +319,7 @@ func progressivePerCluster(
ClustersToRollout: rolloutClusters,
ClustersTimeOut: timeoutClusters,
MaxFailureBreach: failureBreach,
RecheckAfter: minRecheckAfter(rolloutClusters, minSuccessTime),
}
}

Expand Down Expand Up @@ -344,13 +348,15 @@ func progressivePerCluster(
return RolloutResult{
ClustersToRollout: rolloutClusters,
ClustersTimeOut: timeoutClusters,
RecheckAfter: minRecheckAfter(rolloutClusters, minSuccessTime),
}
}
}

return RolloutResult{
ClustersToRollout: rolloutClusters,
ClustersTimeOut: timeoutClusters,
RecheckAfter: minRecheckAfter(rolloutClusters, minSuccessTime),
}
}

Expand Down Expand Up @@ -417,6 +423,7 @@ func progressivePerGroup(
ClustersToRollout: rolloutClusters,
ClustersTimeOut: timeoutClusters,
MaxFailureBreach: failureBreach,
RecheckAfter: minRecheckAfter(rolloutClusters, minSuccessTime),
}
}
}
Expand All @@ -426,6 +433,7 @@ func progressivePerGroup(
ClustersToRollout: rolloutClusters,
ClustersTimeOut: timeoutClusters,
MaxFailureBreach: failureBreach,
RecheckAfter: minRecheckAfter(rolloutClusters, minSuccessTime),
}
}

Expand Down Expand Up @@ -467,7 +475,7 @@ func determineRolloutStatus(
timeOutTime := getTimeOutTime(status.LastTransitionTime, timeout)
status.TimeOutTime = timeOutTime
// check if current time is before the timeout time
if RolloutClock.Now().Before(timeOutTime.Time) {
if timeOutTime == nil || RolloutClock.Now().Before(timeOutTime.Time) {
rolloutClusters = append(rolloutClusters, *status)
} else {
status.Status = TimeOut
Expand All @@ -482,6 +490,10 @@ func determineRolloutStatus(
// RolloutClock if a start time isn't provided.
func getTimeOutTime(startTime *metav1.Time, timeout time.Duration) *metav1.Time {
var timeoutTime time.Time
// if timeout is not set (default to maxTimeDuration), the timeout time should not be set
if timeout == maxTimeDuration {
return nil
}
if startTime == nil {
timeoutTime = RolloutClock.Now().Add(timeout)
} else {
Expand Down Expand Up @@ -578,3 +590,20 @@ func decisionGroupsToGroupKeys(decisionsGroup []MandatoryDecisionGroup) []cluste
}
return result
}

func minRecheckAfter(rolloutClusters []ClusterRolloutStatus, minSuccessTime time.Duration) *time.Duration {
var minRecheckAfter *time.Duration
for _, r := range rolloutClusters {
if r.TimeOutTime != nil {
timeOut := r.TimeOutTime.Sub(RolloutClock.Now())
if minRecheckAfter == nil || *minRecheckAfter > timeOut {
minRecheckAfter = &timeOut
}
}
}
if minSuccessTime != 0 && minSuccessTime < *minRecheckAfter {
minRecheckAfter = &minSuccessTime
}

return minRecheckAfter
}
Loading

0 comments on commit 4cc2fb0

Please sign in to comment.