Skip to content

Fix wrongful use of GetDependency - #911

Merged
mandre merged 3 commits into
k-orc:mainfrom
shiftstack:fetch-dependency-adoption
Sep 16, 2026
Merged

mandre merged 3 commits into
k-orc:mainfrom
shiftstack:fetch-dependency-adoption

Conversation

@mandre

@mandre mandre commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

The endpoint controller wrongfully used GetDependency instead of FetchDependency which added a finalizer to dependency objects as a side effect.

Also add the snippet to the ListOSResourcesForAdoption() function in the scaffolding.

…rcesForAdoption

ListOSResourcesForAdoption is a read-only lookup to check if an existing
OpenStack resource matches the spec for adoption. It should not add
finalizers to dependency objects.

Replace serviceDependency.GetDependency() and regionDependency.GetDependency()
with dependency.FetchDependency(), which performs a lightweight lookup without
finalizer side effects. This matches the pattern used by all other controllers
(router, network, securitygroup, subnet, group, floatingip, limit, role).
Reuse the existing create dependency lists (RequiredCreateDependencies
and OptionalCreateDependencies) to generate FetchDependency calls in
ListOSResourcesForAdoption. Adoption dependencies typically match
create dependencies, and any controller-specific differences can be
customized after scaffolding.

Required create deps use address-of (&resourceSpec.XxxRef) for value-type
refs, while optional ones use the pointer directly (resourceSpec.XxxRef)
and are guarded by a nil check.

This follows the pattern established by controllers like router, network,
securitygroup, subnet, and limit, which all use FetchDependency in their
adoption methods.
Add a note in the FetchDependency section clarifying that
ListOSResourcesForAdoption must always use FetchDependency, never
GetDependency from a DeletionGuardDependency, since adoption is a
read-only check that should not add finalizers.
"github.com/k-orc/openstack-resource-controller/v2/internal/logging"
"github.com/k-orc/openstack-resource-controller/v2/internal/osclients"
{{- if len .ImportDependencies }}
{{- if or (len .ImportDependencies) (len .AllCreateDependencies) }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know go template uses polish notation for logical operands. Cool

@mandre
mandre added this pull request to the merge queue Sep 16, 2026
Merged via the queue into k-orc:main with commit f7f834e Sep 16, 2026
10 checks passed
@mandre
mandre deleted the fetch-dependency-adoption branch September 16, 2026 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver:patch No API change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants