-
Notifications
You must be signed in to change notification settings - Fork 127
Clean Up AWS Resources After Cluster Deletion #1396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Vivek Reddy <[email protected]>
akondur
approved these changes
Nov 8, 2024
Collaborator
akondur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
akondur
reviewed
Nov 12, 2024
akondur
reviewed
Nov 12, 2024
Signed-off-by: vivekr-splunk <[email protected]>
Collaborator
Author
|
I think security group need to be deleted later once cluster gets cleared
,i will test it out
…On Tue, Nov 12, 2024 at 9:54 AM Arjun Kondur ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In test/deploy-eks-cluster.sh
<#1396 (comment)>
:
> @@ -21,6 +21,22 @@ if [[ -z "${EKS_CLUSTER_K8_VERSION}" ]]; then
fi
function deleteCluster() {
+ echo "Cleanup role, security-group, open-id ${TEST_CLUSTER_NAME}"
+ account_id=$(aws sts get-caller-identity --query "Account" --output text)
+ rolename=$(echo ${TEST_CLUSTER_NAME} | awk -F- '{print "EBS_" $(NF-1) "_" $(NF)}')
+ role_attached_policies=$(aws iam list-attached-role-policies --role-name $rolename --query 'AttachedPolicies[*].PolicyArn' --output text)
+ for policy_arn in ${role_attached_policies};
+ do
+ aws iam detach-role-policy --role-name ${rolename} --policy-arn ${policy_arn}
+ done
+
+ aws iam delete-role --role-name ${rolename}
+ oidc_id=$(aws eks describe-cluster --name ${TEST_CLUSTER_NAME} --query "cluster.identity.oidc.issuer" --output text | cut -d '/' -f 5)
+ aws iam delete-open-id-connect-provider --open-id-connect-provider-arn arn:aws:iam::${account_id}:oidc-provider/${oidc_id}
+ security_group_id=$(aws eks describe-cluster --name ${TEST_CLUSTER_NAME} --query "cluster.resourcesVpcConfig.securityGroupIds[0]" --output text)
+ aws ec2 delete-security-group --group-id ${security_group_id}
Looks like security groups also have dependent objects:
An error occurred (DependencyViolation) when calling the DeleteSecurityGroup operation: resource sg-0158103d0e31e7ef1 has a dependent object
—
Reply to this email directly, view it on GitHub
<#1396 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWRQER6FAFPXUDT5DHDQNQL2AI6FBAVCNFSM6AAAAABRN67QWWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDIMZQGMZDGNBXGE>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
Signed-off-by: vivekr-splunk <[email protected]>
akondur
approved these changes
Nov 12, 2024
Collaborator
|
I tried deleting it post cluster deletion as well and it fails:
.
.
.
2024-11-12 16:01:18 [✔] all cluster resources were deleted
Cluster eks-sok-smoke-test-cluster-managersecret-109839685 deleted
successfully
.
.
Deleting security group
An error occurred (DependencyViolation) when calling the
DeleteSecurityGroup operation: resource sg-0e17b70c84157efe2 has a
dependent object
I believe it may have network interfaces linked to it.
Thanks and Regards,
Arjun Kondur
On Tue, Nov 12, 2024 at 12:01 PM vivekr-splunk ***@***.***>
wrote:
… I think security group need to be deleted later once cluster gets cleared
,i will test it out
On Tue, Nov 12, 2024 at 9:54 AM Arjun Kondur ***@***.***>
wrote:
> ***@***.**** commented on this pull request.
> ------------------------------
>
> In test/deploy-eks-cluster.sh
> <
#1396 (comment)>
> :
>
> > @@ -21,6 +21,22 @@ if [[ -z "${EKS_CLUSTER_K8_VERSION}" ]]; then
> fi
>
> function deleteCluster() {
> + echo "Cleanup role, security-group, open-id ${TEST_CLUSTER_NAME}"
> + account_id=$(aws sts get-caller-identity --query "Account" --output
text)
> + rolename=$(echo ${TEST_CLUSTER_NAME} | awk -F- '{print "EBS_" $(NF-1)
"_" $(NF)}')
> + role_attached_policies=$(aws iam list-attached-role-policies
--role-name $rolename --query 'AttachedPolicies[*].PolicyArn' --output
text)
> + for policy_arn in ${role_attached_policies};
> + do
> + aws iam detach-role-policy --role-name ${rolename} --policy-arn
${policy_arn}
> + done
> +
> + aws iam delete-role --role-name ${rolename}
> + oidc_id=$(aws eks describe-cluster --name ${TEST_CLUSTER_NAME} --query
"cluster.identity.oidc.issuer" --output text | cut -d '/' -f 5)
> + aws iam delete-open-id-connect-provider --open-id-connect-provider-arn
arn:aws:iam::${account_id}:oidc-provider/${oidc_id}
> + security_group_id=$(aws eks describe-cluster --name
${TEST_CLUSTER_NAME} --query
"cluster.resourcesVpcConfig.securityGroupIds[0]" --output text)
> + aws ec2 delete-security-group --group-id ${security_group_id}
>
> Looks like security groups also have dependent objects:
>
> An error occurred (DependencyViolation) when calling the
DeleteSecurityGroup operation: resource sg-0158103d0e31e7ef1 has a
dependent object
>
> —
> Reply to this email directly, view it on GitHub
> <
#1396 (review)>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/AWRQER6FAFPXUDT5DHDQNQL2AI6FBAVCNFSM6AAAAABRN67QWWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDIMZQGMZDGNBXGE>
> .
> You are receiving this because you were assigned.Message ID:
> ***@***.***>
>
—
Reply to this email directly, view it on GitHub
<#1396 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQRH3Z2DX47GXYKYATQLGF32AI66RAVCNFSM6AAAAABRN67QWWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINZRGIYTSOJQGU>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
Signed-off-by: vivekr-splunk <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Clean Up AWS Resources After Cluster Deletion
Description
This PR introduces automation to clean up any remaining AWS resources, specifically Security Groups and OIDC IDs, after a Kubernetes cluster deletion. The objective is to ensure no orphaned resources are left behind once the pipeline completes, preventing unnecessary resource usage and avoiding potential security risks associated with leftover configurations.
Changes
Why This Is Needed
Leaving behind AWS Security Groups and OIDC configurations can lead to:
Testing
Additional Notes
Please review the resource deletion logic to ensure it aligns with existing resource tagging conventions and does not inadvertently delete in-use resources in shared environments.
This PR will help maintain a clean AWS environment and improve resource efficiency in our CI/CD pipeline.