Skip to content

Commit 12765b7

Browse files
committed
controllers/oauthclients: make console operator responsible for creating console oauth client
instead of relying on CVO to create it. This makes it so that we can prevent CVO from entering a bad state when cluster authentication type is set to OIDC. Signed-off-by: Bryce Palmer <[email protected]>
1 parent dbb03bb commit 12765b7

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

manifests/01-oauth.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

manifests/03-rbac-role-cluster.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ rules:
2525
- get
2626
- list
2727
- watch
28+
- create
2829
- apiGroups:
2930
- oauth.openshift.io
3031
resources:

pkg/console/controllers/oauthclients/oauthclients.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
corev1 "k8s.io/api/core/v1"
10+
"k8s.io/apimachinery/pkg/api/errors"
1011
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1112
"k8s.io/apimachinery/pkg/util/wait"
1213
corev1informers "k8s.io/client-go/informers/core/v1"
@@ -15,6 +16,7 @@ import (
1516
"k8s.io/klog/v2"
1617

1718
configv1 "github.com/openshift/api/config/v1"
19+
oauthv1 "github.com/openshift/api/oauth/v1"
1820
operatorv1 "github.com/openshift/api/operator/v1"
1921
configv1informers "github.com/openshift/client-go/config/informers/externalversions/config/v1"
2022
configv1lister "github.com/openshift/client-go/config/listers/config/v1"
@@ -40,7 +42,7 @@ import (
4042
// oauthClientsController:
4143
//
4244
// updates:
43-
// - oauthclient.oauth.openshift.io/console (created by CVO)
45+
// - oauthclient.oauth.openshift.io/console (creates if doesn't exist)
4446
// writes:
4547
// - consoles.operator.openshift.io/cluster .status.conditions:
4648
// - type=OAuthClientSyncProgressing
@@ -206,10 +208,21 @@ func (c *oauthClientsController) syncOAuthClient(
206208
consoleURL string,
207209
) (reason string, err error) {
208210
oauthClient, err := c.oauthClientLister.Get(oauthsub.Stub().Name)
209-
if err != nil {
211+
if err != nil && !errors.IsNotFound(err) {
210212
// 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+
}
212224
}
225+
213226
clientCopy := oauthClient.DeepCopy()
214227
oauthsub.RegisterConsoleToOAuthClient(clientCopy, consoleURL, secretsub.GetSecretString(sec))
215228
_, _, oauthErr := oauthsub.CustomApplyOAuth(c.oauthClient, clientCopy, ctx)
@@ -233,5 +246,4 @@ func (c *oauthClientsController) deregisterClient(ctx context.Context) error {
233246
updated := oauthsub.DeRegisterConsoleFromOAuthClient(existingOAuthClient.DeepCopy())
234247
_, err = c.oauthClient.OAuthClients().Update(ctx, updated, metav1.UpdateOptions{})
235248
return err
236-
237249
}

0 commit comments

Comments
 (0)