Skip to content

Commit

Permalink
Refactoring the code to follow our controller patterns and adding pro…
Browse files Browse the repository at this point in the history
…per message for setProgressing use case
  • Loading branch information
safwank97 committed Oct 13, 2023
1 parent abe539e commit bf8b8d9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/aro/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func operator(ctx context.Context, log *logrus.Entry) error {
client)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller %s: %v", autosizednodes.ControllerName, err)
}
if err = (machinehealthcheck.NewMachineHealthCheckReconciler(
if err = (machinehealthcheck.NewReconciler(
log.WithField("controller", machinehealthcheck.ControllerName),
client, dh)).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create controller %s: %v", machinehealthcheck.ControllerName, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ const (
enabled string = "aro.machinehealthcheck.enabled"
)

type MachineHealthCheckReconciler struct {
type Reconciler struct {
base.AROController

dh dynamichelper.Interface
}

func NewMachineHealthCheckReconciler(log *logrus.Entry, client client.Client, dh dynamichelper.Interface) *MachineHealthCheckReconciler {
return &MachineHealthCheckReconciler{
func NewReconciler(log *logrus.Entry, client client.Client, dh dynamichelper.Interface) *Reconciler {
return &Reconciler{
AROController: base.AROController{
Log: log,
Client: client,
Expand All @@ -56,7 +56,7 @@ func NewMachineHealthCheckReconciler(log *logrus.Entry, client client.Client, dh

// Reconcile watches MachineHealthCheck objects, and if any changes,
// reconciles the associated ARO MachineHealthCheck object
func (r *MachineHealthCheckReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) {
func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) {
instance, err := r.GetCluster(ctx)

if err != nil {
Expand All @@ -70,7 +70,7 @@ func (r *MachineHealthCheckReconciler) Reconcile(ctx context.Context, request ct

r.Log.Debug("running")
if !instance.Spec.OperatorFlags.GetSimpleBoolean(managed) {
r.SetProgressing(ctx, "MHC and it's alerts are disabled because this cluster is not MHC managed.")
r.SetProgressing(ctx, "Not MHC Managed for cluster maintenance purpose.")

err := r.dh.EnsureDeleted(ctx, "MachineHealthCheck", "openshift-machine-api", "aro-machinehealthcheck")
if err != nil {
Expand Down Expand Up @@ -134,7 +134,7 @@ func (r *MachineHealthCheckReconciler) Reconcile(ctx context.Context, request ct
}

// SetupWithManager will manage only our MHC resource with our specific controller name
func (r *MachineHealthCheckReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return strings.EqualFold(arov1alpha1.SingletonClusterName, o.GetName())
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func TestMachineHealthCheckReconciler(t *testing.T) {

ctx := context.Background()

r := NewMachineHealthCheckReconciler(
r := NewReconciler(
logrus.NewEntry(logrus.StandardLogger()),
clientBuilder.Build(),
mdh,
Expand Down

0 comments on commit bf8b8d9

Please sign in to comment.