[Fleet] Allow to delete orphaned agentless policies#271952
Open
nchaulet wants to merge 5 commits into
Open
Conversation
|
Pinging @elastic/fleet (Team:Fleet) |
Contributor
💚 Build Succeeded
Metrics [docs]
History
cc @nchaulet |
MichelLosier
approved these changes
May 29, 2026
Contributor
MichelLosier
left a comment
There was a problem hiding this comment.
Looks and works great! ![]()
| }); | ||
| } | ||
|
|
||
| private async deleteOrphanedAgentlessResources(policyId: string, user?: any) { |
Contributor
There was a problem hiding this comment.
[nit] Think we can avoid the any type here
Suggested change
| private async deleteOrphanedAgentlessResources(policyId: string, user?: any) { | |
| private async deleteOrphanedAgentlessResources(policyId: string, user?: AuthenticatedUser, { |
WIth that may not need to ?? undefined below, since the AuthenticatedUser type is expected.
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
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.
Summary
Resolves #266426
When an agentless agent policy is manually deleted from Elasticsearch, its associated package policies become orphaned. Attempting to delete them through the agentless API fails with a 404 because the agent
policy no longer exists.
This PR handles that 404 gracefully by cleaning up orphaned resources (package policies and agentless deployment) instead of throwing.
Changes
deleteAgentlessPolicynow catches 404 fromagentPolicyService.get()and falls back to orphan cleanup instead of throwingdeleteOrphanedAgentlessResources(new private method) deletes orphaned package policies viafindAllForAgentPolicy+deletewithforce: true, then issues a best-effort DELETE to the Agentless APITest plan