Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce an interface for controllers to improve consistency #3263

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Commits on Nov 9, 2023

  1. operator: Let AROControllers configure their own loggers

    Progressing toward not exporting controller name constants.
    Matthew Barnes committed Nov 9, 2023
    Configuration menu
    Copy the full SHA
    e397ee6 View commit details
    Browse the repository at this point in the history
  2. operator: Introduce AROReconciler interface

    Initial methods are geared toward controller registration:
    
    	GetName() string
    	SetupWithManager(ctrl.Manager) error
    
    All AROController subtypes must implement SetupWithManager.
    Matthew Barnes committed Nov 9, 2023
    Configuration menu
    Copy the full SHA
    76934a5 View commit details
    Browse the repository at this point in the history
  3. operator: Do not export controller name constants

    Use AROReconciler.GetName instead.
    Matthew Barnes committed Nov 9, 2023
    Configuration menu
    Copy the full SHA
    9660fb4 View commit details
    Browse the repository at this point in the history
  4. operator: Consistency tweaks

    Matthew Barnes committed Nov 9, 2023
    Configuration menu
    Copy the full SHA
    03642e4 View commit details
    Browse the repository at this point in the history
  5. operator: Add EnabledFlag field to AROController

    Matthew Barnes committed Nov 9, 2023
    Configuration menu
    Copy the full SHA
    f1b40b0 View commit details
    Browse the repository at this point in the history
  6. operator: Add reconcile methods to AROReconciler interface

    This introduces two new methods in AROReconciler:
    
      ReconcileEnabled(ctx, request, cluster) -> (result, error)
      ReconcileDisabled(ctx, request, cluster) -> (result, error)
    
    One or the other method will be called based on the controller's
    "enabled" operator flag.
    
    AROController itself now implements the Reconcile method in order
    to consistently handle disabled controllers.  Subtypes need only
    implement the ReconcileEnabled method, called when the controller
    is enabled.
    
    The Reconcile method uses the "template method" design pattern
    from object-oriented programming.  This warrants some explanation
    since the pattern looks a little odd in Golang.
    
    Some background reading:
    https://golangbyexample.com/template-method-design-pattern-golang/
    
    AROController provides ReconcileDisabled but leaves ReconcileEnabled
    unimplemented, so ReconcileEnabled is effectively an abstract method.
    Therefore AROController itself is not an AROReconciler according to
    Golang's interface semantics, but its subtypes are.
    
    Because AROController's Reconcile method calls ReconcileEnabled,
    which is abstract, it needs a way to cast itself to an AROReconciler.
    
    This is the purpose of the Reconciler field in AROController.  The
    field is set during subtype instantiation:
    
       r := ExampleReconciler{
           AROController: base.AROController {
               Log:         ...
               Client:      ...
               Name:        ...
               EnabledFlag: ...
           }
       }
       r.Reconciler = r
       return r
    
    The Reconciler field is essentially a virtual method table like
    those inherent in polymorphic languages like C++ and Python.  It
    allows AROController to call abstract AROReconciler methods that
    are implemented by a subtype.
    Matthew Barnes committed Nov 9, 2023
    Configuration menu
    Copy the full SHA
    499680a View commit details
    Browse the repository at this point in the history
  7. operator: Add unit tests for AROController's Reconcile

    Matthew Barnes committed Nov 9, 2023
    Configuration menu
    Copy the full SHA
    3c6c252 View commit details
    Browse the repository at this point in the history