Skip to content

Commit

Permalink
Merge pull request #582 from giantswarm/aws-cni-deleted-helm-managed-…
Browse files Browse the repository at this point in the history
…resources

🐛 EKS - when aws-cni is disabled deleted all resources including helm managed resources
  • Loading branch information
calvix authored Jan 18, 2024
2 parents e25dc0f + 220042d commit ba007f8
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions pkg/cloud/services/awsnode/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/kustomize/api/konfig"

infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/awserrors"
Expand Down Expand Up @@ -273,20 +272,16 @@ func (s *Service) deleteResource(ctx context.Context, remoteClient client.Client
}
s.scope.Debug(fmt.Sprintf("resource %s was not found, no action", key))
} else {
// resource found, delete if no label or not managed by helm
if val, ok := obj.GetLabels()[konfig.ManagedbyLabelKey]; !ok || val != "Helm" {
if err := remoteClient.Delete(ctx, obj, &client.DeleteOptions{}); err != nil {
if !apierrors.IsNotFound(err) {
return fmt.Errorf("deleting %s: %w", key, err)
}
s.scope.Debug(fmt.Sprintf(
"resource %s was not found, not deleted", key))
} else {
s.scope.Debug(fmt.Sprintf("resource %s was deleted", key))
if err := remoteClient.Delete(ctx, obj, &client.DeleteOptions{}); err != nil {
if !apierrors.IsNotFound(err) {
return fmt.Errorf("deleting %s: %w", key, err)
}
s.scope.Debug(fmt.Sprintf(
"resource %s was not found, not deleted", key))
} else {
s.scope.Debug(fmt.Sprintf("resource %s is managed by helm, not deleted", key))
s.scope.Debug(fmt.Sprintf("resource %s was deleted", key))
}

}

return nil
Expand Down

0 comments on commit ba007f8

Please sign in to comment.