Skip to content

Commit 59a263a

Browse files
Merge pull request #142 from enj/enj/i/handle_degraded_conditions
Bug 1725935: Split handling of degraded across multiple conditions
2 parents 50c8730 + e6776d4 commit 59a263a

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

pkg/operator2/oauth.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ func (c *authOperator) handleOAuthConfig(
8282
},
8383
)
8484
}
85-
if err := v1helpers.NewMultiLineAggregate(errsIDP); err != nil {
86-
setDegradedTrue(operatorConfig, "IdentityProviderConfigError", err.Error())
87-
}
85+
handleDegraded(operatorConfig, "IdentityProviderConfig", v1helpers.NewMultiLineAggregate(errsIDP))
8886

8987
assetPublicURL, corsAllowedOrigins := consoleToDeploymentData(consoleConfig)
9088

pkg/operator2/operator.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,13 @@ func (c *authOperator) Sync(obj metav1.Object) error {
252252

253253
operatorConfigCopy := operatorConfig.DeepCopy()
254254

255-
// clear degraded status
256-
setDegradedFalse(operatorConfigCopy)
257-
258255
syncErr := c.handleSync(operatorConfigCopy)
259-
if syncErr != nil {
260-
setDegradedTrue(operatorConfigCopy, "OperatorSyncLoopError", syncErr.Error())
256+
// this is a catch all degraded state that we only set when we are otherwise not degraded
257+
globalDegradedErr := syncErr
258+
if isDegraded(operatorConfigCopy) {
259+
globalDegradedErr = nil // unset because we are already degraded for some other reason
261260
}
261+
handleDegraded(operatorConfigCopy, "OperatorSync", globalDegradedErr)
262262

263263
if _, _, err := v1helpers.UpdateStatus(c.authOperatorConfigClient, func(status *operatorv1.OperatorStatus) error {
264264
// store a copy of our starting conditions, we need to preserve last transition time
@@ -313,6 +313,7 @@ func (c *authOperator) handleSync(operatorConfig *operatorv1.Authentication) err
313313
resourceVersions = append(resourceVersions, ingress.GetResourceVersion())
314314

315315
route, routerSecret, err := c.handleRoute(ingress)
316+
handleDegraded(operatorConfig, "RouteStatus", err)
316317
if err != nil {
317318
return fmt.Errorf("failed handling the route: %v", err)
318319
}
@@ -451,6 +452,7 @@ func (c *authOperator) handleVersion(
451452
// but we do NOT want to go to the next version until all OAuth server pods are at that version
452453

453454
routeReady, routeMsg, err := c.checkRouteHealthy(route, routerSecret, ingress)
455+
handleDegraded(operatorConfig, "RouteHealth", err)
454456
if err != nil {
455457
return fmt.Errorf("unable to check route health: %v", err)
456458
}
@@ -460,6 +462,7 @@ func (c *authOperator) handleVersion(
460462
}
461463

462464
wellknownReady, wellknownMsg, err := c.checkWellknownEndpointsReady(authConfig, route)
465+
handleDegraded(operatorConfig, "WellKnownEndpoint", err)
463466
if err != nil {
464467
return fmt.Errorf("unable to check the .well-known endpoint: %v", err)
465468
}
@@ -469,6 +472,7 @@ func (c *authOperator) handleVersion(
469472
}
470473

471474
oauthClientsReady, oauthClientsMsg, err := c.oauthClientsReady(route)
475+
handleDegraded(operatorConfig, "OAuthClients", err)
472476
if err != nil {
473477
return fmt.Errorf("unable to check OAuth clients' readiness: %v", err)
474478
}

pkg/operator2/route.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ func (c *authOperator) handleRoute(ingress *configv1.Ingress) (*routev1.Route, *
2323
return nil, nil, err
2424
}
2525

26+
host := getCanonicalHost(route, ingress)
27+
if len(host) == 0 {
28+
// be careful not to print route.spec as it many contain secrets
29+
return nil, nil, fmt.Errorf("route is not available at canonical host %s: %+v", ingressToHost(ingress), route.Status.Ingress)
30+
}
31+
2632
// assume it is unsafe to mutate route in case we go to a shared informer in the future
2733
// this way everything else can just assume route.Spec.Host is correct
2834
// note that we are not updating route.Spec.Host in the API - that value is nonsense to us
2935
route = route.DeepCopy()
30-
route.Spec.Host = getCanonicalHost(route, ingress)
31-
32-
if len(route.Spec.Host) == 0 {
33-
return nil, nil, fmt.Errorf("route has no host: %#v", route)
34-
}
36+
route.Spec.Host = host
3537

3638
if err := isValidRoute(route, ingress); err != nil {
39+
// TODO remove this delete so that we do not lose the early creation timestamp of our route
3740
// delete the route so that it is replaced with the proper one in next reconcile loop
3841
klog.Infof("deleting invalid route: %#v", route)
3942
opts := &metav1.DeleteOptions{Preconditions: &metav1.Preconditions{UID: &route.UID}}
@@ -48,7 +51,8 @@ func (c *authOperator) handleRoute(ingress *configv1.Ingress) (*routev1.Route, *
4851
return nil, nil, err
4952
}
5053
if len(routerSecret.Data) == 0 {
51-
return nil, nil, fmt.Errorf("router secret is empty: %#v", routerSecret)
54+
// be careful not to print the routerSecret even when it is empty
55+
return nil, nil, fmt.Errorf("router secret %s/%s is empty", routerSecret.Namespace, routerSecret.Name)
5256
}
5357

5458
return route, routerSecret, nil

pkg/operator2/status.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
11
package operator2
22

33
import (
4+
"strings"
5+
46
operatorv1 "github.com/openshift/api/operator/v1"
57
"github.com/openshift/library-go/pkg/operator/v1helpers"
68
)
79

8-
func setDegradedTrue(operatorConfig *operatorv1.Authentication, reason, message string) {
10+
func handleDegraded(operatorConfig *operatorv1.Authentication, prefix string, err error) {
11+
if err != nil {
12+
v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions,
13+
operatorv1.OperatorCondition{
14+
Type: prefix + operatorv1.OperatorStatusTypeDegraded,
15+
Status: operatorv1.ConditionTrue,
16+
Reason: "Error",
17+
Message: err.Error(),
18+
})
19+
return
20+
}
921
v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions,
1022
operatorv1.OperatorCondition{
11-
Type: operatorv1.OperatorStatusTypeDegraded,
12-
Status: operatorv1.ConditionTrue,
13-
Reason: reason,
14-
Message: message,
23+
Type: prefix + operatorv1.OperatorStatusTypeDegraded,
24+
Status: operatorv1.ConditionFalse,
1525
})
1626
}
1727

18-
func setDegradedFalse(operatorConfig *operatorv1.Authentication) {
19-
v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions,
20-
operatorv1.OperatorCondition{
21-
Type: operatorv1.OperatorStatusTypeDegraded,
22-
Status: operatorv1.ConditionFalse,
23-
})
28+
func isDegraded(operatorConfig *operatorv1.Authentication) bool {
29+
for _, condition := range operatorConfig.Status.Conditions {
30+
if strings.HasSuffix(condition.Type, operatorv1.OperatorStatusTypeDegraded) &&
31+
condition.Status == operatorv1.ConditionTrue {
32+
return true
33+
}
34+
}
35+
return false
2436
}
2537

2638
func setProgressingTrue(operatorConfig *operatorv1.Authentication, reason, message string) {

0 commit comments

Comments
 (0)