66 "time"
77
88 "github.com/spf13/cobra"
9+ "k8s.io/klog/v2"
910
1011 "k8s.io/client-go/kubernetes"
1112 "k8s.io/utils/clock"
@@ -14,8 +15,9 @@ import (
1415 configeversionedclient "github.com/openshift/client-go/config/clientset/versioned"
1516 configexternalinformers "github.com/openshift/client-go/config/informers/externalversions"
1617 "github.com/openshift/library-go/pkg/controller/controllercmd"
17- "github.com/openshift/library-go/pkg/operator/certrotation "
18+ "github.com/openshift/library-go/pkg/operator/configobserver/featuregates "
1819 "github.com/openshift/library-go/pkg/operator/genericoperatorclient"
20+ "github.com/openshift/library-go/pkg/operator/status"
1921 "github.com/openshift/library-go/pkg/operator/v1helpers"
2022
2123 "github.com/openshift/cluster-kube-apiserver-operator/pkg/operator"
@@ -85,8 +87,6 @@ func (o *Options) Run(ctx context.Context, clock clock.Clock) error {
8587 return fmt .Errorf ("failed to create config client: %w" , err )
8688 }
8789
88- configInformers := configexternalinformers .NewSharedInformerFactory (configClient , 10 * time .Minute )
89-
9090 kubeAPIServerInformersForNamespaces := v1helpers .NewKubeInformersForNamespaces (
9191 kubeClient ,
9292 operatorclient .GlobalMachineSpecifiedConfigNamespace ,
@@ -95,6 +95,8 @@ func (o *Options) Run(ctx context.Context, clock clock.Clock) error {
9595 operatorclient .TargetNamespace ,
9696 )
9797
98+ configInformers := configexternalinformers .NewSharedInformerFactory (configClient , 10 * time .Minute )
99+
98100 operatorClient , dynamicInformers , err := genericoperatorclient .NewStaticPodOperatorClient (
99101 clock ,
100102 o .controllerContext .KubeConfig ,
@@ -107,9 +109,30 @@ func (o *Options) Run(ctx context.Context, clock clock.Clock) error {
107109 return err
108110 }
109111
110- certRotationScale , err := certrotation .GetCertRotationScale (ctx , kubeClient , operatorclient .GlobalUserSpecifiedConfigNamespace )
111- if err != nil {
112- return err
112+ // We can't start informers until after the resources have been requested. Now is the time.
113+ kubeAPIServerInformersForNamespaces .Start (ctx .Done ())
114+ dynamicInformers .Start (ctx .Done ())
115+ configInformers .Start (ctx .Done ())
116+
117+ desiredVersion := status .VersionForOperatorFromEnv ()
118+ missingVersion := "0.0.1-snapshot"
119+ featureGateAccessor := featuregates .NewFeatureGateAccess (
120+ desiredVersion , missingVersion ,
121+ configInformers .Config ().V1 ().ClusterVersions (), configInformers .Config ().V1 ().FeatureGates (),
122+ o .controllerContext .EventRecorder ,
123+ )
124+
125+ go func () {
126+ featureGateAccessor .Run (ctx )
127+ }()
128+
129+ select {
130+ case <- featureGateAccessor .InitialFeatureGatesObserved ():
131+ featureGates , _ := featureGateAccessor .CurrentFeatureGates ()
132+ klog .Infof ("FeatureGates initialized: knownFeatureGates=%v" , featureGates .KnownFeatures ())
133+ case <- time .After (1 * time .Minute ):
134+ klog .Errorf ("timed out waiting for FeatureGate detection" )
135+ return fmt .Errorf ("timed out waiting for FeatureGate detection" )
113136 }
114137
115138 kubeAPIServerCertRotationController , err := certrotationcontroller .NewCertRotationControllerOnlyWhenExpired (
@@ -118,7 +141,7 @@ func (o *Options) Run(ctx context.Context, clock clock.Clock) error {
118141 configInformers ,
119142 kubeAPIServerInformersForNamespaces ,
120143 o .controllerContext .EventRecorder ,
121- certRotationScale ,
144+ featureGateAccessor ,
122145 )
123146 if err != nil {
124147 return err
@@ -133,11 +156,6 @@ func (o *Options) Run(ctx context.Context, clock clock.Clock) error {
133156 return err
134157 }
135158
136- // We can't start informers until after the resources have been requested. Now is the time.
137- configInformers .Start (ctx .Done ())
138- kubeAPIServerInformersForNamespaces .Start (ctx .Done ())
139- dynamicInformers .Start (ctx .Done ())
140-
141159 // FIXME: These are missing a wait group to track goroutines and handle graceful termination
142160 // (@deads2k wants time to think it through)
143161
0 commit comments