Skip to content

fix(stacks): fix stack name resolution not filtering by endpoint#5

Open
FAZuH wants to merge 2 commits into
wahl-dev:mainfrom
FAZuH:fix/stackname-incorrect-endpoint
Open

fix(stacks): fix stack name resolution not filtering by endpoint#5
FAZuH wants to merge 2 commits into
wahl-dev:mainfrom
FAZuH:fix/stackname-incorrect-endpoint

Conversation

@FAZuH

@FAZuH FAZuH commented Jun 3, 2026

Copy link
Copy Markdown

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_id to filter stacks in get_stack_id_from_name and resolve_stack in helpers.rs, which fixes the incorrect resolution. This function is only used by stacks subcommands (deploy, remove, start, stop, resource-control), most of which require --endpoint to be specified, so passing endpoint_id through is a non-breaking change.

This PR also adds get_stack_id_from_name_filters_by_endpoint_id unit 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 returns None. This test fails against the previous implementation.

FAZuH added 2 commits June 3, 2026 02:37
`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.
@FAZuH FAZuH marked this pull request as ready for review June 3, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant