Skip to content

Commit

Permalink
Pass revision_id when assigning/removing SGs
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin committed Aug 19, 2024
1 parent 75b1fbb commit ed1d336
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions pkg/openstack/loadbalancer_sg.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ func applyNodeSecurityGroupIDForLB(network *gophercloud.ServiceClient, svcConf *
}

// Add the SG to the port
// TODO(dulek): This isn't an atomic operation. In order to protect from lost update issues we should use
// `revision_number` handling to make sure our update to `security_groups` field wasn't preceded
// by a different one. Same applies to a removal of the SG.
newSGs := append(port.SecurityGroups, sg)
updateOpts := neutronports.UpdateOpts{SecurityGroups: &newSGs}
updateOpts := neutronports.UpdateOpts{SecurityGroups: &newSGs, RevisionNumber: &port.RevisionNumber}
mc := metrics.NewMetricContext("port", "update")
res := neutronports.Update(context.TODO(), network, port.ID, updateOpts)
if mc.ObserveRequest(res.Err) != nil {
Expand Down Expand Up @@ -121,9 +118,7 @@ func disassociateSecurityGroupForLB(network *gophercloud.ServiceClient, sg strin

// Update port security groups
newSGs := existingSGs.List()
// TODO(dulek): This should be done using Neutron's revision_number to make sure
// we don't trigger a lost update issue.
updateOpts := neutronports.UpdateOpts{SecurityGroups: &newSGs}
updateOpts := neutronports.UpdateOpts{SecurityGroups: &newSGs, RevisionNumber: &port.RevisionNumber}
mc := metrics.NewMetricContext("port", "update")
res := neutronports.Update(context.TODO(), network, port.ID, updateOpts)
if mc.ObserveRequest(res.Err) != nil {
Expand Down

0 comments on commit ed1d336

Please sign in to comment.