Skip to content

Commit 95766a7

Browse files
stlazdeads2k
authored andcommitted
oauthclients: re-create status handler on each sync
1 parent d266e59 commit 95766a7

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

pkg/console/controllers/oauthclients/oauthclients.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ type oauthClientsController struct {
6363
targetNSConfigLister corev1listers.ConfigMapLister
6464
featureGatesLister configv1lister.FeatureGateLister
6565

66-
statusHandler status.StatusHandler
6766
authStatusHandler status.AuthStatusHandler
6867
}
6968

@@ -103,7 +102,6 @@ func NewOAuthClientsController(
103102
targetNSDeploymentsLister: targetNSDeploymentsInformer.Lister(),
104103
featureGatesLister: featureGatesInformer.Lister(),
105104

106-
statusHandler: status.NewStatusHandler(operatorClient),
107105
authStatusHandler: status.NewAuthStatusHandler(authentication, api.OpenShiftConsoleName, api.TargetNamespace, api.OpenShiftConsoleOperator),
108106
}
109107

@@ -128,6 +126,8 @@ func NewOAuthClientsController(
128126
}
129127

130128
func (c *oauthClientsController) sync(ctx context.Context, controllerContext factory.SyncContext) error {
129+
statusHandler := status.NewStatusHandler(c.operatorClient)
130+
131131
if shouldSync, err := c.handleManaged(ctx); err != nil {
132132
return err
133133
} else if !shouldSync {
@@ -176,36 +176,43 @@ func (c *oauthClientsController) sync(ctx context.Context, controllerContext fac
176176
}
177177

178178
clientSecret, secErr := c.syncSecret(ctx, operatorConfig, controllerContext.Recorder())
179-
c.statusHandler.AddConditions(status.HandleProgressingOrDegraded("OAuthClientSecretSync", "FailedApply", secErr))
179+
statusHandler.AddConditions(status.HandleProgressingOrDegraded("OAuthClientSecretSync", "FailedApply", secErr))
180180
if secErr != nil {
181181
syncErr = secErr
182182
break
183183
}
184184

185185
oauthErrReason, oauthErr := c.syncOAuthClient(ctx, clientSecret, consoleURL.String())
186-
c.statusHandler.AddConditions(status.HandleProgressingOrDegraded("OAuthClientSync", oauthErrReason, oauthErr))
186+
statusHandler.AddConditions(status.HandleProgressingOrDegraded("OAuthClientSync", oauthErrReason, oauthErr))
187187
if oauthErr != nil {
188188
syncErr = oauthErr
189189
break
190190
}
191191

192192
case configv1.AuthenticationTypeOIDC:
193-
syncErr = c.syncAuthTypeOIDC(ctx, controllerContext, operatorConfig, authnConfig)
193+
syncErr = c.syncAuthTypeOIDC(ctx, controllerContext, statusHandler, operatorConfig, authnConfig)
194194
}
195195

196196
// AuthStatusHandler manages fields that are behind the CustomNoUpgrade and TechPreviewNoUpgrade featuregate sets
197197
// call Apply() only if they are enabled, otherwise server-side apply will complain
198198
if featureGates.Spec.FeatureSet == configv1.TechPreviewNoUpgrade || featureGates.Spec.FeatureSet == configv1.CustomNoUpgrade {
199199
if err := c.authStatusHandler.Apply(ctx, authnConfig); err != nil {
200-
c.statusHandler.AddConditions(status.HandleProgressingOrDegraded("AuthStatusHandler", "FailedApply", err))
201-
return c.statusHandler.FlushAndReturn(err)
200+
statusHandler.AddConditions(status.HandleProgressingOrDegraded("AuthStatusHandler", "FailedApply", err))
201+
return statusHandler.FlushAndReturn(err)
202202
}
203203
}
204204

205-
return c.statusHandler.FlushAndReturn(syncErr)
205+
return statusHandler.FlushAndReturn(syncErr)
206206
}
207207

208-
func (c *oauthClientsController) syncAuthTypeOIDC(ctx context.Context, controllerContext factory.SyncContext, operatorConfig *operatorv1.Console, authnConfig *configv1.Authentication) error {
208+
func (c *oauthClientsController) syncAuthTypeOIDC(
209+
ctx context.Context,
210+
controllerContext factory.SyncContext,
211+
statusHandler status.StatusHandler,
212+
operatorConfig *operatorv1.Console,
213+
authnConfig *configv1.Authentication,
214+
) error {
215+
209216
clientConfig := utilsub.GetOIDCClientConfig(authnConfig)
210217
if clientConfig == nil {
211218
c.authStatusHandler.WithCurrentOIDCClient("")
@@ -215,8 +222,8 @@ func (c *oauthClientsController) syncAuthTypeOIDC(ctx context.Context, controlle
215222

216223
if len(clientConfig.ClientID) == 0 {
217224
err := fmt.Errorf("no ID set on OIDC client")
218-
c.statusHandler.AddConditions(status.HandleProgressingOrDegraded("OIDCClientConfig", "MissingID", err))
219-
return c.statusHandler.FlushAndReturn(err)
225+
statusHandler.AddConditions(status.HandleProgressingOrDegraded("OIDCClientConfig", "MissingID", err))
226+
return statusHandler.FlushAndReturn(err)
220227
}
221228
c.authStatusHandler.WithCurrentOIDCClient(clientConfig.ClientID)
222229

@@ -236,7 +243,7 @@ func (c *oauthClientsController) syncAuthTypeOIDC(ctx context.Context, controlle
236243
if apierrors.IsNotFound(err) || secretsub.GetSecretString(secret) != expectedClientSecret {
237244
secret, _, err = resourceapply.ApplySecret(ctx, c.secretsClient, controllerContext.Recorder(), secretsub.DefaultSecret(operatorConfig, expectedClientSecret))
238245
if err != nil {
239-
c.statusHandler.AddConditions(status.HandleProgressingOrDegraded("OIDCClientSecretSync", "FailedApply", err))
246+
statusHandler.AddConditions(status.HandleProgressingOrDegraded("OIDCClientSecretSync", "FailedApply", err))
240247
return err
241248
}
242249
}

0 commit comments

Comments
 (0)