fix(stacks): fix stack name resolution not filtering by endpoint#5
Open
FAZuH wants to merge 2 commits into
Open
fix(stacks): fix stack name resolution not filtering by endpoint#5FAZuH wants to merge 2 commits into
FAZuH wants to merge 2 commits into
Conversation
`get_stack_id_from_name` fetches iterates over all stacks and returns the id of the first stack with matching `name`. When stacks share a name across endpoints, this can match the wrong stack, causing an API error. Fix by filtering with `endpoint_id`, and move `choose_endpoint` before `resolve_stack` in affected handlers.
…esolution Adds an unit test that mocks the Portainer API to test stacks with the same name on different endpoints are correctly filtered by its endpoint. This test will fail without the enpoint filter added in 3158471.
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.
get_stack_id_from_name matched stacks by name only, without considering the endpoint. Since the same stack name can exist across multiple endpoints, this could return the wrong stack ID.
This PR adds
endpoint_idto filter stacks inget_stack_id_from_nameandresolve_stackinhelpers.rs, which fixes the incorrect resolution. This function is only used bystackssubcommands (deploy,remove,start,stop,resource-control), most of which require--endpointto be specified, so passingendpoint_idthrough is a non-breaking change.This PR also adds
get_stack_id_from_name_filters_by_endpoint_idunit test, which mocks an API response containing two stacks with identical names on different endpoints, asserting each resolves to its correct ID and that a non-existent endpoint returnsNone. This test fails against the previous implementation.