7
7
"time"
8
8
9
9
corev1 "k8s.io/api/core/v1"
10
+ "k8s.io/apimachinery/pkg/api/errors"
10
11
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
12
"k8s.io/apimachinery/pkg/util/wait"
12
13
corev1informers "k8s.io/client-go/informers/core/v1"
@@ -15,6 +16,7 @@ import (
15
16
"k8s.io/klog/v2"
16
17
17
18
configv1 "github.com/openshift/api/config/v1"
19
+ oauthv1 "github.com/openshift/api/oauth/v1"
18
20
operatorv1 "github.com/openshift/api/operator/v1"
19
21
configv1informers "github.com/openshift/client-go/config/informers/externalversions/config/v1"
20
22
configv1lister "github.com/openshift/client-go/config/listers/config/v1"
@@ -40,7 +42,7 @@ import (
40
42
// oauthClientsController:
41
43
//
42
44
// updates:
43
- // - oauthclient.oauth.openshift.io/console (created by CVO )
45
+ // - oauthclient.oauth.openshift.io/console (creates if doesn't exist )
44
46
// writes:
45
47
// - consoles.operator.openshift.io/cluster .status.conditions:
46
48
// - type=OAuthClientSyncProgressing
@@ -206,10 +208,21 @@ func (c *oauthClientsController) syncOAuthClient(
206
208
consoleURL string ,
207
209
) (reason string , err error ) {
208
210
oauthClient , err := c .oauthClientLister .Get (oauthsub .Stub ().Name )
209
- if err != nil {
211
+ if err != nil && ! errors . IsNotFound ( err ) {
210
212
// at this point we must die & wait for someone to fix the lack of an outhclient. there is nothing we can do.
211
- return "FailedGet" , fmt .Errorf ("oauth client for console does not exist and cannot be created (%w)" , err )
213
+ return "FailedGet" , fmt .Errorf ("getting console oauth client (%w)" , err )
214
+ }
215
+
216
+ if errors .IsNotFound (err ) {
217
+ oauthClient = & oauthv1.OAuthClient {
218
+ ObjectMeta : metav1.ObjectMeta {
219
+ Name : oauthsub .Stub ().Name ,
220
+ },
221
+ GrantMethod : oauthv1 .GrantHandlerAuto ,
222
+ RespondWithChallenges : false ,
223
+ }
212
224
}
225
+
213
226
clientCopy := oauthClient .DeepCopy ()
214
227
oauthsub .RegisterConsoleToOAuthClient (clientCopy , consoleURL , secretsub .GetSecretString (sec ))
215
228
_ , _ , oauthErr := oauthsub .CustomApplyOAuth (c .oauthClient , clientCopy , ctx )
@@ -233,5 +246,4 @@ func (c *oauthClientsController) deregisterClient(ctx context.Context) error {
233
246
updated := oauthsub .DeRegisterConsoleFromOAuthClient (existingOAuthClient .DeepCopy ())
234
247
_ , err = c .oauthClient .OAuthClients ().Update (ctx , updated , metav1.UpdateOptions {})
235
248
return err
236
-
237
249
}
0 commit comments