Skip to content

Commit

Permalink
chore: Improve error message for deleting EC2NodeClass (#5656)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis authored and jigisha620 committed Feb 16, 2024
1 parent e4bde9a commit ac520cd
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pkg/cloudprovider/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ func (c *CloudProvider) resolveNodeClassFromNodeClaim(ctx context.Context, nodeC
}
// For the purposes of NodeClass CloudProvider resolution, we treat deleting NodeClasses as NotFound
if !nodeClass.DeletionTimestamp.IsZero() {
return nil, errors.NewNotFound(v1beta1.SchemeGroupVersion.WithResource("ec2nodeclasses").GroupResource(), nodeClass.Name)
// For the purposes of NodeClass CloudProvider resolution, we treat deleting NodeClasses as NotFound,
// but we return a different error message to be clearer to users
return nil, newTerminatingNodeClassError(nodeClass.Name)
}
return nodeClass, nil
}
Expand All @@ -225,9 +227,10 @@ func (c *CloudProvider) resolveNodeClassFromNodePool(ctx context.Context, nodePo
if err := c.kubeClient.Get(ctx, types.NamespacedName{Name: nodePool.Spec.Template.Spec.NodeClassRef.Name}, nodeClass); err != nil {
return nil, err
}
// For the purposes of NodeClass CloudProvider resolution, we treat deleting NodeClasses as NotFound
if !nodeClass.DeletionTimestamp.IsZero() {
return nil, errors.NewNotFound(v1beta1.SchemeGroupVersion.WithResource("ec2nodeclasses").GroupResource(), nodeClass.Name)
// For the purposes of NodeClass CloudProvider resolution, we treat deleting NodeClasses as NotFound,
// but we return a different error message to be clearer to users
return nil, newTerminatingNodeClassError(nodeClass.Name)
}
return nodeClass, nil
}
Expand Down Expand Up @@ -270,7 +273,7 @@ func (c *CloudProvider) resolveNodePoolFromInstance(ctx context.Context, instanc
}
return nodePool, nil
}
return nil, errors.NewNotFound(schema.GroupResource{Group: corev1beta1.Group, Resource: "NodePool"}, "")
return nil, errors.NewNotFound(schema.GroupResource{Group: corev1beta1.Group, Resource: "nodepools"}, "")
}

func (c *CloudProvider) instanceToNodeClaim(i *instance.Instance, instanceType *cloudprovider.InstanceType) *corev1beta1.NodeClaim {
Expand Down Expand Up @@ -317,3 +320,11 @@ func (c *CloudProvider) instanceToNodeClaim(i *instance.Instance, instanceType *
nodeClaim.Status.ImageID = i.ImageID
return nodeClaim
}

// newTerminatingNodeClassError returns a NotFound error for handling by
func newTerminatingNodeClassError(name string) *errors.StatusError {
qualifiedResource := schema.GroupResource{Group: corev1beta1.Group, Resource: "ec2nodeclasses"}
err := errors.NewNotFound(qualifiedResource, name)
err.ErrStatus.Message = fmt.Sprintf("%s %q is terminating, treating as not found", qualifiedResource.String(), name)
return err
}

0 comments on commit ac520cd

Please sign in to comment.