Skip to content

Commit

Permalink
Addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bryan-cox committed Nov 7, 2022
1 parent a1bbfc9 commit 75e7e00
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions hypershift-operator/controllers/nodepool/nodepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,6 @@ func deleteMachineHealthCheck(ctx context.Context, c client.Client, mhc *capiv1.
}

func (r *NodePoolReconciler) delete(ctx context.Context, nodePool *hyperv1.NodePool, controlPlaneNamespace string) error {
allMachinesTerminiated := false
md := machineDeployment(nodePool, controlPlaneNamespace)
ms := machineSet(nodePool, controlPlaneNamespace)
mhc := machineHealthCheck(nodePool, controlPlaneNamespace)
Expand Down Expand Up @@ -904,14 +903,10 @@ func (r *NodePoolReconciler) delete(ctx context.Context, nodePool *hyperv1.NodeP
return fmt.Errorf("failed to delete ConfigMaps with nodePool label: %w", err)
}

if nodePool.Spec.Platform.AWS != nil {
for !allMachinesTerminiated {
time.Sleep(5 * time.Second)
allMachinesTerminiated, err = r.allMachinesTerminated(nodePool)
if err != nil {
return err
}
}
// Ensure all machines in NodePool are deleted
err = r.ensureMachineDeletion(nodePool)
if err != nil {
return err
}

// Delete all secrets related to the NodePool
Expand Down Expand Up @@ -2038,7 +2033,7 @@ func (r *NodePoolReconciler) doesCPODecompressAndDecodeConfig(ctx context.Contex
return managesDecompressAndDecodeConfig, nil
}

func (r *NodePoolReconciler) allMachinesTerminated(nodePool *hyperv1.NodePool) (bool, error) {
func (r *NodePoolReconciler) ensureMachineDeletion(nodePool *hyperv1.NodePool) error {
machineSetList := &unstructured.UnstructuredList{}
var gvk schema.GroupVersionKind
var err error
Expand All @@ -2048,12 +2043,12 @@ func (r *NodePoolReconciler) allMachinesTerminated(nodePool *hyperv1.NodePool) (
case hyperv1.AWSPlatform:
gvk, err = apiutil.GVKForObject(&capiaws.AWSMachineList{}, api.Scheme)
if err != nil {
return false, err
return err
}
default:
// need a default path that returns a value that does not cause the hypershift operator to crash
// if no explicit machineSet is defined safe to assume none exist
return true, nil
return nil
}

machineSetList.SetGroupVersionKind(schema.GroupVersionKind{
Expand All @@ -2063,7 +2058,7 @@ func (r *NodePoolReconciler) allMachinesTerminated(nodePool *hyperv1.NodePool) (
})

if err := r.List(context.Background(), machineSetList); err != nil {
return false, fmt.Errorf("failed to list MachineSet: %w", err)
return fmt.Errorf("failed to list MachineSet: %w", err)
}

var filteredMachines []client.Object
Expand All @@ -2077,8 +2072,8 @@ func (r *NodePoolReconciler) allMachinesTerminated(nodePool *hyperv1.NodePool) (
}

if len(filteredMachines) > 0 {
return false, nil
return fmt.Errorf("all machines still not fully terminated")
}

return true, nil
return nil
}

0 comments on commit 75e7e00

Please sign in to comment.