@@ -11,7 +11,10 @@ import (
1111 apiconfigv1 "github.com/openshift/api/config/v1"
1212 configv1client "github.com/openshift/client-go/config/clientset/versioned"
1313 configv1 "github.com/openshift/client-go/config/informers/externalversions/config/v1"
14+ "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/openshiftconfig"
1415 "github.com/sirupsen/logrus"
16+ "k8s.io/client-go/kubernetes"
17+ "k8s.io/client-go/rest"
1518 "k8s.io/client-go/tools/cache"
1619)
1720
@@ -58,6 +61,53 @@ func RegisterEventHandlers(informer configv1.APIServerInformer, syncer *Syncer)
5861 })
5962}
6063
64+ // SetupAPIServerTLSConfig sets up the APIServer TLS configuration for HTTPS servers.
65+ // It checks if OpenShift config API is available and if so, creates the necessary
66+ // syncer and informer infrastructure to watch for cluster-wide TLS configuration changes.
67+ //
68+ // Returns:
69+ // - querier: A Querier that can be used to get TLS configuration (NoopQuerier if OpenShift API not available)
70+ // - factory: A SharedInformerFactory that must be started after operators are ready (nil if OpenShift API not available)
71+ // - error: Any error encountered during setup
72+ func SetupAPIServerTLSConfig (logger * logrus.Logger , config * rest.Config ) (Querier , interface { Start (<- chan struct {}) }, error ) {
73+ // Create Kubernetes client for discovery
74+ clientset , err := kubernetes .NewForConfig (config )
75+ if err != nil {
76+ return nil , nil , fmt .Errorf ("error creating kubernetes client: %w" , err )
77+ }
78+
79+ // Check if OpenShift config API is available
80+ openshiftConfigAPIExists , err := openshiftconfig .IsAPIAvailable (clientset .Discovery ())
81+ if err != nil {
82+ return nil , nil , fmt .Errorf ("error checking for OpenShift config API support: %w" , err )
83+ }
84+
85+ if ! openshiftConfigAPIExists {
86+ return NoopQuerier (), nil , nil
87+ }
88+
89+ logger .Info ("OpenShift APIServer API available - setting up watch for APIServer TLS configuration" )
90+
91+ // Create versioned config client
92+ versionedConfigClient , err := configv1client .NewForConfig (config )
93+ if err != nil {
94+ return nil , nil , fmt .Errorf ("error configuring openshift config client: %w" , err )
95+ }
96+
97+ // Create syncer and informer
98+ apiServerInformer , apiServerSyncer , apiServerQuerier , apiServerFactory , err := NewSyncer (logger , versionedConfigClient )
99+ if err != nil {
100+ return nil , nil , fmt .Errorf ("error initializing APIServer TLS syncer: %w" , err )
101+ }
102+
103+ logger .Info ("APIServer TLS configuration will be applied to HTTPS servers" )
104+
105+ // Register event handlers for APIServer resource changes
106+ RegisterEventHandlers (apiServerInformer , apiServerSyncer )
107+
108+ return apiServerQuerier , apiServerFactory , nil
109+ }
110+
61111// Syncer deals with watching APIServer type(s) on the cluster and let the caller
62112// query for cluster scoped APIServer TLS configuration.
63113type Syncer struct {
0 commit comments