@@ -117,26 +117,25 @@ var backoff = wait.Backoff{
117
117
118
118
func (s * Service ) AssociateFloatingIP (openStackCluster * infrav1.OpenStackCluster , fp * floatingips.FloatingIP , portID string ) error {
119
119
s .logger .Info ("Associating floating IP" , "id" , fp .ID , "ip" , fp .FloatingIP )
120
+
120
121
fpUpdateOpts := & floatingips.UpdateOpts {
121
122
PortID : & portID ,
122
123
}
124
+
123
125
mc := metrics .NewMetricPrometheusContext ("floating_ip" , "update" )
124
126
_ , err := floatingips .Update (s .client , fp .ID , fpUpdateOpts ).Extract ()
125
127
if mc .ObserveRequest (err ) != nil {
126
128
record .Warnf (openStackCluster , "FailedAssociateFloatingIP" , "Failed to associate floating IP %s with port %s: %v" , fp .FloatingIP , portID , err )
127
129
return err
128
130
}
129
- record .Eventf (openStackCluster , "SuccessfulAssociateFloatingIP" , "Associated floating IP %s with port %s" , fp .FloatingIP , portID )
130
131
131
- s .logger .Info ("Waiting for floating IP" , "id" , fp .ID , "targetStatus" , "ACTIVE" )
132
+ if err = s .waitForFloatingIP (fp .ID , "ACTIVE" ); err != nil {
133
+ record .Warnf (openStackCluster , "FailedAssociateFloatingIP" , "Failed to associate floating IP %s with port %s: wait for floating IP ACTIVE: %v" , fp .FloatingIP , portID , err )
134
+ return err
135
+ }
132
136
133
- return wait .ExponentialBackoff (backoff , func () (bool , error ) {
134
- fp , err := floatingips .Get (s .client , fp .ID ).Extract ()
135
- if err != nil {
136
- return false , err
137
- }
138
- return fp .Status == "ACTIVE" , nil
139
- })
137
+ record .Eventf (openStackCluster , "SuccessfulAssociateFloatingIP" , "Associated floating IP %s with port %s" , fp .FloatingIP , portID )
138
+ return nil
140
139
}
141
140
142
141
func (s * Service ) DisassociateFloatingIP (openStackCluster * infrav1.OpenStackCluster , ip string ) error {
@@ -154,21 +153,30 @@ func (s *Service) DisassociateFloatingIP(openStackCluster *infrav1.OpenStackClus
154
153
fpUpdateOpts := & floatingips.UpdateOpts {
155
154
PortID : nil ,
156
155
}
156
+
157
157
mc := metrics .NewMetricPrometheusContext ("floating_ip" , "update" )
158
158
_ , err = floatingips .Update (s .client , fip .ID , fpUpdateOpts ).Extract ()
159
159
if mc .ObserveRequest (err ) != nil {
160
160
record .Warnf (openStackCluster , "FailedDisassociateFloatingIP" , "Failed to disassociate floating IP %s: %v" , fip .FloatingIP , err )
161
161
return err
162
162
}
163
- record .Eventf (openStackCluster , "SuccessfulDisassociateFloatingIP" , "Disassociated floating IP %s" , fip .FloatingIP )
164
163
165
- s .logger .Info ("Waiting for floating IP" , "id" , fip .ID , "targetStatus" , "DOWN" )
164
+ if err = s .waitForFloatingIP (fip .ID , "DOWN" ); err != nil {
165
+ record .Warnf (openStackCluster , "FailedDisassociateFloatingIP" , "Failed to disassociate floating IP: wait for floating IP DOWN: %v" , fip .FloatingIP , err )
166
+ return err
167
+ }
168
+
169
+ record .Eventf (openStackCluster , "SuccessfulDisassociateFloatingIP" , "Disassociated floating IP %s" , fip .FloatingIP )
170
+ return nil
171
+ }
166
172
173
+ func (s * Service ) waitForFloatingIP (id , target string ) error {
174
+ s .logger .Info ("Waiting for floating IP" , "id" , id , "targetStatus" , target )
167
175
return wait .ExponentialBackoff (backoff , func () (bool , error ) {
168
- fip , err := floatingips .Get (s .client , fip . ID ).Extract ()
176
+ fip , err := floatingips .Get (s .client , id ).Extract ()
169
177
if err != nil {
170
178
return false , err
171
179
}
172
- return fip .Status == "DOWN" , nil
180
+ return fip .Status == target , nil
173
181
})
174
182
}
0 commit comments