File tree Expand file tree Collapse file tree 3 files changed +17
-29
lines changed
controllers/topology/cluster/scope Expand file tree Collapse file tree 3 files changed +17
-29
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import (
2323
2424 runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog"
2525 runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
26+ "sigs.k8s.io/cluster-api/util"
2627)
2728
2829// HookResponseTracker is a helper to capture the responses of the various lifecycle hooks.
@@ -48,7 +49,7 @@ func (h *HookResponseTracker) AggregateRetryAfter() time.Duration {
4849 res := int32 (0 )
4950 for _ , resp := range h .responses {
5051 if retryResponse , ok := resp .(runtimehooksv1.RetryResponseObject ); ok {
51- res = lowestNonZeroRetryAfterSeconds (res , retryResponse .GetRetryAfterSeconds ())
52+ res = util . LowestNonZeroInt32 (res , retryResponse .GetRetryAfterSeconds ())
5253 }
5354 }
5455 return time .Duration (res ) * time .Second
@@ -74,16 +75,3 @@ func (h *HookResponseTracker) AggregateMessage() string {
7475 }
7576 return strings .Join (hookAndMessages , "; " )
7677}
77-
78- func lowestNonZeroRetryAfterSeconds (i , j int32 ) int32 {
79- if i == 0 {
80- return j
81- }
82- if j == 0 {
83- return i
84- }
85- if i < j {
86- return i
87- }
88- return j
89- }
Original file line number Diff line number Diff line change @@ -263,7 +263,7 @@ func aggregateSuccessfulResponses(aggregatedResponse runtimehooksv1.ResponseObje
263263 for _ , resp := range responses {
264264 aggregatedRetryResponse , ok := aggregatedResponse .(runtimehooksv1.RetryResponseObject )
265265 if ok {
266- aggregatedRetryResponse .SetRetryAfterSeconds (lowestNonZeroRetryAfterSeconds (
266+ aggregatedRetryResponse .SetRetryAfterSeconds (util . LowestNonZeroInt32 (
267267 aggregatedRetryResponse .GetRetryAfterSeconds (),
268268 resp .(runtimehooksv1.RetryResponseObject ).GetRetryAfterSeconds (),
269269 ))
@@ -275,20 +275,6 @@ func aggregateSuccessfulResponses(aggregatedResponse runtimehooksv1.ResponseObje
275275 aggregatedResponse .SetMessage (strings .Join (messages , ", " ))
276276}
277277
278- // lowestNonZeroRetryAfterSeconds returns the lowest non-zero value of the two provided values.
279- func lowestNonZeroRetryAfterSeconds (i , j int32 ) int32 {
280- if i == 0 {
281- return j
282- }
283- if j == 0 {
284- return i
285- }
286- if i < j {
287- return i
288- }
289- return j
290- }
291-
292278// CallExtension makes the call to the extension with the given name.
293279// The response object passed will be updated with the response of the call.
294280// An error is returned if the extension is not compatible with the hook.
Original file line number Diff line number Diff line change @@ -593,6 +593,20 @@ func LowestNonZeroResult(i, j ctrl.Result) ctrl.Result {
593593 }
594594}
595595
596+ // LowestNonZeroInt32 returns the lowest non-zero value of the two provided values.
597+ func LowestNonZeroInt32 (i , j int32 ) int32 {
598+ if i == 0 {
599+ return j
600+ }
601+ if j == 0 {
602+ return i
603+ }
604+ if i < j {
605+ return i
606+ }
607+ return j
608+ }
609+
596610// IsNil returns an error if the passed interface is equal to nil or if it has an interface value of nil.
597611func IsNil (i interface {}) bool {
598612 if i == nil {
You can’t perform that action at this time.
0 commit comments