@@ -23,6 +23,8 @@ import (
2323 "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm"
2424 "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/openshift"
2525 "github.com/operator-framework/operator-lifecycle-manager/pkg/feature"
26+ "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/apiserver"
27+ "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/openshiftconfig"
2628 "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
2729 "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorstatus"
2830 "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/queueinformer"
@@ -129,22 +131,6 @@ func main() {
129131 }
130132 config := mgr .GetConfig ()
131133
132- listenAndServe , err := server .GetListenAndServeFunc (
133- server .WithLogger (logger ),
134- server .WithTLS (tlsCertPath , tlsKeyPath , clientCAPath ),
135- server .WithKubeConfig (config ),
136- server .WithDebug (* debug ),
137- )
138- if err != nil {
139- logger .Fatalf ("Error setting up health/metric/pprof service: %v" , err )
140- }
141-
142- go func () {
143- if err := listenAndServe (); err != nil && err != http .ErrServerClosed {
144- logger .Error (err )
145- }
146- }()
147-
148134 // create a config that validates we're creating objects with labels
149135 validatingConfig := validatingroundtripper .Wrap (config , mgr .GetScheme ())
150136
@@ -169,6 +155,50 @@ func main() {
169155 logger .WithError (err ).Fatal ("error configuring metadata client" )
170156 }
171157
158+ // Setup APIServer TLS configuration for HTTPS servers
159+ discovery := opClient .KubernetesInterface ().Discovery ()
160+ openshiftConfigAPIExists , err := openshiftconfig .IsAPIAvailable (discovery )
161+ if err != nil {
162+ logger .WithError (err ).Fatal ("error checking for OpenShift config API support" )
163+ }
164+
165+ apiServerTLSQuerier := apiserver .NoopQuerier ()
166+ var apiServerFactory interface { Start (<- chan struct {}) }
167+ if openshiftConfigAPIExists {
168+ logger .Info ("OpenShift APIServer API available - setting up watch for APIServer TLS configuration" )
169+
170+ apiServerInformer , apiServerSyncer , querier , factory , err := apiserver .NewSyncer (logger , versionedConfigClient )
171+ if err != nil {
172+ logger .WithError (err ).Fatal ("error initializing APIServer TLS syncer" )
173+ }
174+
175+ logger .Info ("APIServer TLS configuration will be applied to HTTPS servers" )
176+ apiServerTLSQuerier = querier
177+
178+ // Register event handlers for APIServer resource changes
179+ apiserver .RegisterEventHandlers (apiServerInformer , apiServerSyncer )
180+
181+ apiServerFactory = factory
182+ }
183+
184+ // Setup metrics/health server with TLS configuration
185+ listenAndServe , err := server .GetListenAndServeFunc (
186+ server .WithLogger (logger ),
187+ server .WithTLS (tlsCertPath , tlsKeyPath , clientCAPath ),
188+ server .WithKubeConfig (config ),
189+ server .WithAPIServerTLSQuerier (apiServerTLSQuerier ),
190+ server .WithDebug (* debug ),
191+ )
192+ if err != nil {
193+ logger .Fatalf ("Error setting up health/metric/pprof service: %v" , err )
194+ }
195+
196+ go func () {
197+ if err := listenAndServe (); err != nil && err != http .ErrServerClosed {
198+ logger .Error (err )
199+ }
200+ }()
201+
172202 // Create a new instance of the operator.
173203 op , err := olm .NewOperator (
174204 ctx ,
@@ -181,6 +211,7 @@ func main() {
181211 olm .WithRestConfig (validatingConfig ),
182212 olm .WithConfigClient (versionedConfigClient ),
183213 olm .WithProtectedCopiedCSVNamespaces (* protectedCopiedCSVNamespaces ),
214+ olm .WithOpenshiftConfigAPIExists (openshiftConfigAPIExists ),
184215 )
185216 if err != nil {
186217 logger .WithError (err ).Fatal ("error configuring operator" )
@@ -190,6 +221,11 @@ func main() {
190221 op .Run (ctx )
191222 <- op .Ready ()
192223
224+ // Start APIServer TLS informer factory if on OpenShift
225+ if apiServerFactory != nil {
226+ apiServerFactory .Start (ctx .Done ())
227+ }
228+
193229 // Emit CSV metric
194230 if err = op .EnsureCSVMetric (); err != nil {
195231 logger .WithError (err ).Fatal ("error emitting metrics for existing CSV" )
0 commit comments