Skip to content

Commit fd98fee

Browse files
committed
add support for set community additive
add option to enable setting community and extcommunity additive instead of replacing the list. Signed-off-by: Ivo Gosemann <ivo.gosemann@sap.com>
1 parent 601eeea commit fd98fee

15 files changed

Lines changed: 259 additions & 20 deletions

File tree

‎Tiltfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ k8s_yaml('./config/samples/v1alpha1_prefixset.yaml')
165165
k8s_resource(new_name='ccloud-prefixset', objects=['ccloud-prefixset:prefixset'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False, labels=['samples'])
166166

167167
k8s_yaml('./config/samples/v1alpha1_routingpolicy.yaml')
168-
k8s_resource(new_name='bgp-import-policy', objects=['bgp-import-policy:routingpolicy', 'internal-networks:prefixset', 'partner-networks:prefixset', 'blocked-networks:prefixset'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False, labels=['samples'])
168+
k8s_resource(new_name='bgp-import-policy', objects=['bgp-import-policy:routingpolicy', 'internal-networks:prefixset', 'partner-networks:prefixset', 'blocked-networks:prefixset', 'communityset-regular:communityset', 'communityset-extended:communityset'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False, labels=['samples'])
169169

170170
k8s_yaml('./config/samples/cisco/nx/v1alpha1_vpcdomain.yaml')
171171
k8s_resource(new_name='vpcdomain', objects=['leaf1-vpcdomain:vpcdomain', 'leaf1-vrfvpckeepalive:vrf', 'eth1-30:interface', 'vpc-peer-link:interfaceconfig', 'eth1-31:interface','eth1-32:interface', 'po1:interface'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False, labels=['samples'])

‎api/core/v1alpha1/routingpolicy_types.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ type SetASPathReplace struct {
197197
Replacement intstr.IntOrString `json:"replacement"`
198198
}
199199

200+
// CommunityOperation defines whether communities are added to the route's existing
201+
// set (Add) or replace it (Replace).
202+
// +kubebuilder:validation:Enum=Add;Replace
203+
type CommunityOperation string
204+
205+
const (
206+
// CommunityOperationAdd appends the communities to the route's existing set.
207+
CommunityOperationAdd CommunityOperation = "Add"
208+
// CommunityOperationReplace overwrites the route's communities with the configured set.
209+
CommunityOperationReplace CommunityOperation = "Replace"
210+
)
211+
200212
// SetCommunityAction defines the action to set BGP standard communities.
201213
type SetCommunityAction struct {
202214
// Communities is the list of BGP standard communities to set.
@@ -205,6 +217,12 @@ type SetCommunityAction struct {
205217
// +required
206218
// +kubebuilder:validation:MinItems=1
207219
Communities []string `json:"communities"`
220+
221+
// Operation controls whether the communities are added to the route's existing
222+
// communities (Add) or replace them (Replace).
223+
// +optional
224+
// +kubebuilder:default=Replace
225+
Operation CommunityOperation `json:"operation,omitempty"`
208226
}
209227

210228
// SetExtCommunityAction defines the action to set BGP extended communities.
@@ -215,6 +233,12 @@ type SetExtCommunityAction struct {
215233
// +required
216234
// +kubebuilder:validation:MinItems=1
217235
Communities []string `json:"communities"`
236+
237+
// Operation controls whether the communities are added to the route's existing
238+
// communities (Add) or replace them (Replace).
239+
// +optional
240+
// +kubebuilder:default=Replace
241+
Operation CommunityOperation `json:"operation,omitempty"`
218242
}
219243

220244
// RoutingPolicyStatus defines the observed state of RoutingPolicy.

‎charts/network-operator/templates/crd/routingpolicies.networking.metal.ironcore.dev.yaml‎

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎charts/network-operator/templates/prometheus/controller-manager-metrics-monitor.yaml‎

Lines changed: 9 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎config/crd/bases/networking.metal.ironcore.dev_routingpolicies.yaml‎

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎config/samples/v1alpha1_routingpolicy.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ spec:
2323
communities:
2424
- "65137:100"
2525
- "65137:200"
26+
operation: Add
2627
setExtCommunity:
2728
communities:
2829
- "65137:100"
30+
operation: Replace
2931
- sequence: 20
3032
conditions:
3133
matchPrefixSet:

‎docs/api-reference/index.md‎

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,12 +2855,12 @@ func (p *Provider) EnsureRoutingPolicy(ctx context.Context, req *provider.Ensure
28552855

28562856
if stmt.Actions.BgpActions != nil {
28572857
if stmt.Actions.BgpActions.SetCommunity != nil {
2858-
if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities); err != nil {
2858+
if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities, stmt.Actions.BgpActions.SetCommunity.Operation); err != nil {
28592859
return err
28602860
}
28612861
}
28622862
if stmt.Actions.BgpActions.SetExtCommunity != nil {
2863-
if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities); err != nil {
2863+
if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities, stmt.Actions.BgpActions.SetExtCommunity.Operation); err != nil {
28642864
return err
28652865
}
28662866
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ type RouteMapEntry struct {
2727
Action Action `json:"action"`
2828
Order int32 `json:"order"`
2929
SrttItems struct {
30+
Additive AdminSt `json:"additive"`
3031
ItemItems struct {
3132
ItemList gnmiext.List[ExtCommItem, *ExtCommItem] `json:"Item-list,omitzero"`
3233
} `json:"item-items,omitzero"`
3334
} `json:"srtt-items,omitzero"`
3435
SregcommItems struct {
36+
Additive AdminSt `json:"additive"`
3537
NoCommAttr AdminSt `json:"noCommAttr"`
3638
ItemItems struct {
3739
ItemList gnmiext.List[string, *CommItem] `json:"Item-list,omitzero"`
@@ -73,7 +75,7 @@ type RouteMapEntry struct {
7375

7476
func (e *RouteMapEntry) Key() int32 { return e.Order }
7577

76-
func (e *RouteMapEntry) SetCommunities(communities []string) error {
78+
func (e *RouteMapEntry) SetCommunities(communities []string, operation v1alpha1.CommunityOperation) error {
7779
for _, comm := range communities {
7880
c, err := Community(comm)
7981
if err != nil {
@@ -82,17 +84,25 @@ func (e *RouteMapEntry) SetCommunities(communities []string) error {
8284
e.SregcommItems.NoCommAttr = AdminStDisabled
8385
e.SregcommItems.ItemItems.ItemList.Set(&CommItem{Community: c})
8486
}
87+
e.SregcommItems.Additive = AdminStDisabled
88+
if operation == v1alpha1.CommunityOperationAdd {
89+
e.SregcommItems.Additive = AdminStEnabled
90+
}
8591
return nil
8692
}
8793

88-
func (e *RouteMapEntry) SetExtCommunities(communities []string) error {
94+
func (e *RouteMapEntry) SetExtCommunities(communities []string, operation v1alpha1.CommunityOperation) error {
8995
for _, comm := range communities {
9096
c, err := RouteTarget(comm)
9197
if err != nil {
9298
return err
9399
}
94100
e.SrttItems.ItemItems.ItemList.Set(&ExtCommItem{Community: c, Scope: RtExtComScopeTransitive})
95101
}
102+
e.SrttItems.Additive = AdminStDisabled
103+
if operation == v1alpha1.CommunityOperationAdd {
104+
e.SrttItems.Additive = AdminStEnabled
105+
}
96106
return nil
97107
}
98108

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,28 @@ func init() {
141141
comboRM.Name = "RM-COMBINED-MATCH"
142142
comboRM.EntItems.EntryList.Set(comboEntry)
143143
Register("route_map_combined_match", comboRM)
144+
145+
commAdditiveEntry := &RouteMapEntry{}
146+
commAdditiveEntry.Order = 10
147+
commAdditiveEntry.Action = ActionPermit
148+
if err := commAdditiveEntry.SetCommunities([]string{"65000:10", "65000:20"}, v1alpha1.CommunityOperationAdd); err != nil {
149+
panic(err)
150+
}
151+
152+
commAdditiveRM := &RouteMap{}
153+
commAdditiveRM.Name = "RM-COMMUNITY-ADDITIVE"
154+
commAdditiveRM.EntItems.EntryList.Set(commAdditiveEntry)
155+
Register("route_map_community_additive", commAdditiveRM)
156+
157+
extCommAdditiveEntry := &RouteMapEntry{}
158+
extCommAdditiveEntry.Order = 10
159+
extCommAdditiveEntry.Action = ActionPermit
160+
if err := extCommAdditiveEntry.SetExtCommunities([]string{"65000:10", "65000:20"}, v1alpha1.CommunityOperationAdd); err != nil {
161+
panic(err)
162+
}
163+
164+
extCommAdditiveRM := &RouteMap{}
165+
extCommAdditiveRM.Name = "RM-EXTCOMMUNITY-ADDITIVE"
166+
extCommAdditiveRM.EntItems.EntryList.Set(extCommAdditiveEntry)
167+
Register("route_map_extcommunity_additive", extCommAdditiveRM)
144168
}

0 commit comments

Comments
 (0)