Skip to content

Commit

Permalink
make sure wellKnownReadyController can't have the same condition twice
Browse files Browse the repository at this point in the history
  • Loading branch information
bertinatto committed Oct 8, 2024
1 parent 1934908 commit b8a27c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
13 changes: 6 additions & 7 deletions pkg/controllers/common/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ func (e *ControllerProgressingError) Unwrap() error {
return e.err
}

func (e *ControllerProgressingError) ToCondition(controllerName string) operatorv1.OperatorCondition {
return operatorv1.OperatorCondition{
Type: ControllerProgressingConditionName(controllerName),
Status: operatorv1.ConditionTrue,
Reason: e.reason,
Message: e.err.Error(),
}
func (e *ControllerProgressingError) ToCondition(controllerName string) *applyoperatorv1.OperatorConditionApplyConfiguration {
return applyoperatorv1.OperatorCondition().
WithType(ControllerProgressingConditionName(controllerName)).
WithStatus(operatorv1.ConditionTrue).
WithReason(e.reason).
WithMessage(e.err.Error())
}

// IsDegraded returns true if the condition matching this error (same type, reason and message)
Expand Down
39 changes: 17 additions & 22 deletions pkg/controllers/readiness/wellknown_ready_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@ func (c *wellKnownReadyController) sync(ctx context.Context, controllerContext f
}

// the code below this point triggers status updates, unify status update handling in defer
available := applyoperatorv1.OperatorCondition().
WithType("WellKnownAvailable").
WithStatus(operatorv1.ConditionFalse)
progressing := applyoperatorv1.OperatorCondition().
WithType(common.ControllerProgressingConditionName(controllerName)).
WithStatus(operatorv1.ConditionTrue)
status := applyoperatorv1.OperatorStatus()
defer func() {
status = status.WithConditions(available, progressing)
if updateErr := c.operatorClient.ApplyOperatorStatus(ctx, c.controllerInstanceName, status); updateErr != nil {
// fall through to the generic error handling for degraded and requeue
utilruntime.HandleError(updateErr)
Expand All @@ -122,48 +129,36 @@ func (c *wellKnownReadyController) sync(ctx context.Context, controllerContext f
// the well-known endpoint cannot be ready until we know the oauth-server's hostname
_, err = c.routeLister.Routes("openshift-authentication").Get("oauth-openshift")
if apierrors.IsNotFound(err) {
status = status.WithConditions(applyoperatorv1.OperatorCondition().
WithType("WellKnownAvailable").
available = available.
WithStatus(operatorv1.ConditionFalse).
WithReason("PrereqsNotReady").
WithMessage(err.Error()))
WithMessage(err.Error())
}
if err != nil {
return err
}

if err := c.isWellknownEndpointsReady(ctx, operatorSpec, operatorStatus, authConfig, infraConfig); err != nil {
status = status.WithConditions(applyoperatorv1.OperatorCondition().
WithType("WellKnownAvailable").
available = available.
WithStatus(operatorv1.ConditionFalse).
WithReason("NotReady").
WithMessage(fmt.Sprintf("The well-known endpoint is not yet available: %s", err.Error())))

WithMessage(fmt.Sprintf("The well-known endpoint is not yet available: %s", err.Error()))
if progressingErr, ok := err.(*common.ControllerProgressingError); ok {
if progressingErr.IsDegraded(controllerName, operatorStatus) {
return progressingErr.Unwrap()
}
condition := progressingErr.ToCondition(controllerName)
status = status.WithConditions(applyoperatorv1.OperatorCondition().
WithType(condition.Type).
WithStatus(condition.Status).
WithReason(condition.Reason).
WithMessage(condition.Message))
progressing = progressingErr.ToCondition(controllerName)
return nil
} else {
return err
}
}

status = status.WithConditions(
applyoperatorv1.OperatorCondition().
WithType(common.ControllerProgressingConditionName(controllerName)).
WithStatus(operatorv1.ConditionFalse),
applyoperatorv1.OperatorCondition().
WithType("WellKnownAvailable").
WithStatus(operatorv1.ConditionTrue).
WithReason("AsExpected"),
)
progressing = progressing.
WithStatus(operatorv1.ConditionFalse)
available = available.
WithStatus(operatorv1.ConditionTrue).
WithReason("AsExpected")

return nil
}
Expand Down

0 comments on commit b8a27c0

Please sign in to comment.