Skip to content

Commit 71912ee

Browse files
committed
AddressScope: Tighten adoption filter
ListOSResourcesForAdoption only filtered by name. Include the immutable IPVersion field and ProjectID when set in the list filter to prevent adopting an address scope with the wrong IP version or from the wrong project.
1 parent 7fe8404 commit 71912ee

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

internal/controllers/addressscope/actuator.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,25 @@ func (actuator addressscopeActuator) ListOSResourcesForAdoption(ctx context.Cont
7171
return nil, false
7272
}
7373

74+
// Resolve the project ID from ProjectRef if set.
75+
var projectID string
76+
if resourceSpec.ProjectRef != nil {
77+
project, rs := dependency.FetchDependency(
78+
ctx, actuator.k8sClient, orcObject.Namespace, resourceSpec.ProjectRef, "Project",
79+
func(dep *orcv1alpha1.Project) bool {
80+
return orcv1alpha1.IsAvailable(dep) && dep.Status.ID != nil
81+
},
82+
)
83+
if needsReschedule, _ := rs.NeedsReschedule(); needsReschedule {
84+
return nil, false
85+
}
86+
projectID = ptr.Deref(project.Status.ID, "")
87+
}
88+
7489
listOpts := addressscopes.ListOpts{
75-
Name: getResourceName(orcObject),
90+
Name: getResourceName(orcObject),
91+
IPVersion: int(resourceSpec.IPVersion),
92+
ProjectID: projectID,
7693
}
7794

7895
return actuator.osClient.ListAddressScopes(ctx, listOpts), true

0 commit comments

Comments
 (0)