Skip to content

Commit d4a2640

Browse files
Use Patch instead of Update for interface config in NX-OS
EnsureInterface now uses sb.Patch (gNMI update/merge) for all interface configuration objects instead of sb.Update (gNMI replace). This prevents the operator from clobbering interface config written by other automation (e.g. an OpenStack driver agent) that manages the same interface subtree concurrently. Signed-off-by: Felix Kästner <felix.kaestner@sap.com>
1 parent 9fd5d82 commit d4a2640

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

‎internal/provider/cisco/nxos/provider.go‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
13351335
return err
13361336
}
13371337

1338-
sb.Update(p)
1338+
sb.Patch(p)
13391339

13401340
case v1alpha1.InterfaceTypeLoopback:
13411341
lb := new(Loopback)
@@ -1348,7 +1348,7 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
13481348
lb.AdminSt = AdminStUp
13491349
}
13501350
lb.RtvrfMbrItems = NewVrfMember(name, vrf)
1351-
sb.Update(lb)
1351+
sb.Patch(lb)
13521352

13531353
case v1alpha1.InterfaceTypeAggregate:
13541354
f := new(Feature)
@@ -1462,13 +1462,13 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
14621462
}
14631463
}
14641464

1465-
sb.Update(pc)
1465+
sb.Patch(pc)
14661466

14671467
if req.MultiChassisID != nil {
14681468
v := new(VPCIf)
14691469
v.ID = int(*req.MultiChassisID)
14701470
v.SetPortChannel(name)
1471-
sb.Update(v)
1471+
sb.Patch(v)
14721472
}
14731473

14741474
case v1alpha1.InterfaceTypeRoutedVLAN:
@@ -1491,7 +1491,7 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
14911491
}
14921492
svi.VlanID = req.VLAN.Spec.ID
14931493
svi.RtvrfMbrItems = NewVrfMember(name, vrf)
1494-
sb.Update(svi)
1494+
sb.Patch(svi)
14951495

14961496
fwif := new(FabricFwdIf)
14971497
fwif.ID = name
@@ -1508,7 +1508,7 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
15081508

15091509
fwif.AdminSt = AdminStEnabled
15101510
fwif.Mode = FwdModeAnycastGateway
1511-
sb.Update(fwif)
1511+
sb.Patch(fwif)
15121512
default:
15131513
sb.Delete(fwif)
15141514
}
@@ -1550,7 +1550,7 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
15501550
s.Medium = MediumPointToPoint
15511551
}
15521552

1553-
sb.Update(s)
1553+
sb.Patch(s)
15541554

15551555
default:
15561556
return apistatus.NewUnsupportedFieldError(apistatus.FieldViolation{
@@ -1589,27 +1589,27 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
15891589
}
15901590
}
15911591
}
1592-
sb.Update(stp)
1592+
sb.Patch(stp)
15931593
}
15941594

15951595
// Add the address items last, as they depend on the interface being created first.
15961596
if addr != nil {
1597-
sb.Update(addr)
1597+
sb.Patch(addr)
15981598
}
15991599

16001600
switch {
16011601
case req.Interface.Spec.BFD != nil && req.Interface.Spec.BFD.Enabled:
16021602
f := new(Feature)
16031603
f.Name = "bfd"
16041604
f.AdminSt = AdminStEnabled
1605-
sb.Update(f)
1605+
sb.Patch(f)
16061606

16071607
// Disable ICMP redirect messages on BFD-enabled interfaces.
16081608
// See: https://www.cisco.com/c/en/us/td/docs/dcn/nx-os/nexus9000/106x/configuration/interfaces/cisco-nexus-9000-series-nx-os-interfaces-configuration-guide-release-106x/b-cisco-nexus-9000-nx-os-interfaces-configuration-guide-93x_chapter_01111.html
16091609
icmp := new(ICMPIf)
16101610
icmp.ID = name
16111611
icmp.Ctrl = "port-unreachable"
1612-
sb.Update(icmp)
1612+
sb.Patch(icmp)
16131613

16141614
bfd := new(BFD)
16151615
bfd.ID = name
@@ -1629,18 +1629,18 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
16291629
if err := bfd.Validate(); err != nil {
16301630
return err
16311631
}
1632-
sb.Update(bfd)
1632+
sb.Patch(bfd)
16331633

16341634
case req.Interface.Spec.BFD != nil && !req.Interface.Spec.BFD.Enabled:
16351635
f := new(Feature)
16361636
f.Name = "bfd"
16371637
f.AdminSt = AdminStEnabled
1638-
sb.Update(f)
1638+
sb.Patch(f)
16391639

16401640
bfd := new(BFD)
16411641
bfd.ID = name
16421642
bfd.AdminSt = AdminStDisabled
1643-
sb.Update(bfd)
1643+
sb.Patch(bfd)
16441644

16451645
default:
16461646
// BFD not specified — clean up any leftover BFD config on the interface.
@@ -1659,10 +1659,10 @@ func (p *Provider) EnsureInterface(ctx context.Context, req *provider.EnsureInte
16591659
sb.Delete(icmp)
16601660
case v1alpha1.InterfaceTypeLoopback:
16611661
icmp.Ctrl = "port-unreachable,redirect"
1662-
sb.Update(icmp)
1662+
sb.Patch(icmp)
16631663
case v1alpha1.InterfaceTypeRoutedVLAN:
16641664
icmp.Ctrl = "port-unreachable"
1665-
sb.Update(icmp)
1665+
sb.Patch(icmp)
16661666
}
16671667
}
16681668

0 commit comments

Comments
 (0)