Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Calculate requeue time in rollout #306

Merged
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
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
Loading