Skip to content

Commit 67c3f06

Browse files
authored
Integrate APIServer TLS controller into OLM operator (#3744)
Adds cluster-wide TLS configuration support to the OLM operator's HTTPS metrics/health server on OpenShift clusters. Optimizes the discovery calls for both proxy and apiserver into a single call. On OpenShift, the metrics server now automatically adopts cluster-wide TLS security profiles (Old, Intermediate, Modern, Custom) without restart. Assisted-By: Claude Signed-off-by: Todd Short <todd.short@me.com>
1 parent ea9b449 commit 67c3f06

3 files changed

Lines changed: 61 additions & 27 deletions

File tree

cmd/olm/main.go

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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")

pkg/controller/operators/olm/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type operatorConfig struct {
3737
apiLabeler labeler.Labeler
3838
restConfig *rest.Config
3939
configClient configv1client.Interface
40+
openshiftConfigAPIExists bool
4041
}
4142

4243
func (o *operatorConfig) OperatorClient() operatorclient.ClientInterface {
@@ -202,3 +203,9 @@ func WithConfigClient(configClient configv1client.Interface) OperatorOption {
202203
config.configClient = configClient
203204
}
204205
}
206+
207+
func WithOpenshiftConfigAPIExists(exists bool) OperatorOption {
208+
return func(config *operatorConfig) {
209+
config.openshiftConfigAPIExists = exists
210+
}
211+
}

pkg/controller/operators/olm/operator.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import (
5757
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/event"
5858
index "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/index"
5959
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/labeler"
60-
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/openshiftconfig"
6160
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
6261
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
6362
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
@@ -853,18 +852,10 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
853852
return nil, err
854853
}
855854

856-
// Check if OpenShift config API is available (used by proxy and apiserver controllers)
857-
discovery := config.operatorClient.KubernetesInterface().Discovery()
858-
openshiftConfigAPIExists, err := openshiftconfig.IsAPIAvailable(discovery)
859-
if err != nil {
860-
op.logger.Errorf("error happened while probing for OpenShift config API support - %v", err)
861-
return nil, err
862-
}
863-
864855
// setup proxy env var injection policies
865856
proxyQuerierInUse := proxy.NoopQuerier()
866-
if openshiftConfigAPIExists {
867-
op.logger.Info("OpenShift Proxy API available - setting up watch for Proxy type")
857+
if config.openshiftConfigAPIExists {
858+
op.logger.Info("OpenShift Proxy API available - setting up watch for Proxy type")
868859

869860
proxyInformer, proxySyncer, proxyQuerier, err := proxy.NewSyncer(op.logger, config.configClient)
870861
if err != nil {

0 commit comments

Comments
 (0)