You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refact/lb/sg: isolate sg deletion fragments to be reused
Isolating security group deletion fragments from EnsureLoadBalancerDeleted
to buildSecurityGroupsToDelete and deleteSecurityGroupsWithBackoff, so
the envaluation criteria and backof deletion can be reused in future
implementations, i.e. NLB with Security Groups.
klog.V(2).Infof("Ignoring DependencyViolation while deleting load-balancer security group (%s), assuming because LB is in process of deleting", securityGroupID)
2912
+
ignore=true
2913
+
}
2914
+
}
2915
+
if!ignore {
2916
+
returntrue, fmt.Errorf("error while deleting load balancer security group (%s): %q", securityGroupID, err)
2917
+
}
2918
+
}
2919
+
2920
+
iflen(securityGroupIDs) ==0 {
2921
+
klog.V(2).Info("Deleted all security groups for load balancer: ", svcName)
2922
+
returntrue, nil
2923
+
}
2924
+
2925
+
klog.V(2).Infof("Waiting for load-balancer %q to delete so we can delete security groups: %v", svcName, securityGroupIDs)
2926
+
returnfalse, nil
2927
+
})
2928
+
iferr!=nil {
2929
+
ids:= []string{}
2930
+
forid:=rangesecurityGroupIDs {
2931
+
ids=append(ids, id)
2932
+
}
2933
+
returnfmt.Errorf("timed out deleting ELB: %s. Could not delete security groups %v", svcName, strings.Join(ids, ","))
2934
+
}
2935
+
returnnil
2936
+
}
2937
+
2938
+
// buildSecurityGroupsToDelete evaluates all deletion criteria and creates a list of valid security group IDs to be deleted.
2939
+
// It returns two maps:
2940
+
// - `securityGroupIDs`: A map of security group IDs that are eligible for deletion.
2941
+
// - `taggedLBSecurityGroups`: A map of security group IDs that are tagged and associated with the load balancer.
2942
+
// The function filters security groups based on the following criteria:
2943
+
// - Excludes security groups defined in the Cloud Configuration.
2944
+
// - Excludes security groups with no cluster tags.
2945
+
// - Excludes security groups annotated with `service.beta.kubernetes.io/aws-load-balancer-security-groups` or
//We don't want to delete a security group that was defined in the Cloud Configuration.
2983
+
continue
2984
+
}
2985
+
ifsgID=="" {
2986
+
klog.Warningf("Ignoring empty security group in %s", service.Name)
2987
+
continue
2988
+
}
2989
+
2990
+
if!c.tagging.hasClusterTag(sg.Tags) {
2991
+
klog.Warningf("Ignoring security group with no cluster tag in %s", service.Name)
2992
+
continue
2993
+
} else {
2994
+
taggedLBSecurityGroups[sgID] =struct{}{}
2995
+
}
2996
+
2997
+
// This is an extra protection of deletion of non provisioned Security Group which is annotated with `service.beta.kubernetes.io/aws-load-balancer-security-groups`.
2998
+
if_, ok:=annotatedSgSet[sgID]; ok {
2999
+
klog.Warningf("Ignoring security group with annotation `service.beta.kubernetes.io/aws-load-balancer-security-groups` or service.beta.kubernetes.io/aws-load-balancer-extra-security-groups in %s", service.Name)
//We don't want to delete a security group that was defined in the Cloud Configuration.
2975
-
continue
2976
-
}
2977
-
ifsgID=="" {
2978
-
klog.Warningf("Ignoring empty security group in %s", service.Name)
2979
-
continue
2980
-
}
2981
-
2982
-
if!c.tagging.hasClusterTag(sg.Tags) {
2983
-
klog.Warningf("Ignoring security group with no cluster tag in %s", service.Name)
2984
-
continue
2985
-
} else {
2986
-
taggedLBSecurityGroups[sgID] =struct{}{}
2987
-
}
2988
3080
2989
-
// This is an extra protection of deletion of non provisioned Security Group which is annotated with `service.beta.kubernetes.io/aws-load-balancer-security-groups`.
2990
-
if_, ok:=annotatedSgSet[sgID]; ok {
2991
-
klog.Warningf("Ignoring security group with annotation `service.beta.kubernetes.io/aws-load-balancer-security-groups` or service.beta.kubernetes.io/aws-load-balancer-extra-security-groups in %s", service.Name)
2992
-
continue
2993
-
}
2994
-
2995
-
securityGroupIDs[sgID] =struct{}{}
2996
-
}
3081
+
// Delete the security group(s) for the load balancer
3082
+
// Note that this is annoying: the load balancer disappears from the API immediately, but it is still
3083
+
// deleting in the background. We get a DependencyViolation until the load balancer has deleted itself
klog.V(2).Infof("Ignoring DependencyViolation while deleting load-balancer security group (%s), assuming because LB is in process of deleting", securityGroupID)
3048
-
ignore=true
3049
-
}
3050
-
}
3051
-
if!ignore {
3052
-
returnfmt.Errorf("error while deleting load balancer security group (%s): %q", securityGroupID, err)
3053
-
}
3054
-
}
3055
-
}
3056
-
3057
-
iflen(securityGroupIDs) ==0 {
3058
-
klog.V(2).Info("Deleted all security groups for load balancer: ", service.Name)
3059
-
break
3060
-
}
3061
-
3062
-
iftime.Now().After(timeoutAt) {
3063
-
ids:= []string{}
3064
-
forid:=rangesecurityGroupIDs {
3065
-
ids=append(ids, id)
3066
-
}
3067
-
3068
-
returnfmt.Errorf("timed out deleting ELB: %s. Could not delete security groups %v", service.Name, strings.Join(ids, ","))
3069
-
}
3070
-
3071
-
klog.V(2).Info("Waiting for load-balancer to delete so we can delete security groups: ", service.Name)
0 commit comments