diff --git a/cmd/aro/operator.go b/cmd/aro/operator.go index ba3de7fcb1e..507c761669b 100644 --- a/cmd/aro/operator.go +++ b/cmd/aro/operator.go @@ -192,9 +192,9 @@ func operator(ctx context.Context, log *logrus.Entry) error { return fmt.Errorf("unable to create controller %s: %v", autosizednodes.ControllerName, err) } if err = (machinehealthcheck.NewMachineHealthCheckReconciler( - log.WithField("controller", machinehealthcheck.MHCControllerName), + log.WithField("controller", machinehealthcheck.ControllerName), client, dh)).SetupWithManager(mgr); err != nil { - return fmt.Errorf("unable to create controller %s: %v", machinehealthcheck.MHCControllerName, err) + return fmt.Errorf("unable to create controller %s: %v", machinehealthcheck.ControllerName, err) } if err = (ingress.NewReconciler( log.WithField("controller", ingress.ControllerName), diff --git a/pkg/operator/controllers/machinehealthcheck/machinehealthcheck_controller.go b/pkg/operator/controllers/machinehealthcheck/machinehealthcheck_controller.go index 68e3e5974a0..d518d981efb 100644 --- a/pkg/operator/controllers/machinehealthcheck/machinehealthcheck_controller.go +++ b/pkg/operator/controllers/machinehealthcheck/machinehealthcheck_controller.go @@ -32,9 +32,9 @@ var machinehealthcheckYaml []byte var mhcremediationalertYaml []byte const ( - MHCControllerName string = "MachineHealthCheck" - MHCManaged string = "aro.machinehealthcheck.managed" - MHCEnabled string = "aro.machinehealthcheck.enabled" + ControllerName string = "MachineHealthCheck" + managed string = "aro.machinehealthcheck.managed" + enabled string = "aro.machinehealthcheck.enabled" ) type MachineHealthCheckReconciler struct { @@ -48,7 +48,7 @@ func NewMachineHealthCheckReconciler(log *logrus.Entry, client client.Client, dh AROController: base.AROController{ Log: log, Client: client, - Name: MHCControllerName, + Name: ControllerName, }, dh: dh, } @@ -63,13 +63,13 @@ func (r *MachineHealthCheckReconciler) Reconcile(ctx context.Context, request ct return reconcile.Result{}, err } - if !instance.Spec.OperatorFlags.GetSimpleBoolean(MHCEnabled) { + if !instance.Spec.OperatorFlags.GetSimpleBoolean(enabled) { r.Log.Debug("controller is disabled") return reconcile.Result{}, nil } r.Log.Debug("running") - if !instance.Spec.OperatorFlags.GetSimpleBoolean(MHCManaged) { + if !instance.Spec.OperatorFlags.GetSimpleBoolean(managed) { r.SetProgressing(ctx, "MHC and it's alerts are disabled because this cluster is not MHC managed.") err := r.dh.EnsureDeleted(ctx, "MachineHealthCheck", "openshift-machine-api", "aro-machinehealthcheck") @@ -141,7 +141,7 @@ func (r *MachineHealthCheckReconciler) SetupWithManager(mgr ctrl.Manager) error return ctrl.NewControllerManagedBy(mgr). For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)). - Named(MHCControllerName). + Named(ControllerName). Owns(&machinev1beta1.MachineHealthCheck{}). Owns(&monitoringv1.PrometheusRule{}). Complete(r) diff --git a/pkg/operator/controllers/machinehealthcheck/machinehealthcheck_controller_test.go b/pkg/operator/controllers/machinehealthcheck/machinehealthcheck_controller_test.go index c88e05a28b6..2db7d61bbb6 100644 --- a/pkg/operator/controllers/machinehealthcheck/machinehealthcheck_controller_test.go +++ b/pkg/operator/controllers/machinehealthcheck/machinehealthcheck_controller_test.go @@ -11,6 +11,7 @@ import ( "time" "github.com/golang/mock/gomock" + operatorv1 "github.com/openshift/api/operator/v1" "github.com/sirupsen/logrus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ctrl "sigs.k8s.io/controller-runtime" @@ -21,15 +22,14 @@ import ( _ "github.com/Azure/ARO-RP/pkg/util/scheme" utilconditions "github.com/Azure/ARO-RP/test/util/conditions" utilerror "github.com/Azure/ARO-RP/test/util/error" - operatorv1 "github.com/openshift/api/operator/v1" ) // Test reconcile function func TestMachineHealthCheckReconciler(t *testing.T) { transitionTime := metav1.Time{Time: time.Now()} - defaultAvailable := utilconditions.ControllerDefaultAvailable(MHCControllerName) - defaultProgressing := utilconditions.ControllerDefaultProgressing(MHCControllerName) - defaultDegraded := utilconditions.ControllerDefaultDegraded(MHCControllerName) + defaultAvailable := utilconditions.ControllerDefaultAvailable(ControllerName) + defaultProgressing := utilconditions.ControllerDefaultProgressing(ControllerName) + defaultDegraded := utilconditions.ControllerDefaultDegraded(ControllerName) defaultConditions := []operatorv1.OperatorCondition{defaultAvailable, defaultProgressing, defaultDegraded} @@ -57,7 +57,7 @@ func TestMachineHealthCheckReconciler(t *testing.T) { }, Spec: arov1alpha1.ClusterSpec{ OperatorFlags: arov1alpha1.OperatorFlags{ - MHCEnabled: strconv.FormatBool(false), + enabled: strconv.FormatBool(false), }, }, Status: arov1alpha1.ClusterStatus{ @@ -79,8 +79,8 @@ func TestMachineHealthCheckReconciler(t *testing.T) { }, Spec: arov1alpha1.ClusterSpec{ OperatorFlags: arov1alpha1.OperatorFlags{ - MHCEnabled: strconv.FormatBool(true), - MHCManaged: strconv.FormatBool(false), + enabled: strconv.FormatBool(true), + managed: strconv.FormatBool(false), }, }, Status: arov1alpha1.ClusterStatus{ @@ -102,8 +102,8 @@ func TestMachineHealthCheckReconciler(t *testing.T) { }, Spec: arov1alpha1.ClusterSpec{ OperatorFlags: arov1alpha1.OperatorFlags{ - MHCEnabled: strconv.FormatBool(true), - MHCManaged: strconv.FormatBool(false), + enabled: strconv.FormatBool(true), + managed: strconv.FormatBool(false), }, }, Status: arov1alpha1.ClusterStatus{ @@ -118,7 +118,7 @@ func TestMachineHealthCheckReconciler(t *testing.T) { defaultAvailable, defaultProgressing, { - Type: MHCControllerName + "Controller" + operatorv1.OperatorStatusTypeDegraded, + Type: ControllerName + "Controller" + operatorv1.OperatorStatusTypeDegraded, Status: operatorv1.ConditionTrue, LastTransitionTime: transitionTime, Message: "Could not delete mhc", @@ -134,8 +134,8 @@ func TestMachineHealthCheckReconciler(t *testing.T) { }, Spec: arov1alpha1.ClusterSpec{ OperatorFlags: arov1alpha1.OperatorFlags{ - MHCEnabled: strconv.FormatBool(true), - MHCManaged: strconv.FormatBool(false), + enabled: strconv.FormatBool(true), + managed: strconv.FormatBool(false), }, }, Status: arov1alpha1.ClusterStatus{ @@ -151,7 +151,7 @@ func TestMachineHealthCheckReconciler(t *testing.T) { defaultAvailable, defaultProgressing, { - Type: MHCControllerName + "Controller" + operatorv1.OperatorStatusTypeDegraded, + Type: ControllerName + "Controller" + operatorv1.OperatorStatusTypeDegraded, Status: operatorv1.ConditionTrue, LastTransitionTime: transitionTime, Message: "Could not delete mhc alert", @@ -167,8 +167,8 @@ func TestMachineHealthCheckReconciler(t *testing.T) { }, Spec: arov1alpha1.ClusterSpec{ OperatorFlags: arov1alpha1.OperatorFlags{ - MHCEnabled: strconv.FormatBool(true), - MHCManaged: strconv.FormatBool(true), + enabled: strconv.FormatBool(true), + managed: strconv.FormatBool(true), }, }, }, @@ -186,8 +186,8 @@ func TestMachineHealthCheckReconciler(t *testing.T) { }, Spec: arov1alpha1.ClusterSpec{ OperatorFlags: arov1alpha1.OperatorFlags{ - MHCEnabled: strconv.FormatBool(true), - MHCManaged: strconv.FormatBool(true), + enabled: strconv.FormatBool(true), + managed: strconv.FormatBool(true), }, }, Status: arov1alpha1.ClusterStatus{ @@ -202,7 +202,7 @@ func TestMachineHealthCheckReconciler(t *testing.T) { defaultAvailable, defaultProgressing, { - Type: MHCControllerName + "Controller" + operatorv1.OperatorStatusTypeDegraded, + Type: ControllerName + "Controller" + operatorv1.OperatorStatusTypeDegraded, Status: operatorv1.ConditionTrue, LastTransitionTime: transitionTime, Message: "failed to ensure",