@@ -18,7 +18,6 @@ package floatingip
1818
1919import (
2020 "context"
21- "fmt"
2221 "iter"
2322
2423 "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/layer3/floatingips"
@@ -27,10 +26,10 @@ import (
2726 "github.com/k-orc/openstack-resource-controller/v2/internal/controllers/generic/progress"
2827 "github.com/k-orc/openstack-resource-controller/v2/internal/logging"
2928 osclients "github.com/k-orc/openstack-resource-controller/v2/internal/osclients"
29+ "github.com/k-orc/openstack-resource-controller/v2/internal/util/dependency"
3030 orcerrors "github.com/k-orc/openstack-resource-controller/v2/internal/util/errors"
3131 "github.com/k-orc/openstack-resource-controller/v2/internal/util/tags"
3232 corev1 "k8s.io/api/core/v1"
33- apierrors "k8s.io/apimachinery/pkg/api/errors"
3433 "k8s.io/utils/ptr"
3534 ctrl "sigs.k8s.io/controller-runtime"
3635 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -89,62 +88,29 @@ func (actuator floatingipActuator) ListOSResourcesForAdoption(ctx context.Contex
8988func (actuator floatingipCreateActuator ) ListOSResourcesForImport (ctx context.Context , obj orcObjectPT , filter filterT ) (iter.Seq2 [* osResourceT , error ], progress.ReconcileStatus ) {
9089 var reconcileStatus progress.ReconcileStatus
9190
92- network := & orcv1alpha1.Network {}
93- if filter .FloatingNetworkRef != nil {
94- networkKey := client.ObjectKey {Name : string (ptr .Deref (filter .FloatingNetworkRef , "" )), Namespace : obj .Namespace }
95- if err := actuator .k8sClient .Get (ctx , networkKey , network ); err != nil {
96- if apierrors .IsNotFound (err ) {
97- reconcileStatus = reconcileStatus .WithReconcileStatus (
98- progress .WaitingOnObject ("Network" , networkKey .Name , progress .WaitingOnCreation ))
99- } else {
100- reconcileStatus = reconcileStatus .WithReconcileStatus (
101- progress .WrapError (fmt .Errorf ("fetching network %s: %w" , networkKey .Name , err )))
102- }
103- } else {
104- if ! orcv1alpha1 .IsAvailable (network ) || network .Status .ID == nil {
105- reconcileStatus = reconcileStatus .WithReconcileStatus (
106- progress .WaitingOnObject ("Network" , networkKey .Name , progress .WaitingOnReady ))
107- }
108- }
109- }
110-
111- port := & orcv1alpha1.Port {}
112- if filter .PortRef != nil {
113- portKey := client.ObjectKey {Name : string (ptr .Deref (filter .PortRef , "" )), Namespace : obj .Namespace }
114- if err := actuator .k8sClient .Get (ctx , portKey , port ); err != nil {
115- if apierrors .IsNotFound (err ) {
116- reconcileStatus = reconcileStatus .WithReconcileStatus (
117- progress .WaitingOnObject ("Port" , portKey .Name , progress .WaitingOnCreation ))
118- } else {
119- reconcileStatus = reconcileStatus .WithReconcileStatus (
120- progress .WrapError (fmt .Errorf ("fetching port %s: %w" , portKey .Name , err )))
121- }
122- } else {
123- if ! orcv1alpha1 .IsAvailable (port ) || port .Status .ID == nil {
124- reconcileStatus = reconcileStatus .WithReconcileStatus (
125- progress .WaitingOnObject ("Port" , portKey .Name , progress .WaitingOnReady ))
126- }
127- }
128- }
129-
130- project := & orcv1alpha1.Project {}
131- if filter .ProjectRef != nil {
132- projectKey := client.ObjectKey {Name : string (* filter .ProjectRef ), Namespace : obj .Namespace }
133- if err := actuator .k8sClient .Get (ctx , projectKey , project ); err != nil {
134- if apierrors .IsNotFound (err ) {
135- reconcileStatus = reconcileStatus .WithReconcileStatus (
136- progress .WaitingOnObject ("Project" , projectKey .Name , progress .WaitingOnCreation ))
137- } else {
138- reconcileStatus = reconcileStatus .WithReconcileStatus (
139- progress .WrapError (fmt .Errorf ("fetching project %s: %w" , projectKey .Name , err )))
140- }
141- } else {
142- if ! orcv1alpha1 .IsAvailable (project ) || project .Status .ID == nil {
143- reconcileStatus = reconcileStatus .WithReconcileStatus (
144- progress .WaitingOnObject ("Project" , projectKey .Name , progress .WaitingOnReady ))
145- }
146- }
147- }
91+ network , rs := dependency .FetchDependency (
92+ ctx , actuator .k8sClient , obj .Namespace , filter .FloatingNetworkRef , "Network" ,
93+ func (dep * orcv1alpha1.Network ) bool {
94+ return orcv1alpha1 .IsAvailable (dep ) && dep .Status .ID != nil
95+ },
96+ )
97+ reconcileStatus = reconcileStatus .WithReconcileStatus (rs )
98+
99+ port , rs := dependency .FetchDependency (
100+ ctx , actuator .k8sClient , obj .Namespace , filter .PortRef , "Port" ,
101+ func (dep * orcv1alpha1.Port ) bool {
102+ return orcv1alpha1 .IsAvailable (dep ) && dep .Status .ID != nil
103+ },
104+ )
105+ reconcileStatus = reconcileStatus .WithReconcileStatus (rs )
106+
107+ project , rs := dependency .FetchDependency (
108+ ctx , actuator .k8sClient , obj .Namespace , filter .ProjectRef , "Project" ,
109+ func (dep * orcv1alpha1.Project ) bool {
110+ return orcv1alpha1 .IsAvailable (dep ) && dep .Status .ID != nil
111+ },
112+ )
113+ reconcileStatus = reconcileStatus .WithReconcileStatus (rs )
148114
149115 if needsReschedule , _ := reconcileStatus .NeedsReschedule (); needsReschedule {
150116 return nil , reconcileStatus
0 commit comments