From 30dea78ecc94b18e99995f5620fb8ea65046ff37 Mon Sep 17 00:00:00 2001 From: David Eads Date: Fri, 18 Oct 2024 12:51:30 -0400 Subject: [PATCH] separate apply-configuration live from apply-configuration --- pkg/cmd/mom/apply_configuration_command.go | 2 - .../mom/apply_configuration_live_command.go | 33 +++++++++++ pkg/operator/replacement_starter.go | 17 ++++++ pkg/operator/starter.go | 59 +++++++++++++++++-- 4 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 pkg/cmd/mom/apply_configuration_live_command.go diff --git a/pkg/cmd/mom/apply_configuration_command.go b/pkg/cmd/mom/apply_configuration_command.go index 0b16696b2..77da1a06d 100644 --- a/pkg/cmd/mom/apply_configuration_command.go +++ b/pkg/cmd/mom/apply_configuration_command.go @@ -16,8 +16,6 @@ func NewApplyConfigurationCommand(streams genericiooptions.IOStreams) *cobra.Com } func RunApplyConfiguration(ctx context.Context, input libraryapplyconfiguration.ApplyConfigurationInput) (libraryapplyconfiguration.AllDesiredMutationsGetter, error) { - // TODO initialize dynamic clients, informers, operator clients, and kubeclients from the input to demonstrate. - authenticationOperatorInput, err := operator.CreateOperatorInputFromMOM(ctx, input) if err != nil { return nil, fmt.Errorf("unable to configure operator input: %w", err) diff --git a/pkg/cmd/mom/apply_configuration_live_command.go b/pkg/cmd/mom/apply_configuration_live_command.go new file mode 100644 index 000000000..b70c4dacb --- /dev/null +++ b/pkg/cmd/mom/apply_configuration_live_command.go @@ -0,0 +1,33 @@ +package mom + +import ( + "context" + "fmt" + + "github.com/openshift/cluster-authentication-operator/pkg/operator" + + "github.com/openshift/multi-operator-manager/pkg/library/libraryapplyconfiguration" + "github.com/spf13/cobra" + "k8s.io/cli-runtime/pkg/genericiooptions" +) + +func NewApplyConfigurationLiveCommand(streams genericiooptions.IOStreams) *cobra.Command { + return libraryapplyconfiguration.NewApplyConfigurationCommand(RunApplyConfiguration, streams) +} + +func RunApplyConfigurationLive(ctx context.Context, input libraryapplyconfiguration.ApplyConfigurationInput) (libraryapplyconfiguration.AllDesiredMutationsGetter, error) { + authenticationOperatorInput, err := operator.CreateOperatorInputFromMOM(ctx, input) + if err != nil { + return nil, fmt.Errorf("unable to configure operator input: %w", err) + } + operatorStarter, err := operator.CreateOperatorStarterLive(ctx, authenticationOperatorInput) + if err != nil { + return nil, fmt.Errorf("unable to configure operators: %w", err) + } + var operatorRunError error + if err := operatorStarter.RunOnce(ctx); err != nil { + operatorRunError = fmt.Errorf("unable to run operators: %w", err) + } + + return libraryapplyconfiguration.NewApplyConfigurationFromClient(input.MutationTrackingClient.GetMutations()), operatorRunError +} diff --git a/pkg/operator/replacement_starter.go b/pkg/operator/replacement_starter.go index 6a0aaccb5..3da6e6936 100644 --- a/pkg/operator/replacement_starter.go +++ b/pkg/operator/replacement_starter.go @@ -306,3 +306,20 @@ func CreateOperatorStarter(ctx context.Context, authOperatorInput *authenticatio return ret, nil } + +func CreateOperatorStarterLive(ctx context.Context, authOperatorInput *authenticationOperatorInput) (libraryapplyconfiguration.OperatorStarter, error) { + ret := &libraryapplyconfiguration.SimpleOperatorStarter{ + Informers: append([]libraryapplyconfiguration.SimplifiedInformerFactory{}, authOperatorInput.informerFactories...), + } + + informerFactories := newInformerFactories(authOperatorInput) + ret.Informers = append(ret.Informers, informerFactories.simplifiedInformerFactories()...) + + oauthRunOnceFns, err := prepareOauthOperatorLive(ctx, authOperatorInput, informerFactories) + if err != nil { + return nil, fmt.Errorf("unable to prepare oauth server: %w", err) + } + ret.ControllerRunOnceFns = append(ret.ControllerRunOnceFns, oauthRunOnceFns...) + + return ret, nil +} diff --git a/pkg/operator/starter.go b/pkg/operator/starter.go index 921767f87..a3ad6de78 100644 --- a/pkg/operator/starter.go +++ b/pkg/operator/starter.go @@ -328,10 +328,11 @@ func prepareOauthOperator( libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, routerCertsController.Sync), libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, serviceCAController.Sync), libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, staticResourceController.Sync), - libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, wellKnownReadyController.Sync), - libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, authRouteCheckController.Sync), - libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, authServiceCheckController.Sync), - libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, authServiceEndpointCheckController.Sync), + // moved to live + //libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, wellKnownReadyController.Sync), + //libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, authRouteCheckController.Sync), + //libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, authServiceCheckController.Sync), + //libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, authServiceEndpointCheckController.Sync), libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, workersAvailableController.Sync), libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, proxyConfigController.Sync), libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, customRouteController.Sync), @@ -377,6 +378,56 @@ func prepareOauthOperator( return runOnceFns, runFns, nil } +func prepareOauthOperatorLive( + ctx context.Context, + authOperatorInput *authenticationOperatorInput, + informerFactories authenticationOperatorInformerFactories, +) ([]libraryapplyconfiguration.RunOnceFunc, error) { + + systemCABundle, err := loadSystemCACertBundle() + if err != nil { + return nil, err + } + + wellKnownReadyController := readiness.NewWellKnownReadyController( + "openshift-authentication", + informerFactories.kubeInformersForNamespaces, + informerFactories.operatorConfigInformer, + informerFactories.namespacedOpenshiftAuthenticationRoutes.Route().V1().Routes(), + authOperatorInput.authenticationOperatorClient, + authOperatorInput.eventRecorder, + ) + + authRouteCheckController := oauthendpoints.NewOAuthRouteCheckController( + authOperatorInput.authenticationOperatorClient, + informerFactories.kubeInformersForNamespaces.InformersFor("openshift-authentication"), + informerFactories.kubeInformersForNamespaces.InformersFor("openshift-config-managed"), + informerFactories.namespacedOpenshiftAuthenticationRoutes.Route().V1().Routes(), + informerFactories.operatorConfigInformer.Config().V1().Ingresses(), + systemCABundle, + authOperatorInput.eventRecorder, + ) + authServiceCheckController := oauthendpoints.NewOAuthServiceCheckController( + authOperatorInput.authenticationOperatorClient, + informerFactories.kubeInformersForNamespaces.InformersFor("openshift-authentication"), + authOperatorInput.eventRecorder, + ) + authServiceEndpointCheckController := oauthendpoints.NewOAuthServiceEndpointsCheckController( + authOperatorInput.authenticationOperatorClient, + informerFactories.kubeInformersForNamespaces.InformersFor("openshift-authentication"), + authOperatorInput.eventRecorder, + ) + + runOnceFns := []libraryapplyconfiguration.RunOnceFunc{ + libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, wellKnownReadyController.Sync), + libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, authRouteCheckController.Sync), + libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, authServiceCheckController.Sync), + libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, authServiceEndpointCheckController.Sync), + } + + return runOnceFns, nil +} + func prepareOauthAPIServerOperator( ctx context.Context, authOperatorInput *authenticationOperatorInput,