Skip to content

Commit

Permalink
Dont list and terminate ASG-managed EC2 instances
Browse files Browse the repository at this point in the history
  • Loading branch information
rifelpet committed Jan 5, 2024
1 parent 1202209 commit 336f5af
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion pkg/resources/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func ListResourcesAWS(cloud awsup.AWSCloud, clusterInfo resources.ClusterInfo) (
listFunctions := []listFn{
// EC2
ListAutoScalingGroups,
ListInstances,
ListKeypairs,
ListSecurityGroups,
ListVolumes,
Expand All @@ -88,6 +87,12 @@ func ListResourcesAWS(cloud awsup.AWSCloud, clusterInfo resources.ClusterInfo) (
ListEventBridgeRules,
}

if clusterInfo.UsesKarpenter {
// ASG deletion cascades to their instances
// Only karpenter-enabled clusters have instances not in ASGs
listFunctions = append(listFunctions, ListInstances)
}

if !dns.IsGossipClusterName(clusterName) && !clusterUsesNoneDNS {
// Route 53
listFunctions = append(listFunctions, ListRoute53Records)
Expand Down
5 changes: 3 additions & 2 deletions pkg/resources/clusterinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the License.
package resources

type ClusterInfo struct {
Name string
UsesNoneDNS bool
Name string
UsesNoneDNS bool
UsesKarpenter bool
// Azure specific
AzureResourceGroupName string
AzureResourceGroupShared bool
Expand Down
5 changes: 3 additions & 2 deletions pkg/resources/ops/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ import (
// ListResources collects the resources from the specified cloud
func ListResources(cloud fi.Cloud, cluster *kops.Cluster) (map[string]*resources.Resource, error) {
clusterInfo := resources.ClusterInfo{
Name: cluster.Name,
UsesNoneDNS: cluster.UsesNoneDNS(),
Name: cluster.Name,
UsesNoneDNS: cluster.UsesNoneDNS(),
UsesKarpenter: cluster.Spec.Karpenter != nil && cluster.Spec.Karpenter.Enabled,
}

switch cloud.ProviderID() {
Expand Down

0 comments on commit 336f5af

Please sign in to comment.