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
@@ -207,10 +209,21 @@ func (c *oauthClientsController) syncOAuthClient(
207
209
consoleURL string ,
208
210
) (reason string , err error ) {
209
211
oauthClient , err := c .oauthClientLister .Get (oauthsub .Stub ().Name )
210
- if err != nil {
212
+ if err != nil && ! errors . IsNotFound ( err ) {
211
213
// at this point we must die & wait for someone to fix the lack of an outhclient. there is nothing we can do.
212
- return "FailedGet" , fmt .Errorf ("oauth client for console does not exist and cannot be created (%w)" , err )
214
+ return "FailedGet" , fmt .Errorf ("getting console oauth client (%w)" , err )
215
+ }
216
+
217
+ if errors .IsNotFound (err ) {
218
+ oauthClient = & oauthv1.OAuthClient {
219
+ ObjectMeta : metav1.ObjectMeta {
220
+ Name : oauthsub .Stub ().Name ,
221
+ },
222
+ GrantMethod : oauthv1 .GrantHandlerAuto ,
223
+ RespondWithChallenges : false ,
224
+ }
213
225
}
226
+
214
227
clientCopy := oauthClient .DeepCopy ()
215
228
oauthsub .RegisterConsoleToOAuthClient (clientCopy , consoleURL , secretsub .GetSecretString (sec ))
216
229
_ , _ , oauthErr := oauthsub .CustomApplyOAuth (c .oauthClient , clientCopy , ctx )
@@ -234,5 +247,4 @@ func (c *oauthClientsController) deregisterClient(ctx context.Context) error {
234
247
updated := oauthsub .DeRegisterConsoleFromOAuthClient (existingOAuthClient .DeepCopy ())
235
248
_ , err = c .oauthClient .OAuthClients ().Update (ctx , updated , metav1.UpdateOptions {})
236
249
return err
237
-
238
250
}
0 commit comments