Skip to content

Commit 99ccd53

Browse files
Merge pull request #1914 from RomanBednar/OCPBUGS-24588
OCPBUGS-24588: degrade when deployment progressing too long
2 parents af5b21e + b5024a1 commit 99ccd53

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-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 := 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/deploymentcontroller/deployment_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ func (c *DeploymentController) syncManaged(ctx context.Context, opSpec *opv1.Ope
300300
WithMessage(msg).
301301
WithReason("Deploying")
302302
}
303+
304+
// Degrade when operator is progressing too long.
305+
if v1helpers.IsUpdatingTooLong(opStatus, c.instanceName+opv1.OperatorStatusTypeProgressing) {
306+
return fmt.Errorf("Deployment was progressing too long")
307+
}
303308
status = status.WithConditions(progressingCondition)
304309
}
305310

pkg/operator/v1helpers/helpers.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import (
2323
"sigs.k8s.io/yaml"
2424
)
2525

26+
const (
27+
progressingConditionTimeout = 15 * time.Minute
28+
)
29+
2630
// SetOperandVersion sets the new version and returns the previous value.
2731
func SetOperandVersion(versions *[]configv1.OperandVersion, operandVersion configv1.OperandVersion) string {
2832
if versions == nil {
@@ -554,3 +558,10 @@ func IsConditionPresentAndEqual(conditions []metav1.Condition, conditionType str
554558
}
555559
return false
556560
}
561+
562+
// IsUpdatingTooLong determines if updating operands condition takes too long.
563+
// It returns true if the given condition was found and has been set to True longer than progressingConditionTimeout.
564+
func IsUpdatingTooLong(operatorStatus *operatorv1.OperatorStatus, progressingConditionType string) bool {
565+
progressing := FindOperatorCondition(operatorStatus.Conditions, progressingConditionType)
566+
return progressing != nil && progressing.Status == operatorv1.ConditionTrue && time.Now().After(progressing.LastTransitionTime.Add(progressingConditionTimeout))
567+
}

0 commit comments

Comments
 (0)