Repository navigation
Remove IAM role from its instance profile before deleting orphaned role - #18845
shreyaabaranwal wants to merge 1 commit into
Conversation
When the last instance group of a role is deleted, update cluster tries to delete the orphaned IAM role, but the role is still in its instance profile, so DeleteRole fails with DeleteConflict and the update fails after retrying for 10 minutes. Remove the role from its same-name instance profile and delete the profile if it is owned by the cluster. Skip the role if the profile is not owned, or if the profile is still in the model. Signed-off-by: shreyaabaranwal <shreyabaranwal229@gmail.com>
|
Hi @shreyaabaranwal. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Fixes #18838
When the last instance group of a role is deleted (for example
kops delete ig bastions), the nextkops update cluster --yestries to garbage-collect the orphaned IAM role. The role is still in its instance profile, soDeleteRolefails withDeleteConflict. The task keeps retrying until the 10 minute deadline and the whole update fails. Automation likeupdate --yes && rolling-update --yesstops halfway, and every later update fails the same way until the profile is fixed by hand.The delete branch of
IAMRole.RenderAWSremoves inline and managed policies and then callsDeleteRole, but never removes the role from its instance profile.FindDeletionsalso doesn't queue the orphaned profile.What this PR changes:
IAMName). If it is taggedkubernetes.io/cluster/<cluster>: owned, remove the role from it and delete it, then delete the role as before.FindDeletions, don't queue a role whose same-nameIAMInstanceProfileis still in the model. This coversspec.iam.profilepointing at kops's own profile, where the role drops out of the model but running nodes still use the profile.I used
GetInstanceProfilewith the known name rather than addingListInstanceProfilesForRoleto the IAM interface, to keep the change small and easy to backport. I kept this in the role task instead of queuing a separate profile deletion, because there's no ordering between deletion tasks fromFindDeletionstoday, so the role and profile deletions would run in parallel.Mock changes:
mockiamdidn't behave like AWS here, which is why no test caught this.DeleteRolenow returnsDeleteConflictExceptionwhile the role is in an instance profile andNoSuchEntityExceptionfor a missing role.DeleteInstanceProfilereturnsDeleteConflictExceptionwhile the profile still has a role. I also addedDetachRolePolicy, which was missing.Tests:
iamrole_test.go: owned role in an owned profile (role and profile are deleted), profile not owned by the cluster (nothing is detached or deleted, no error), and a role without a profile (unchanged behaviour). The first two fail on master with the same DeleteConflict deadline error as the issue.iam_test.go:FindDeletionsdoesn't queue a role whose profile is still in the model.go test ./cmd/kops/...(lifecycle and integration tests) pass with no golden file changes.make quick-ciandverify-golangci-lintpass.Known limits:
Open question:
If an instance group switches from the managed profile to a custom
spec.iam.profile, the old instances keep using the managed profile until a rolling update. With this change, the nextupdate --yeswould remove that profile before the rolling update. Is that acceptable, or would you prefer to skip it in that case?Possible follow-ups (not in this PR):
kops delete clusterhas the same gap for untagged profiles.iaminstanceprofile.go:135dereferencesa.Nameinside thea == nilbranch.ListAttachedRolePoliciescompares role name pointers instead of values.