@@ -4,10 +4,6 @@ import (
44 "context"
55 "fmt"
66
7- "github.com/gophercloud/gophercloud"
8- "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags"
9- "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
10- "github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
117 "github.com/sirupsen/logrus"
128 "gopkg.in/yaml.v2"
139 capo "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7"
@@ -17,10 +13,10 @@ import (
1713 "github.com/openshift/installer/pkg/asset/manifests"
1814 "github.com/openshift/installer/pkg/asset/manifests/capiutils"
1915 "github.com/openshift/installer/pkg/infrastructure/clusterapi"
16+ "github.com/openshift/installer/pkg/infrastructure/openstack/infraready"
2017 "github.com/openshift/installer/pkg/infrastructure/openstack/preprovision"
2118 "github.com/openshift/installer/pkg/rhcos"
2219 "github.com/openshift/installer/pkg/types/openstack"
23- openstackdefaults "github.com/openshift/installer/pkg/types/openstack/defaults"
2420)
2521
2622// Provider defines the InfraProvider.
@@ -80,6 +76,7 @@ func (p Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput)
8076 infraID = in .InfraID
8177 installConfig = in .InstallConfig
8278 )
79+
8380 ospCluster := & capo.OpenStackCluster {}
8481 key := client.ObjectKey {
8582 Name : infraID ,
@@ -89,34 +86,7 @@ func (p Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput)
8986 return fmt .Errorf ("failed to get OSPCluster: %w" , err )
9087 }
9188
92- networkClient , err := openstackdefaults .NewServiceClient ("network" , openstackdefaults .DefaultClientOpts (installConfig .Config .Platform .OpenStack .Cloud ))
93- if err != nil {
94- return err
95- }
96-
97- apiPort , err := createPort (networkClient , "api" , infraID , ospCluster .Status .Network .ID , ospCluster .Status .Network .Subnets [0 ].ID , installConfig .Config .Platform .OpenStack .APIVIPs [0 ])
98- if err != nil {
99- return err
100- }
101- if installConfig .Config .OpenStack .APIFloatingIP != "" {
102- err = assignFIP (networkClient , installConfig .Config .OpenStack .APIFloatingIP , apiPort )
103- if err != nil {
104- return err
105- }
106- }
107-
108- ingressPort , err := createPort (networkClient , "ingress" , infraID , ospCluster .Status .Network .ID , ospCluster .Status .Network .Subnets [0 ].ID , installConfig .Config .Platform .OpenStack .IngressVIPs [0 ])
109- if err != nil {
110- return err
111- }
112- if installConfig .Config .OpenStack .IngressFloatingIP != "" {
113- err = assignFIP (networkClient , installConfig .Config .OpenStack .IngressFloatingIP , ingressPort )
114- if err != nil {
115- return err
116- }
117- }
118-
119- return nil
89+ return infraready .FloatingIPs (ospCluster , installConfig , infraID )
12090}
12191
12292var _ clusterapi.IgnitionProvider = Provider {}
@@ -132,58 +102,3 @@ func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]
132102
133103 return preprovision .UploadIgnitionAndBuildShim (ctx , installConfig .Config .Platform .OpenStack .Cloud , infraID , installConfig .Config .Proxy , bootstrapIgnData )
134104}
135-
136- func createPort (client * gophercloud.ServiceClient , role , infraID , networkID , subnetID , fixedIP string ) (* ports.Port , error ) {
137- createOpts := ports.CreateOpts {
138- Name : fmt .Sprintf ("%s-%s-port" , infraID , role ),
139- NetworkID : networkID ,
140- Description : "Created By OpenShift Installer" ,
141- FixedIPs : []ports.IP {
142- {
143- IPAddress : fixedIP ,
144- SubnetID : subnetID ,
145- }},
146- }
147-
148- port , err := ports .Create (client , createOpts ).Extract ()
149- if err != nil {
150- return nil , err
151- }
152-
153- tag := fmt .Sprintf ("openshiftClusterID=%s" , infraID )
154- err = attributestags .Add (client , "ports" , port .ID , tag ).ExtractErr ()
155- if err != nil {
156- return nil , err
157- }
158- return port , err
159- }
160-
161- func assignFIP (client * gophercloud.ServiceClient , address string , port * ports.Port ) error {
162- listOpts := floatingips.ListOpts {
163- FloatingIP : address ,
164- }
165- allPages , err := floatingips .List (client , listOpts ).AllPages ()
166- if err != nil {
167- return fmt .Errorf ("failed to list floating IPs: %w" , err )
168- }
169- allFIPs , err := floatingips .ExtractFloatingIPs (allPages )
170- if err != nil {
171- return fmt .Errorf ("failed to extract floating IPs: %w" , err )
172- }
173-
174- if len (allFIPs ) != 1 {
175- return fmt .Errorf ("could not find FIP: %s" , address )
176- }
177-
178- fip := allFIPs [0 ]
179-
180- updateOpts := floatingips.UpdateOpts {
181- PortID : & port .ID ,
182- }
183-
184- _ , err = floatingips .Update (client , fip .ID , updateOpts ).Extract ()
185- if err != nil {
186- return fmt .Errorf ("failed to attach floating IP to port: %w" , err )
187- }
188- return nil
189- }
0 commit comments