Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#10939 from sbueringer/pr-improve-m…
Browse files Browse the repository at this point in the history
…p-unit-tests

🌱 Improve MP unit test coverage
  • Loading branch information
k8s-ci-robot authored Jul 25, 2024
2 parents c5b4e93 + 7f8410a commit d36541f
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 86 deletions.
19 changes: 3 additions & 16 deletions exp/internal/controllers/machinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,6 @@ func (r *MachinePoolReconciler) reconcileDeleteNodes(ctx context.Context, cluste
return nil
}

if r.Tracker == nil {
return errors.New("Cannot establish cluster client to delete nodes")
}

clusterClient, err := r.Tracker.GetClient(ctx, util.ObjectKey(cluster))
if err != nil {
return err
Expand All @@ -328,13 +324,9 @@ func (r *MachinePoolReconciler) isMachinePoolNodeDeleteTimeoutPassed(machinePool
// reconcileDeleteExternal tries to delete external references, returning true if it cannot find any.
func (r *MachinePoolReconciler) reconcileDeleteExternal(ctx context.Context, machinePool *expv1.MachinePool) (bool, error) {
objects := []*unstructured.Unstructured{}
references := []*corev1.ObjectReference{}
// check for external ref
if machinePool.Spec.Template.Spec.Bootstrap.ConfigRef != nil {
references = append(references, machinePool.Spec.Template.Spec.Bootstrap.ConfigRef)
}
if machinePool.Spec.Template.Spec.InfrastructureRef != (corev1.ObjectReference{}) {
references = append(references, &machinePool.Spec.Template.Spec.InfrastructureRef)
references := []*corev1.ObjectReference{
machinePool.Spec.Template.Spec.Bootstrap.ConfigRef,
&machinePool.Spec.Template.Spec.InfrastructureRef,
}

// Loop over the references and try to retrieve it with the client.
Expand Down Expand Up @@ -374,11 +366,6 @@ func (r *MachinePoolReconciler) watchClusterNodes(ctx context.Context, cluster *
return nil
}

// If there is no tracker, don't watch remote nodes
if r.Tracker == nil {
return nil
}

return r.Tracker.Watch(ctx, remote.WatchInput{
Name: "machinepool-watchNodes",
Cluster: util.ObjectKey(cluster),
Expand Down
3 changes: 2 additions & 1 deletion exp/internal/controllers/machinepool_controller_noderef.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -153,7 +154,7 @@ func (r *MachinePoolReconciler) deleteRetiredNodes(ctx context.Context, c client
delete(nodeRefsMap, providerID)
}
for _, node := range nodeRefsMap {
if err := c.Delete(ctx, node); err != nil {
if err := c.Delete(ctx, node); err != nil && !apierrors.IsNotFound(err) {
return errors.Wrapf(err, "failed to delete Node")
}
}
Expand Down
Loading

0 comments on commit d36541f

Please sign in to comment.