Skip to content

Commit 51232b7

Browse files
committed
move isUpdatingTooLong function to helpers
1 parent 6018a90 commit 51232b7

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

pkg/operator/apiserver/controller/workload/workload.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"strings"
8-
"time"
9-
107
appsv1 "k8s.io/api/apps/v1"
118
corev1 "k8s.io/api/core/v1"
129
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -17,6 +14,7 @@ import (
1714
corev1listers "k8s.io/client-go/listers/core/v1"
1815
"k8s.io/client-go/tools/cache"
1916
"k8s.io/client-go/util/workqueue"
17+
"strings"
2018

2119
operatorv1 "github.com/openshift/api/operator/v1"
2220
openshiftconfigclientv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
@@ -293,7 +291,7 @@ func (c *Controller) updateOperatorStatus(ctx context.Context, previousStatus *o
293291
// Update is done when all pods have been updated to the latest revision
294292
// and the deployment controller has reported NewReplicaSetAvailable
295293
workloadIsBeingUpdated := !workloadAtHighestGeneration || !hasDeploymentProgressed(workload.Status)
296-
workloadIsBeingUpdatedTooLong, err := isUpdatingTooLong(previousStatus, *deploymentProgressingCondition.Type)
294+
workloadIsBeingUpdatedTooLong, err := v1helpers.IsUpdatingTooLong(previousStatus, *deploymentProgressingCondition.Type)
297295
if !workloadAtHighestGeneration {
298296
deploymentProgressingCondition = deploymentProgressingCondition.
299297
WithStatus(operatorv1.ConditionTrue).
@@ -356,13 +354,6 @@ func (c *Controller) updateOperatorStatus(ctx context.Context, previousStatus *o
356354
return nil
357355
}
358356

359-
// isUpdatingTooLong determines if updating operands takes too long.
360-
// it returns true if the progressing condition has been set to True for at least 15 minutes
361-
func isUpdatingTooLong(operatorStatus *operatorv1.OperatorStatus, progressingConditionType string) (bool, error) {
362-
progressing := v1helpers.FindOperatorCondition(operatorStatus.Conditions, progressingConditionType)
363-
return progressing != nil && progressing.Status == operatorv1.ConditionTrue && time.Now().After(progressing.LastTransitionTime.Add(15*time.Minute)), nil
364-
}
365-
366357
// hasDeploymentProgressed returns true if the deployment reports NewReplicaSetAvailable
367358
// via the DeploymentProgressing condition
368359
func hasDeploymentProgressed(status appsv1.DeploymentStatus) bool {

pkg/operator/v1helpers/helpers.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,3 +550,10 @@ func IsConditionPresentAndEqual(conditions []metav1.Condition, conditionType str
550550
}
551551
return false
552552
}
553+
554+
// IsUpdatingTooLong determines if updating operands takes too long.
555+
// it returns true if the progressing condition has been set to True for at least 15 minutes
556+
func IsUpdatingTooLong(operatorStatus *operatorv1.OperatorStatus, progressingConditionType string) (bool, error) {
557+
progressing := FindOperatorCondition(operatorStatus.Conditions, progressingConditionType)
558+
return progressing != nil && progressing.Status == operatorv1.ConditionTrue && time.Now().After(progressing.LastTransitionTime.Add(15*time.Minute)), nil
559+
}

0 commit comments

Comments
 (0)