Skip to content

Commit

Permalink
Tidy: changed empty slice declaration, fixed typo, unexported methods…
Browse files Browse the repository at this point in the history
… and removed unused func variable

Signed-off-by: Michael Shitrit <[email protected]>
  • Loading branch information
mshitrit committed May 9, 2021
1 parent 56f4f9a commit 906058b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions controllers/machinehealthcheck_controller.go
Original file line number Diff line number Diff line change
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 @@ -287,8 +287,8 @@ func (r *MachineHealthCheckReconciler) reconcile(ctx context.Context, logger log
m.Status.RemediationsAllowed = remediationCount
conditions.MarkTrue(m, clusterv1.RemediationAllowedCondition)

errList := r.PatchUnhealthyTargets(ctx, logger, unhealthy, cluster, m)
errList = append(errList, r.PatchHealthyTargets(ctx, logger, healthy, cluster, m)...)
errList := r.patchUnhealthyTargets(ctx, logger, unhealthy, 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 @@ -337,10 +337,10 @@ func (r *MachineHealthCheckReconciler) PatchHealthyTargets(ctx context.Context,
return errList
}

// 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 {
// 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
4 changes: 2 additions & 2 deletions controllers/machinehealthcheck_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2617,10 +2617,10 @@ func TestPatchTargets(t *testing.T) {
}

// Target with wrong patch helper will fail but the other one will be patched.
g.Expect(len(r.PatchUnhealthyTargets(context.TODO(), log.NullLogger{}, []healthCheckTarget{target1, target3}, defaultCluster, mhc))).To(BeNumerically(">", 0))
g.Expect(len(r.patchUnhealthyTargets(context.TODO(), log.NullLogger{}, []healthCheckTarget{target1, target3}, defaultCluster, mhc))).To(BeNumerically(">", 0))
g.Expect(cl.Get(ctx, client.ObjectKey{Name: machine2.Name, Namespace: machine2.Namespace}, machine2)).NotTo(HaveOccurred())
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 906058b

Please sign in to comment.