6
6
"time"
7
7
8
8
corev1 "k8s.io/api/core/v1"
9
- apiexensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
10
- apiexensionsv1informers "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions/apiextensions/v1"
11
- apiexensionsv1listers "k8s.io/apiextensions-apiserver/pkg/client/listers/apiextensions/v1"
12
9
apierrors "k8s.io/apimachinery/pkg/api/errors"
13
10
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
11
"k8s.io/apimachinery/pkg/util/wait"
@@ -34,17 +31,13 @@ import (
34
31
"github.com/openshift/library-go/pkg/operator/events"
35
32
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
36
33
"github.com/openshift/library-go/pkg/operator/v1helpers"
37
- appsv1informers "k8s.io/client-go/informers/apps/v1"
38
- appsv1listers "k8s.io/client-go/listers/apps/v1"
39
34
40
35
"github.com/openshift/console-operator/pkg/api"
41
36
"github.com/openshift/console-operator/pkg/console/controllers/util"
42
37
"github.com/openshift/console-operator/pkg/console/status"
43
- deploymentsub "github.com/openshift/console-operator/pkg/console/subresource/deployment"
44
38
oauthsub "github.com/openshift/console-operator/pkg/console/subresource/oauthclient"
45
39
routesub "github.com/openshift/console-operator/pkg/console/subresource/route"
46
40
secretsub "github.com/openshift/console-operator/pkg/console/subresource/secret"
47
- utilsub "github.com/openshift/console-operator/pkg/console/subresource/util"
48
41
"github.com/openshift/console-operator/pkg/crypto"
49
42
)
50
43
@@ -58,32 +51,23 @@ type oauthClientsController struct {
58
51
authentication configv1client.AuthenticationInterface
59
52
authnLister configv1lister.AuthenticationLister
60
53
consoleOperatorLister operatorv1listers.ConsoleLister
61
- crdLister apiexensionsv1listers.CustomResourceDefinitionLister
62
54
routesLister routev1listers.RouteLister
63
55
ingressConfigLister configv1lister.IngressLister
64
56
targetNSSecretsLister corev1listers.SecretLister
65
- configNSSecretsLister corev1listers.SecretLister
66
- targetNSDeploymentsLister appsv1listers.DeploymentLister
67
- targetNSConfigLister corev1listers.ConfigMapLister
68
57
69
- authStatusHandler status.AuthStatusHandler
58
+ authStatusHandler * status.AuthStatusHandler
70
59
}
71
60
72
61
func NewOAuthClientsController (
73
- ctx context.Context ,
74
62
operatorClient v1helpers.OperatorClient ,
75
63
oauthClient oauthclient.Interface ,
76
64
secretsClient corev1client.SecretsGetter ,
77
- crdInformer apiexensionsv1informers.CustomResourceDefinitionInformer ,
78
65
authentication configv1client.AuthenticationInterface ,
79
66
authnInformer configv1informers.AuthenticationInformer ,
80
67
consoleOperatorInformer operatorv1informers.ConsoleInformer ,
81
68
routeInformer routev1informers.RouteInformer ,
82
69
ingressConfigInformer configv1informers.IngressInformer ,
83
70
targetNSsecretsInformer corev1informers.SecretInformer ,
84
- configNSSecretsInformer corev1informers.SecretInformer ,
85
- targetNSConfigInformer corev1informers.ConfigMapInformer ,
86
- targetNSDeploymentsInformer appsv1informers.DeploymentInformer ,
87
71
oauthClientSwitchedInformer * util.InformerWithSwitch ,
88
72
recorder events.Recorder ,
89
73
) factory.Controller {
@@ -100,10 +84,6 @@ func NewOAuthClientsController(
100
84
routesLister : routeInformer .Lister (),
101
85
ingressConfigLister : ingressConfigInformer .Lister (),
102
86
targetNSSecretsLister : targetNSsecretsInformer .Lister (),
103
- configNSSecretsLister : configNSSecretsInformer .Lister (),
104
- targetNSConfigLister : targetNSConfigInformer .Lister (),
105
- targetNSDeploymentsLister : targetNSDeploymentsInformer .Lister (),
106
- crdLister : crdInformer .Lister (),
107
87
108
88
authStatusHandler : status .NewAuthStatusHandler (authentication , api .OpenShiftConsoleName , api .TargetNamespace , api .OpenShiftConsoleOperator ),
109
89
}
@@ -116,42 +96,45 @@ func NewOAuthClientsController(
116
96
routeInformer .Informer (),
117
97
ingressConfigInformer .Informer (),
118
98
targetNSsecretsInformer .Informer (),
119
- configNSSecretsInformer .Informer (),
120
- targetNSDeploymentsInformer .Informer (),
121
99
).
122
100
WithFilteredEventsInformers (
123
101
factory .NamesFilter (api .OAuthClientName ),
124
102
oauthClientSwitchedInformer .Informer (),
125
103
).
126
- WithFilteredEventsInformers (
127
- factory .NamesFilter ("authentications.config.openshift.io" ),
128
- crdInformer .Informer (),
129
- ).
130
104
WithSyncDegradedOnError (operatorClient ).
131
105
ResyncEvery (wait .Jitter (time .Minute , 1.0 )).
132
106
ToController ("OAuthClientsController" , recorder .WithComponentSuffix ("oauth-clients-controller" ))
133
107
}
134
108
135
109
func (c * oauthClientsController ) sync (ctx context.Context , controllerContext factory.SyncContext ) error {
136
- statusHandler := status .NewStatusHandler (c .operatorClient )
137
-
138
110
if shouldSync , err := c .handleManaged (ctx ); err != nil {
139
111
return err
140
112
} else if ! shouldSync {
141
113
return nil
142
114
}
143
115
144
- operatorConfig , err := c .consoleOperatorLister .Get (api .ConfigResourceName )
116
+ statusHandler := status .NewStatusHandler (c .operatorClient )
117
+
118
+ authnConfig , err := c .authnLister .Get (api .ConfigResourceName )
145
119
if err != nil {
146
120
return err
147
121
}
148
122
149
- ingressConfig , err := c .ingressConfigLister .Get (api .ConfigResourceName )
123
+ switch authnConfig .Spec .Type {
124
+ case "" , configv1 .AuthenticationTypeIntegratedOAuth :
125
+ default :
126
+ // if we're not using integrated oauth, reset all degraded conditions
127
+ statusHandler .AddConditions (status .HandleProgressingOrDegraded ("OAuthClientSecretSync" , "" , nil ))
128
+ statusHandler .AddConditions (status .HandleProgressingOrDegraded ("OAuthClientSync" , "" , nil ))
129
+ return statusHandler .FlushAndReturn (nil )
130
+ }
131
+
132
+ operatorConfig , err := c .consoleOperatorLister .Get (api .ConfigResourceName )
150
133
if err != nil {
151
134
return err
152
135
}
153
136
154
- authnConfig , err := c .authnLister .Get (api .ConfigResourceName )
137
+ ingressConfig , err := c .ingressConfigLister .Get (api .ConfigResourceName )
155
138
if err != nil {
156
139
return err
157
140
}
@@ -167,142 +150,25 @@ func (c *oauthClientsController) sync(ctx context.Context, controllerContext fac
167
150
return routeErr
168
151
}
169
152
170
- var syncErr error
171
- switch authnConfig .Spec .Type {
172
- case "" , configv1 .AuthenticationTypeIntegratedOAuth :
173
- waitCtx , cancel := context .WithTimeout (ctx , 10 * time .Second )
174
- defer cancel ()
175
- if ! cache .WaitForCacheSync (waitCtx .Done (), c .oauthClientSwitchedInformer .Informer ().HasSynced ) {
176
- return statusHandler .FlushAndReturn (fmt .Errorf ("timed out waiting for OAuthClients cache sync" ))
177
- }
178
-
179
- clientSecret , secErr := c .syncSecret (ctx , operatorConfig , controllerContext .Recorder ())
180
- statusHandler .AddConditions (status .HandleProgressingOrDegraded ("OAuthClientSecretSync" , "FailedApply" , secErr ))
181
- if secErr != nil {
182
- return statusHandler .FlushAndReturn (secErr )
183
- }
184
-
185
- oauthErrReason , oauthErr := c .syncOAuthClient (ctx , clientSecret , consoleURL .String ())
186
- statusHandler .AddConditions (status .HandleProgressingOrDegraded ("OAuthClientSync" , oauthErrReason , oauthErr ))
187
- if oauthErr != nil {
188
- return statusHandler .FlushAndReturn (oauthErr )
189
- }
190
-
191
- case configv1 .AuthenticationTypeOIDC :
192
- syncErr = c .syncAuthTypeOIDC (ctx , controllerContext , statusHandler , operatorConfig , authnConfig )
193
- if syncErr != nil {
194
- return statusHandler .FlushAndReturn (syncErr )
195
- }
153
+ waitCtx , cancel := context .WithTimeout (ctx , 10 * time .Second )
154
+ defer cancel ()
155
+ if ! cache .WaitForCacheSync (waitCtx .Done (), c .oauthClientSwitchedInformer .Informer ().HasSynced ) {
156
+ return statusHandler .FlushAndReturn (fmt .Errorf ("timed out waiting for OAuthClients cache sync" ))
196
157
}
197
158
198
- oidcClientsSchema , err := authnConfigHasOIDCFields (c .crdLister )
159
+ clientSecret , err := c .syncSecret (ctx , operatorConfig , controllerContext .Recorder ())
160
+ statusHandler .AddConditions (status .HandleProgressingOrDegraded ("OAuthClientSecretSync" , "FailedApply" , err ))
199
161
if err != nil {
200
162
return statusHandler .FlushAndReturn (err )
201
163
}
202
164
203
- if oidcClientsSchema {
204
- applyErr := c .authStatusHandler .Apply (ctx , authnConfig )
205
- statusHandler .AddConditions (status .HandleProgressingOrDegraded ("AuthStatusHandler" , "FailedApply" , applyErr ))
206
- if applyErr != nil {
207
- return statusHandler .FlushAndReturn (applyErr )
208
- }
209
- }
210
-
211
- return statusHandler .FlushAndReturn (nil )
212
- }
213
-
214
- func (c * oauthClientsController ) syncAuthTypeOIDC (
215
- ctx context.Context ,
216
- controllerContext factory.SyncContext ,
217
- statusHandler status.StatusHandler ,
218
- operatorConfig * operatorv1.Console ,
219
- authnConfig * configv1.Authentication ,
220
- ) error {
221
-
222
- clientConfig := utilsub .GetOIDCClientConfig (authnConfig )
223
- if clientConfig == nil {
224
- c .authStatusHandler .WithCurrentOIDCClient ("" )
225
- c .authStatusHandler .Unavailable ("OIDCClientConfig" , "no OIDC client found" )
226
- return nil
227
- }
228
-
229
- if len (clientConfig .ClientID ) == 0 {
230
- err := fmt .Errorf ("no ID set on OIDC client" )
231
- statusHandler .AddConditions (status .HandleProgressingOrDegraded ("OIDCClientConfig" , "MissingID" , err ))
232
- return statusHandler .FlushAndReturn (err )
233
- }
234
- c .authStatusHandler .WithCurrentOIDCClient (clientConfig .ClientID )
235
-
236
- if len (clientConfig .ClientSecret .Name ) == 0 {
237
- c .authStatusHandler .Degraded ("OIDCClientMissingSecret" , "no client secret in the OIDC client config" )
238
- return nil
239
- }
240
-
241
- clientSecret , err := c .configNSSecretsLister .Secrets (api .OpenShiftConfigNamespace ).Get (clientConfig .ClientSecret .Name )
165
+ oauthErrReason , err := c .syncOAuthClient (ctx , clientSecret , consoleURL .String ())
166
+ statusHandler .AddConditions (status .HandleProgressingOrDegraded ("OAuthClientSync" , oauthErrReason , err ))
242
167
if err != nil {
243
- c .authStatusHandler .Degraded ("OIDCClientSecretGet" , err .Error ())
244
- return err
245
- }
246
-
247
- secret , err := c .targetNSSecretsLister .Secrets (api .TargetNamespace ).Get (secretsub .Stub ().Name )
248
- expectedClientSecret := secretsub .GetSecretString (clientSecret )
249
- if apierrors .IsNotFound (err ) || secretsub .GetSecretString (secret ) != expectedClientSecret {
250
- secret , _ , err = resourceapply .ApplySecret (ctx , c .secretsClient , controllerContext .Recorder (), secretsub .DefaultSecret (operatorConfig , expectedClientSecret ))
251
- if err != nil {
252
- statusHandler .AddConditions (status .HandleProgressingOrDegraded ("OIDCClientSecretSync" , "FailedApply" , err ))
253
- return err
254
- }
255
- }
256
-
257
- if valid , msg , err := c .checkClientConfigStatus (authnConfig , secret ); err != nil {
258
- c .authStatusHandler .Degraded ("DeploymentOIDCConfig" , err .Error ())
259
- return err
260
-
261
- } else if ! valid {
262
- c .authStatusHandler .Progressing ("DeploymentOIDCConfig" , msg )
263
- return nil
264
- }
265
-
266
- c .authStatusHandler .Available ("OIDCConfigAvailable" , "" )
267
- return nil
268
- }
269
-
270
- // checkClientConfigStatus checks whether the current client configuration is being currently in use,
271
- // by looking at the deployment status. It checks whether the deployment is available and updated,
272
- // and also whether the resource versions for the oauth secret and server CA trust configmap match
273
- // the deployment.
274
- func (c * oauthClientsController ) checkClientConfigStatus (authnConfig * configv1.Authentication , clientSecret * corev1.Secret ) (bool , string , error ) {
275
- depl , err := c .targetNSDeploymentsLister .Deployments (api .OpenShiftConsoleNamespace ).Get (api .OpenShiftConsoleDeploymentName )
276
- if err != nil {
277
- return false , "" , err
278
- }
279
-
280
- deplAvailableUpdated := deploymentsub .IsAvailableAndUpdated (depl )
281
- if ! deplAvailableUpdated {
282
- return false , "deployment unavailable or outdated" , nil
283
- }
284
-
285
- if clientSecret .GetResourceVersion () != depl .ObjectMeta .Annotations ["console.openshift.io/oauth-secret-version" ] {
286
- return false , "client secret version not up to date in current deployment" , nil
287
- }
288
-
289
- if len (authnConfig .Spec .OIDCProviders ) > 0 {
290
- serverCAConfigName := authnConfig .Spec .OIDCProviders [0 ].Issuer .CertificateAuthority .Name
291
- if len (serverCAConfigName ) == 0 {
292
- return deplAvailableUpdated , "" , nil
293
- }
294
-
295
- serverCAConfig , err := c .targetNSConfigLister .ConfigMaps (api .OpenShiftConsoleNamespace ).Get (serverCAConfigName )
296
- if err != nil {
297
- return false , "" , err
298
- }
299
-
300
- if serverCAConfig .GetResourceVersion () != depl .ObjectMeta .Annotations ["console.openshift.io/authn-ca-trust-config-version" ] {
301
- return false , "OIDC provider CA version not up to date in current deployment" , nil
302
- }
168
+ return statusHandler .FlushAndReturn (err )
303
169
}
304
170
305
- return deplAvailableUpdated , "" , nil
171
+ return statusHandler . FlushAndReturn ( nil )
306
172
}
307
173
308
174
// handleStatus returns whether sync should happen and any error encountering
@@ -375,28 +241,3 @@ func (c *oauthClientsController) deregisterClient(ctx context.Context) error {
375
241
return err
376
242
377
243
}
378
-
379
- func authnConfigHasOIDCFields (crdLister apiexensionsv1listers.CustomResourceDefinitionLister ) (bool , error ) {
380
- authnCRD , err := crdLister .Get ("authentications.config.openshift.io" )
381
- if err != nil {
382
- return false , err
383
- }
384
-
385
- var authnV1Config * apiexensionsv1.CustomResourceDefinitionVersion
386
- for _ , version := range authnCRD .Spec .Versions {
387
- if version .Name == "v1" && version .Served && version .Storage {
388
- authnV1Config = & version
389
- break
390
- }
391
- }
392
-
393
- if authnV1Config == nil {
394
- return false , fmt .Errorf ("authentications.config.openshift.io is not served or stored as v1" )
395
- }
396
-
397
- schema := authnV1Config .Schema .OpenAPIV3Schema
398
- _ , clientsExist := schema .Properties ["status" ].Properties ["oidcClients" ]
399
-
400
- return clientsExist , nil
401
-
402
- }
0 commit comments