Skip to content

Commit

Permalink
pass the cluster in to the get targets
Browse files Browse the repository at this point in the history
  • Loading branch information
nader-ziada committed Mar 24, 2021
1 parent a07ba35 commit d934d49
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion controllers/machinehealthcheck_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (r *MachineHealthCheckReconciler) reconcile(ctx context.Context, logger log

// fetch all targets
logger.V(3).Info("Finding targets")
targets, err := r.getTargetsFromMHC(ctx, logger, remoteClient, m)
targets, err := r.getTargetsFromMHC(ctx, logger, remoteClient, cluster, m)
if err != nil {
logger.Error(err, "Failed to fetch targets from MachineHealthCheck")
return ctrl.Result{}, err
Expand Down
9 changes: 2 additions & 7 deletions controllers/machinehealthcheck_targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (t *healthCheckTarget) needsRemediation(logger logr.Logger, timeoutForMachi

// getTargetsFromMHC uses the MachineHealthCheck's selector to fetch machines
// and their nodes targeted by the health check, ready for health checking.
func (r *MachineHealthCheckReconciler) getTargetsFromMHC(ctx context.Context, logger logr.Logger, clusterClient client.Reader, mhc *clusterv1.MachineHealthCheck) ([]healthCheckTarget, error) {
func (r *MachineHealthCheckReconciler) getTargetsFromMHC(ctx context.Context, logger logr.Logger, clusterClient client.Reader, cluster *clusterv1.Cluster, mhc *clusterv1.MachineHealthCheck) ([]healthCheckTarget, error) {
machines, err := r.getMachinesFromMHC(ctx, mhc)
if err != nil {
return nil, errors.Wrap(err, "error getting machines from MachineHealthCheck")
Expand All @@ -185,11 +185,6 @@ func (r *MachineHealthCheckReconciler) getTargetsFromMHC(ctx context.Context, lo
return nil, nil
}

var cluster clusterv1.Cluster
if err := clusterClient.Get(ctx, client.ObjectKey{Namespace: mhc.Namespace, Name: mhc.Spec.ClusterName}, &cluster); err != nil {
return nil, errors.Wrapf(err, "error getting Cluster %s/%s for MachineHealthCheck %s", mhc.Namespace, mhc.Spec.ClusterName, mhc.Name)
}

targets := []healthCheckTarget{}
for k := range machines {
skip, reason := shouldSkipRemediation(&machines[k])
Expand All @@ -203,7 +198,7 @@ func (r *MachineHealthCheckReconciler) getTargetsFromMHC(ctx context.Context, lo
return nil, errors.Wrap(err, "unable to initialize patch helper")
}
target := healthCheckTarget{
Cluster: &cluster,
Cluster: cluster,
MHC: mhc,
Machine: &machines[k],
patchHelper: patchHelper,
Expand Down
2 changes: 1 addition & 1 deletion controllers/machinehealthcheck_targets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestGetTargetsFromMHC(t *testing.T) {
t.patchHelper = patchHelper
}

targets, err := reconciler.getTargetsFromMHC(ctx, ctrl.LoggerFrom(ctx), k8sClient, testMHC)
targets, err := reconciler.getTargetsFromMHC(ctx, ctrl.LoggerFrom(ctx), k8sClient, cluster, testMHC)
gs.Expect(err).ToNot(HaveOccurred())

gs.Expect(len(targets)).To(Equal(len(tc.expectedTargets)))
Expand Down

0 comments on commit d934d49

Please sign in to comment.