Skip to content

Commit 8d37f95

Browse files
committed
operator: set oauth-specific relatedObjects dynamically in the operator status
1 parent 215805c commit 8d37f95

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

manifests/08_clusteroperator.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ status:
2020
- group: config.openshift.io
2121
name: cluster
2222
resource: oauths
23-
- group: route.openshift.io
24-
name: oauth-openshift
25-
namespace: openshift-authentication
26-
resource: routes
27-
- group: ""
28-
name: oauth-openshift
29-
namespace: openshift-authentication
30-
resource: services
3123
- group: ""
3224
name: openshift-config
3325
resource: namespaces

pkg/operator/starter.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,25 @@ func prepareOauthAPIServerOperator(
474474
statusControllerOptions = append(statusControllerOptions, apiservercontrollerset.WithStatusControllerPdbCompatibleHighInertia("(APIServer|OAuthServer)"))
475475
}
476476

477+
statusControllerOptions = append(statusControllerOptions, func(ss *status.StatusSyncer) *status.StatusSyncer {
478+
// oauth-specific relatedObjects must not be defined when OIDC is not available
479+
ss.WithRelatedObjectsFunc(func() (isset bool, objs []configv1.ObjectReference) {
480+
oidcAvailable, err := authConfigChecker.OIDCAvailable()
481+
if err != nil {
482+
klog.Infof("error while checking auth config to determine relatedObjects: %v", err)
483+
return false, nil
484+
} else if oidcAvailable {
485+
return true, nil
486+
}
487+
488+
return true, []configv1.ObjectReference{
489+
{Group: routev1.GroupName, Resource: "routes", Name: "oauth-openshift", Namespace: "openshift-authentication"},
490+
{Resource: "services", Name: "oauth-openshift", Namespace: "openshift-authentication"},
491+
}
492+
})
493+
return ss
494+
})
495+
477496
const apiServerConditionsPrefix = "APIServer"
478497

479498
apiServerControllers, err := apiservercontrollerset.NewAPIServerControllerSet(
@@ -617,8 +636,6 @@ func prepareOauthAPIServerOperator(
617636
{Group: configv1.GroupName, Resource: "authentications", Name: "cluster"},
618637
{Group: configv1.GroupName, Resource: "infrastructures", Name: "cluster"},
619638
{Group: configv1.GroupName, Resource: "oauths", Name: "cluster"},
620-
{Group: routev1.GroupName, Resource: "routes", Name: "oauth-openshift", Namespace: "openshift-authentication"},
621-
{Resource: "services", Name: "oauth-openshift", Namespace: "openshift-authentication"},
622639
{Resource: "namespaces", Name: "openshift-config"},
623640
{Resource: "namespaces", Name: "openshift-config-managed"},
624641
{Resource: "namespaces", Name: "openshift-authentication"},

test/e2e-oidc/external_oidc_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
configv1 "github.com/openshift/api/config/v1"
1818
"github.com/openshift/api/features"
1919
operatorv1 "github.com/openshift/api/operator/v1"
20+
routev1 "github.com/openshift/api/route/v1"
2021
configclient "github.com/openshift/client-go/config/clientset/versioned"
2122
oauthclient "github.com/openshift/client-go/oauth/clientset/versioned"
2223
operatorversionedclient "github.com/openshift/client-go/operator/clientset/versioned"
@@ -727,6 +728,7 @@ func (tc *testClient) validateOAuthState(t *testing.T, ctx context.Context, requ
727728
validationErrs = append(validationErrs, validateOAuthResources(ctx, dynamicClient, requireMissing)...)
728729
validationErrs = append(validationErrs, validateOAuthRoutes(ctx, tc.routeClient, tc.configClient, requireMissing)...)
729730
validationErrs = append(validationErrs, validateOAuthControllerConditions(tc.operatorClient, requireMissing)...)
731+
validationErrs = append(validationErrs, validateOAuthRelatedObjects(requireMissing)...)
730732
return len(validationErrs) == 0, nil
731733
})
732734

@@ -872,6 +874,42 @@ func validateOAuthControllerConditions(operatorClient v1helpers.OperatorClient,
872874
return nil
873875
}
874876

877+
func validateOAuthRelatedObjects(ctx context.Context, configClient *configclient.Clientset, requireMissing bool) []error {
878+
co, err := configClient.ConfigV1().ClusterOperators().Get(ctx, "authentication", metav1.GetOptions{})
879+
if err != nil {
880+
return []error{err}
881+
}
882+
883+
oauthRelatedObjects := []configv1.ObjectReference{
884+
{Group: routev1.GroupName, Resource: "routes", Name: "oauth-openshift", Namespace: "openshift-authentication"},
885+
{Resource: "services", Name: "oauth-openshift", Namespace: "openshift-authentication"},
886+
}
887+
888+
errs := make([]error, 0)
889+
for _, oauthObj := range oauthRelatedObjects {
890+
found := false
891+
for _, existingObj := range co.Status.RelatedObjects {
892+
if oauthObj.Group == existingObj.Group &&
893+
oauthObj.Resource == existingObj.Resource &&
894+
oauthObj.Name == existingObj.Name &&
895+
oauthObj.Namespace == existingObj.Namespace {
896+
found = true
897+
break
898+
}
899+
}
900+
901+
if requireMissing && found {
902+
errs = append(errs, fmt.Errorf("oauth related object %s/%s %s/%s should be missing but was found in RelatedObjects",
903+
oauthObj.Group, oauthObj.Resource, oauthObj.Namespace, oauthObj.Name))
904+
} else if !requireMissing && !found {
905+
errs = append(errs, fmt.Errorf("oauth related object %s/%s %s/%s should be present but was not found in RelatedObjects",
906+
oauthObj.Group, oauthObj.Resource, oauthObj.Namespace, oauthObj.Name))
907+
}
908+
}
909+
910+
return errs
911+
}
912+
875913
func (tc *testClient) testOIDCAuthentication(t *testing.T, ctx context.Context, kcClient *test.KeycloakClient, usernameClaim, usernamePrefix string, expectAuthSuccess bool) {
876914
// re-authenticate to ensure we always have a fresh token
877915
var err error

0 commit comments

Comments
 (0)