Skip to content

Commit be1d638

Browse files
committed
operator: set oauth-specific relatedObjects dynamically in the operator status
1 parent a0db9c2 commit be1d638

File tree

3 files changed

+58
-12
lines changed

3 files changed

+58
-12
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: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,27 @@ func prepareOauthAPIServerOperator(
474474
statusControllerOptions = append(statusControllerOptions, apiservercontrollerset.WithStatusControllerPdbCompatibleHighInertia("(APIServer|OAuthServer)"))
475475
}
476476

477-
// configure version removal so it removes versions it doesn't know about.
478477
statusControllerOptions = append(statusControllerOptions, func(ss *status.StatusSyncer) *status.StatusSyncer {
479-
return ss.WithVersionRemoval()
478+
// configure version removal so it removes versions it doesn't know about.
479+
s := ss.WithVersionRemoval()
480+
481+
// configure func to dynamically determine oauth-specific relatedObjects
482+
s.WithRelatedObjectsFunc(func() (isset bool, objs []configv1.ObjectReference) {
483+
oidcAvailable, err := authConfigChecker.OIDCAvailable()
484+
if err != nil {
485+
klog.Infof("error while checking auth config to determine relatedObjects: %v", err)
486+
return false, nil
487+
} else if oidcAvailable {
488+
return true, nil
489+
}
490+
491+
return true, []configv1.ObjectReference{
492+
{Group: routev1.GroupName, Resource: "routes", Name: "oauth-openshift", Namespace: "openshift-authentication"},
493+
{Resource: "services", Name: "oauth-openshift", Namespace: "openshift-authentication"},
494+
}
495+
})
496+
497+
return s
480498
})
481499

482500
const apiServerConditionsPrefix = "APIServer"
@@ -622,8 +640,6 @@ func prepareOauthAPIServerOperator(
622640
{Group: configv1.GroupName, Resource: "authentications", Name: "cluster"},
623641
{Group: configv1.GroupName, Resource: "infrastructures", Name: "cluster"},
624642
{Group: configv1.GroupName, Resource: "oauths", Name: "cluster"},
625-
{Group: routev1.GroupName, Resource: "routes", Name: "oauth-openshift", Namespace: "openshift-authentication"},
626-
{Resource: "services", Name: "oauth-openshift", Namespace: "openshift-authentication"},
627643
{Resource: "namespaces", Name: "openshift-config"},
628644
{Resource: "namespaces", Name: "openshift-config-managed"},
629645
{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"
@@ -728,6 +729,7 @@ func (tc *testClient) validateOAuthState(t *testing.T, ctx context.Context, requ
728729
validationErrs = append(validationErrs, validateOAuthRoutes(ctx, tc.routeClient, tc.configClient, requireMissing)...)
729730
validationErrs = append(validationErrs, validateOAuthControllerConditions(tc.operatorClient, requireMissing)...)
730731
validationErrs = append(validationErrs, validateOperandVersions(ctx, tc.configClient, requireMissing)...)
732+
validationErrs = append(validationErrs, validateOAuthRelatedObjects(ctx, tc.configClient, requireMissing)...)
731733
return len(validationErrs) == 0, nil
732734
})
733735

@@ -900,6 +902,42 @@ func validateOperandVersions(ctx context.Context, cfgClient *configclient.Client
900902
return nil
901903
}
902904

905+
func validateOAuthRelatedObjects(ctx context.Context, configClient *configclient.Clientset, requireMissing bool) []error {
906+
co, err := configClient.ConfigV1().ClusterOperators().Get(ctx, "authentication", metav1.GetOptions{})
907+
if err != nil {
908+
return []error{err}
909+
}
910+
911+
oauthRelatedObjects := []configv1.ObjectReference{
912+
{Group: routev1.GroupName, Resource: "routes", Name: "oauth-openshift", Namespace: "openshift-authentication"},
913+
{Resource: "services", Name: "oauth-openshift", Namespace: "openshift-authentication"},
914+
}
915+
916+
errs := make([]error, 0)
917+
for _, oauthObj := range oauthRelatedObjects {
918+
found := false
919+
for _, existingObj := range co.Status.RelatedObjects {
920+
if oauthObj.Group == existingObj.Group &&
921+
oauthObj.Resource == existingObj.Resource &&
922+
oauthObj.Name == existingObj.Name &&
923+
oauthObj.Namespace == existingObj.Namespace {
924+
found = true
925+
break
926+
}
927+
}
928+
929+
if requireMissing && found {
930+
errs = append(errs, fmt.Errorf("oauth related object %s/%s %s/%s should be missing but was found in RelatedObjects",
931+
oauthObj.Group, oauthObj.Resource, oauthObj.Namespace, oauthObj.Name))
932+
} else if !requireMissing && !found {
933+
errs = append(errs, fmt.Errorf("oauth related object %s/%s %s/%s should be present but was not found in RelatedObjects",
934+
oauthObj.Group, oauthObj.Resource, oauthObj.Namespace, oauthObj.Name))
935+
}
936+
}
937+
938+
return errs
939+
}
940+
903941
func (tc *testClient) testOIDCAuthentication(t *testing.T, ctx context.Context, kcClient *test.KeycloakClient, usernameClaim, usernamePrefix string, expectAuthSuccess bool) {
904942
// re-authenticate to ensure we always have a fresh token
905943
var err error

0 commit comments

Comments
 (0)