Skip to content

Commit df0a115

Browse files
committed
operator: start externaloidc controller behind a featuregates accessor
1 parent 436220f commit df0a115

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

pkg/operator/replacement_starter.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,5 +317,12 @@ func CreateOperatorStarter(ctx context.Context, authOperatorInput *authenticatio
317317
ret.ControllerRunFns = append(ret.ControllerRunFns, oauthAPIServerRunFns...)
318318
ret.ControllerNamedRunOnceFns = append(ret.ControllerNamedRunOnceFns, oauthAPIServerRunOnceFns...)
319319

320+
externalOIDCRunOnceFns, externalOIDCRunFns, err := prepareExternalOIDC(ctx, authOperatorInput, informerFactories)
321+
if err != nil {
322+
return nil, fmt.Errorf("unable to prepare external OIDC: %w", err)
323+
}
324+
ret.ControllerRunFns = append(ret.ControllerRunFns, externalOIDCRunFns...)
325+
ret.ControllerNamedRunOnceFns = append(ret.ControllerNamedRunOnceFns, externalOIDCRunOnceFns...)
326+
320327
return ret, nil
321328
}

pkg/operator/starter.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import (
1212
"github.com/openshift/multi-operator-manager/pkg/library/libraryapplyconfiguration"
1313

1414
configv1 "github.com/openshift/api/config/v1"
15+
"github.com/openshift/api/features"
1516
operatorv1 "github.com/openshift/api/operator/v1"
1617
routev1 "github.com/openshift/api/route/v1"
1718
applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"
1819
"github.com/openshift/cluster-authentication-operator/bindata"
1920
"github.com/openshift/cluster-authentication-operator/pkg/controllers/configobservation/configobservercontroller"
2021
componentroutesecretsync "github.com/openshift/cluster-authentication-operator/pkg/controllers/customroute"
2122
"github.com/openshift/cluster-authentication-operator/pkg/controllers/deployment"
23+
"github.com/openshift/cluster-authentication-operator/pkg/controllers/externaloidc"
2224
"github.com/openshift/cluster-authentication-operator/pkg/controllers/ingressnodesavailable"
2325
"github.com/openshift/cluster-authentication-operator/pkg/controllers/ingressstate"
2426
"github.com/openshift/cluster-authentication-operator/pkg/controllers/metadata"
@@ -39,6 +41,7 @@ import (
3941
workloadcontroller "github.com/openshift/library-go/pkg/operator/apiserver/controller/workload"
4042
apiservercontrollerset "github.com/openshift/library-go/pkg/operator/apiserver/controllerset"
4143
"github.com/openshift/library-go/pkg/operator/certrotation"
44+
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
4245
"github.com/openshift/library-go/pkg/operator/csr"
4346
"github.com/openshift/library-go/pkg/operator/encryption"
4447
"github.com/openshift/library-go/pkg/operator/encryption/controllers/migrators"
@@ -673,6 +676,52 @@ func prepareOauthAPIServerOperator(
673676
return runOnceFns, runFns, nil
674677
}
675678

679+
func prepareExternalOIDC(
680+
ctx context.Context,
681+
authOperatorInput *authenticationOperatorInput,
682+
informerFactories authenticationOperatorInformerFactories,
683+
) ([]libraryapplyconfiguration.NamedRunOnce, []libraryapplyconfiguration.RunFunc, error) {
684+
685+
// By default, this will exit(0) if the featuregates change
686+
featureGateAccessor := featuregates.NewFeatureGateAccess(
687+
status.VersionForOperatorFromEnv(), "0.0.1-snapshot",
688+
informerFactories.operatorConfigInformer.Config().V1().ClusterVersions(),
689+
informerFactories.operatorConfigInformer.Config().V1().FeatureGates(),
690+
authOperatorInput.eventRecorder,
691+
)
692+
go featureGateAccessor.Run(ctx)
693+
go informerFactories.operatorConfigInformer.Start(ctx.Done())
694+
695+
var featureGates featuregates.FeatureGate
696+
select {
697+
case <-featureGateAccessor.InitialFeatureGatesObserved():
698+
featureGates, _ = featureGateAccessor.CurrentFeatureGates()
699+
case <-time.After(1 * time.Minute):
700+
return nil, nil, fmt.Errorf("timed out waiting for FeatureGate detection")
701+
}
702+
703+
if !featureGates.Enabled(features.FeatureGateExternalOIDC) {
704+
return nil, nil, nil
705+
}
706+
707+
externalOIDCController := externaloidc.NewExternalOIDCController(
708+
informerFactories.kubeInformersForNamespaces,
709+
informerFactories.operatorConfigInformer,
710+
authOperatorInput.authenticationOperatorClient,
711+
authOperatorInput.kubeClient.CoreV1(),
712+
authOperatorInput.eventRecorder,
713+
)
714+
715+
runOnceFns := []libraryapplyconfiguration.NamedRunOnce{
716+
libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, "TODO-other-externalOIDCController", externalOIDCController.Sync),
717+
}
718+
runFns := []libraryapplyconfiguration.RunFunc{
719+
libraryapplyconfiguration.AdaptRunFn(externalOIDCController.Run),
720+
}
721+
722+
return runOnceFns, runFns, nil
723+
}
724+
676725
func singleNameListOptions(name string) func(opts *metav1.ListOptions) {
677726
return func(opts *metav1.ListOptions) {
678727
opts.FieldSelector = fields.OneTermEqualSelector("metadata.name", name).String()

0 commit comments

Comments
 (0)