Skip to content

Commit

Permalink
Tidy: changed empty slice declaration, modified var name that collide…
Browse files Browse the repository at this point in the history
…s with pkg name, fixed typo and removed unused func variable

Signed-off-by: Michael Shitrit <[email protected]>
  • Loading branch information
mshitrit committed May 6, 2021
1 parent 56f4f9a commit 21b3046
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 15 additions & 15 deletions controllers/machinehealthcheck_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type MachineHealthCheckReconciler struct {
}

func (r *MachineHealthCheckReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
controller, err := ctrl.NewControllerManagedBy(mgr).
managedController, err := ctrl.NewControllerManagedBy(mgr).
For(&clusterv1.MachineHealthCheck{}).
Watches(
&source.Kind{Type: &clusterv1.Machine{}},
Expand All @@ -85,20 +85,20 @@ func (r *MachineHealthCheckReconciler) SetupWithManager(ctx context.Context, mgr
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
Build(r)
if err != nil {
return errors.Wrap(err, "failed setting up with a controller manager")
return errors.Wrap(err, "failed setting up with a managedController manager")
}
err = controller.Watch(
err = managedController.Watch(
&source.Kind{Type: &clusterv1.Cluster{}},
handler.EnqueueRequestsFromMapFunc(r.clusterToMachineHealthCheck),
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
)
if err != nil {
return errors.Wrap(err, "failed to add Watch for Clusters to controller manager")
return errors.Wrap(err, "failed to add Watch for Clusters to managedController manager")
}

r.controller = controller
r.recorder = mgr.GetEventRecorderFor("machinehealthcheck-controller")
r.controller = managedController
r.recorder = mgr.GetEventRecorderFor("machinehealthcheck-managedController")
return nil
}

Expand Down Expand Up @@ -145,7 +145,7 @@ func (r *MachineHealthCheckReconciler) Reconcile(ctx context.Context, req ctrl.R
defer func() {
// Always attempt to patch the object and status after each reconciliation.
// Patch ObservedGeneration only if the reconciliation completed successfully
patchOpts := []patch.Option{}
var patchOpts []patch.Option
if reterr == nil {
patchOpts = append(patchOpts, patch.WithStatusObservedGeneration{})
}
Expand Down Expand Up @@ -263,7 +263,7 @@ func (r *MachineHealthCheckReconciler) reconcile(ctx context.Context, logger log
EventRemediationRestricted,
message,
)
errList := []error{}
var errList []error
for _, t := range append(healthy, unhealthy...) {
if err := t.patchHelper.Patch(ctx, t.Machine); err != nil {
errList = append(errList, errors.Wrapf(err, "failed to patch machine status for machine: %s/%s", t.Machine.Namespace, t.Machine.Name))
Expand All @@ -288,7 +288,7 @@ func (r *MachineHealthCheckReconciler) reconcile(ctx context.Context, logger log
conditions.MarkTrue(m, clusterv1.RemediationAllowedCondition)

errList := r.PatchUnhealthyTargets(ctx, logger, unhealthy, cluster, m)
errList = append(errList, r.PatchHealthyTargets(ctx, logger, healthy, cluster, m)...)
errList = append(errList, r.PatchHealthyTargets(ctx, logger, healthy, m)...)

// handle update errors
if len(errList) > 0 {
Expand All @@ -306,9 +306,9 @@ func (r *MachineHealthCheckReconciler) reconcile(ctx context.Context, logger log
return ctrl.Result{}, nil
}

// PatchHealthyTargets patches healthy machines with MachineHealthCheckSuccededCondition.
func (r *MachineHealthCheckReconciler) PatchHealthyTargets(ctx context.Context, logger logr.Logger, healthy []healthCheckTarget, cluster *clusterv1.Cluster, m *clusterv1.MachineHealthCheck) []error {
errList := []error{}
// PatchHealthyTargets patches healthy machines with MachineHealthCheckSucceededCondition.
func (r *MachineHealthCheckReconciler) PatchHealthyTargets(ctx context.Context, logger logr.Logger, healthy []healthCheckTarget, m *clusterv1.MachineHealthCheck) []error {
var errList []error
for _, t := range healthy {
if m.Spec.RemediationTemplate != nil {
// Get remediation request object
Expand Down Expand Up @@ -340,7 +340,7 @@ func (r *MachineHealthCheckReconciler) PatchHealthyTargets(ctx context.Context,
// PatchUnhealthyTargets patches machines with MachineOwnerRemediatedCondition for remediation.
func (r *MachineHealthCheckReconciler) PatchUnhealthyTargets(ctx context.Context, logger logr.Logger, unhealthy []healthCheckTarget, cluster *clusterv1.Cluster, m *clusterv1.MachineHealthCheck) []error {
// mark for remediation
errList := []error{}
var errList []error
for _, t := range unhealthy {
condition := conditions.Get(t.Machine, clusterv1.MachineHealthCheckSuccededCondition)

Expand Down Expand Up @@ -440,7 +440,7 @@ func (r *MachineHealthCheckReconciler) clusterToMachineHealthCheck(o client.Obje
}

// This list should only contain MachineHealthChecks which belong to the given Cluster
requests := []reconcile.Request{}
var requests []reconcile.Request
for _, mhc := range mhcList.Items {
key := types.NamespacedName{Namespace: mhc.Namespace, Name: mhc.Name}
requests = append(requests, reconcile.Request{NamespacedName: key})
Expand Down Expand Up @@ -502,7 +502,7 @@ func (r *MachineHealthCheckReconciler) getMachineFromNode(ctx context.Context, n
}
// TODO(vincepri): Remove this loop once controller runtime fake client supports
// adding indexes on objects.
items := []*clusterv1.Machine{}
var items []*clusterv1.Machine
for i := range machineList.Items {
machine := &machineList.Items[i]
if machine.Status.NodeRef != nil && machine.Status.NodeRef.Name == nodeName {
Expand Down
2 changes: 1 addition & 1 deletion controllers/machinehealthcheck_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2622,5 +2622,5 @@ func TestPatchTargets(t *testing.T) {
g.Expect(conditions.Get(machine2, clusterv1.MachineOwnerRemediatedCondition).Status).To(Equal(corev1.ConditionFalse))

// Target with wrong patch helper will fail but the other one will be patched.
g.Expect(len(r.PatchHealthyTargets(context.TODO(), log.NullLogger{}, []healthCheckTarget{target1, target3}, defaultCluster, mhc))).To(BeNumerically(">", 0))
g.Expect(len(r.PatchHealthyTargets(context.TODO(), log.NullLogger{}, []healthCheckTarget{target1, target3}, mhc))).To(BeNumerically(">", 0))
}

0 comments on commit 21b3046

Please sign in to comment.