From f6404f30c42cd2f5a28878f5feff04622d83e847 Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Wed, 3 Jan 2024 16:26:09 +0800 Subject: [PATCH] Fix nil pointer when timeout is not set (#310) Signed-off-by: Jian Qiu --- cluster/v1alpha1/helpers.go | 8 ++++---- cluster/v1alpha1/helpers_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cluster/v1alpha1/helpers.go b/cluster/v1alpha1/helpers.go index 8ee5be26e..fb5398194 100644 --- a/cluster/v1alpha1/helpers.go +++ b/cluster/v1alpha1/helpers.go @@ -167,7 +167,7 @@ func (r *RolloutHandler[T]) getProgressiveClusters(rolloutStrategy RolloutStrate // Perform progressive rollOut for mandatory decision groups first, tolerating no failures if len(clusterGroups) > 0 { rolloutResult := progressivePerGroup( - clusterGroups, intstr.FromInt(0), minSuccessTime, failureTimeout, currentClusterStatus, + clusterGroups, intstr.FromInt32(0), minSuccessTime, failureTimeout, currentClusterStatus, ) if len(rolloutResult.ClustersToRollout) > 0 || len(rolloutResult.ClustersTimeOut) > 0 { rolloutResult.ClustersRemoved = removedClusterStatus @@ -223,7 +223,7 @@ func (r *RolloutHandler[T]) getProgressivePerGroupClusters(rolloutStrategy Rollo // Perform progressive rollout per group for mandatory decision groups first, tolerating no failures if len(clusterGroups) > 0 { - rolloutResult := progressivePerGroup(clusterGroups, intstr.FromInt(0), minSuccessTime, failureTimeout, currentClusterStatus) + rolloutResult := progressivePerGroup(clusterGroups, intstr.FromInt32(0), minSuccessTime, failureTimeout, currentClusterStatus) if len(rolloutResult.ClustersToRollout) > 0 || len(rolloutResult.ClustersTimeOut) > 0 { rolloutResult.ClustersRemoved = removedClusterStatus @@ -585,7 +585,7 @@ func parseTimeout(timeoutStr string) (time.Duration, error) { } func decisionGroupsToGroupKeys(decisionsGroup []MandatoryDecisionGroup) []clusterv1beta1.GroupKey { - result := []clusterv1beta1.GroupKey{} + var result []clusterv1beta1.GroupKey for _, d := range decisionsGroup { gk := clusterv1beta1.GroupKey{} // GroupName is considered first to select the decisionGroups then GroupIndex. @@ -609,7 +609,7 @@ func minRecheckAfter(rolloutClusters []ClusterRolloutStatus, minSuccessTime time } } } - if minSuccessTime != 0 && minSuccessTime < *minRecheckAfter { + if minSuccessTime != 0 && (minRecheckAfter == nil || minSuccessTime < *minRecheckAfter) { minRecheckAfter = &minSuccessTime } diff --git a/cluster/v1alpha1/helpers_test.go b/cluster/v1alpha1/helpers_test.go index 654e757ba..2c688b45d 100644 --- a/cluster/v1alpha1/helpers_test.go +++ b/cluster/v1alpha1/helpers_test.go @@ -2463,7 +2463,7 @@ func TestDecisionGroupsToGroupKeys(t *testing.T) { { name: "Empty MandatoryDecisionGroup", input: []MandatoryDecisionGroup{}, - expected: []clusterv1beta1.GroupKey{}, + expected: nil, }, }