Skip to content

Commit 04e0b54

Browse files
authored
Merge pull request #880 from hidekazuna/fix_fp_event
🐛 Fix event of associate/disassociate floating IP
2 parents 7326419 + 30cb0e3 commit 04e0b54

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

pkg/cloud/services/networking/floatingip.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,25 @@ var backoff = wait.Backoff{
117117

118118
func (s *Service) AssociateFloatingIP(openStackCluster *infrav1.OpenStackCluster, fp *floatingips.FloatingIP, portID string) error {
119119
s.logger.Info("Associating floating IP", "id", fp.ID, "ip", fp.FloatingIP)
120+
120121
fpUpdateOpts := &floatingips.UpdateOpts{
121122
PortID: &portID,
122123
}
124+
123125
mc := metrics.NewMetricPrometheusContext("floating_ip", "update")
124126
_, err := floatingips.Update(s.client, fp.ID, fpUpdateOpts).Extract()
125127
if mc.ObserveRequest(err) != nil {
126128
record.Warnf(openStackCluster, "FailedAssociateFloatingIP", "Failed to associate floating IP %s with port %s: %v", fp.FloatingIP, portID, err)
127129
return err
128130
}
129-
record.Eventf(openStackCluster, "SuccessfulAssociateFloatingIP", "Associated floating IP %s with port %s", fp.FloatingIP, portID)
130131

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+
}
132136

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
140139
}
141140

142141
func (s *Service) DisassociateFloatingIP(openStackCluster *infrav1.OpenStackCluster, ip string) error {
@@ -154,21 +153,30 @@ func (s *Service) DisassociateFloatingIP(openStackCluster *infrav1.OpenStackClus
154153
fpUpdateOpts := &floatingips.UpdateOpts{
155154
PortID: nil,
156155
}
156+
157157
mc := metrics.NewMetricPrometheusContext("floating_ip", "update")
158158
_, err = floatingips.Update(s.client, fip.ID, fpUpdateOpts).Extract()
159159
if mc.ObserveRequest(err) != nil {
160160
record.Warnf(openStackCluster, "FailedDisassociateFloatingIP", "Failed to disassociate floating IP %s: %v", fip.FloatingIP, err)
161161
return err
162162
}
163-
record.Eventf(openStackCluster, "SuccessfulDisassociateFloatingIP", "Disassociated floating IP %s", fip.FloatingIP)
164163

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+
}
166172

173+
func (s *Service) waitForFloatingIP(id, target string) error {
174+
s.logger.Info("Waiting for floating IP", "id", id, "targetStatus", target)
167175
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()
169177
if err != nil {
170178
return false, err
171179
}
172-
return fip.Status == "DOWN", nil
180+
return fip.Status == target, nil
173181
})
174182
}

0 commit comments

Comments
 (0)