Skip to content

Commit 5d49331

Browse files
hidekazunak8s-ci-robot
authored andcommitted
Use Octavia (#426)
1 parent d43c67f commit 5d49331

File tree

27 files changed

+532
-230
lines changed

27 files changed

+532
-230
lines changed

config/crds/openstackproviderconfig_v1alpha1_openstackclusterproviderspec.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,13 @@ spec:
200200
items:
201201
type: string
202202
type: array
203+
useOctavia:
204+
description: UseOctavia is weather LoadBalancer Service is Octavia or not
205+
type: boolean
203206
required:
204207
- cloudsSecret
205208
- cloudName
209+
- useOctavia
206210
- managedAPIServerLoadBalancer
207211
- managedSecurityGroups
208212
version: v1alpha1

pkg/apis/openstackproviderconfig/v1alpha1/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ type OpenstackClusterProviderSpec struct {
202202
// ExternalNetworkID is the ID of an external OpenStack Network. This is necessary
203203
// to get public internet to the VMs.
204204
ExternalNetworkID string `json:"externalNetworkId,omitempty"`
205+
// UseOctavia is weather LoadBalancer Service is Octavia or not
206+
UseOctavia bool `json:"useOctavia"`
205207

206208
// ManagedAPIServerLoadBalancer defines whether a LoadBalancer for the
207209
// APIServer should be created. If set to true the following properties are

pkg/cloud/openstack/cluster/actuator.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"reflect"
1616
providerv1 "sigs.k8s.io/cluster-api-provider-openstack/pkg/apis/openstackproviderconfig/v1alpha1"
1717
"sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/openstack/services/certificates"
18+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/openstack/services/loadbalancer"
1819
"sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/openstack/services/networking"
1920
"sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/openstack/services/provider"
2021
"sigs.k8s.io/cluster-api-provider-openstack/pkg/deployer"
@@ -78,6 +79,10 @@ func (a *Actuator) Reconcile(cluster *clusterv1.Cluster) error {
7879
if err != nil {
7980
return err
8081
}
82+
loadbalancerService, err := loadbalancer.NewService(osProviderClient, clientOpts, clusterProviderSpec.UseOctavia)
83+
if err != nil {
84+
return err
85+
}
8186

8287
defer func() {
8388
if err := a.storeCluster(cluster, clusterCopy, clusterProviderSpec, clusterProviderStatus); err != nil {
@@ -108,7 +113,7 @@ func (a *Actuator) Reconcile(cluster *clusterv1.Cluster) error {
108113
return errors.Errorf("failed to reconcile router: %v", err)
109114
}
110115
if clusterProviderSpec.ManagedAPIServerLoadBalancer {
111-
err = networkingService.ReconcileLoadBalancer(clusterName, clusterProviderSpec, clusterProviderStatus)
116+
err = loadbalancerService.ReconcileLoadBalancer(clusterName, clusterProviderSpec, clusterProviderStatus)
112117
if err != nil {
113118
return errors.Errorf("failed to reconcile load balancer: %v", err)
114119
}

pkg/cloud/openstack/machine/actuator.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)