@@ -26,7 +26,7 @@ import (
2626 "reflect"
2727 constants "sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/openstack/contants"
2828 "sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/openstack/services/compute"
29- "sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/openstack/services/networking "
29+ "sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/openstack/services/loadbalancer "
3030 "sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/openstack/services/provider"
3131 "sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/openstack/services/userdata"
3232 "sigs.k8s.io/cluster-api-provider-openstack/pkg/deployer"
@@ -96,11 +96,6 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
9696 return err
9797 }
9898
99- networkingService , err := networking .NewService (osProviderClient , clientOpts )
100- if err != nil {
101- return err
102- }
103-
10499 clusterProviderSpec , clusterProviderStatus , err := providerv1 .ClusterSpecAndStatusFromProviderSpec (cluster )
105100 if err != nil {
106101 return a .handleMachineError (machine , apierrors .CreateMachine (
@@ -161,8 +156,12 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
161156 }
162157 }
163158
159+ loadbalancerService , err := loadbalancer .NewService (osProviderClient , clientOpts , clusterProviderSpec .UseOctavia )
160+ if err != nil {
161+ return err
162+ }
164163 if clusterProviderSpec .ManagedAPIServerLoadBalancer {
165- err := networkingService .ReconcileLoadBalancerMember (clusterName , machine , clusterProviderSpec , clusterProviderStatus )
164+ err := loadbalancerService .ReconcileLoadBalancerMember (clusterName , machine , clusterProviderSpec , clusterProviderStatus )
166165 if err != nil {
167166 return a .handleMachineError (machine , apierrors .CreateMachine (
168167 "Reconcile LoadBalancer Member err: %v" , err ))
@@ -216,19 +215,18 @@ func (a *Actuator) Delete(ctx context.Context, cluster *clusterv1.Cluster, machi
216215 return err
217216 }
218217
219- networkingService , err := networking .NewService (osProviderClient , clientOpts )
220- if err != nil {
221- return err
222- }
223-
224218 clusterProviderSpec , clusterProviderStatus , err := providerv1 .ClusterSpecAndStatusFromProviderSpec (cluster )
225219 if err != nil {
226220 return a .handleMachineError (machine , apierrors .CreateMachine (
227221 "error updating Openstack instance: %v" , err ))
228222 }
229223
224+ loadbalancerService , err := loadbalancer .NewService (osProviderClient , clientOpts , clusterProviderSpec .UseOctavia )
225+ if err != nil {
226+ return err
227+ }
230228 if clusterProviderSpec .ManagedAPIServerLoadBalancer {
231- err = networkingService .DeleteLoadBalancerMember (clusterName , machine , clusterProviderStatus )
229+ err = loadbalancerService .DeleteLoadBalancerMember (clusterName , machine , clusterProviderStatus )
232230 if err != nil {
233231 return err
234232 }
@@ -268,11 +266,6 @@ func (a *Actuator) Update(ctx context.Context, cluster *clusterv1.Cluster, machi
268266 return err
269267 }
270268
271- networkingService , err := networking .NewService (osProviderClient , clientOpts )
272- if err != nil {
273- return err
274- }
275-
276269 clusterProviderSpec , clusterProviderStatus , err := providerv1 .ClusterSpecAndStatusFromProviderSpec (cluster )
277270 if err != nil {
278271 return a .handleMachineError (machine , apierrors .CreateMachine (
@@ -347,9 +340,13 @@ func (a *Actuator) Update(ctx context.Context, cluster *clusterv1.Cluster, machi
347340 }
348341 }
349342 }
343+ loadbalancerService , err := loadbalancer .NewService (osProviderClient , clientOpts , clusterProviderSpec .UseOctavia )
344+ if err != nil {
345+ return err
346+ }
350347
351348 if clusterProviderSpec .ManagedAPIServerLoadBalancer {
352- err = networkingService .ReconcileLoadBalancerMember (clusterName , machine , clusterProviderSpec , clusterProviderStatus )
349+ err = loadbalancerService .ReconcileLoadBalancerMember (clusterName , machine , clusterProviderSpec , clusterProviderStatus )
353350 if err != nil {
354351 return err
355352 }
0 commit comments