From e34270c51e6cdcd9306f2d3f71e0d05d24eb8108 Mon Sep 17 00:00:00 2001 From: Michael Beaver Date: Tue, 8 Jan 2019 13:32:11 -0600 Subject: [PATCH] Basic support for BGP communities in calico This creates a new section in calico/values.yaml that enables BGP communities to be applied to a cidr by using the bird_ipam templates. Change-Id: I4dbbc8d8e761e0484eeb7c8bf0fefa28d29493e5 --- .../bird/_bird6_ipam.cfg.template.tpl | 16 ++++++++++ .../bird/_bird_ipam.cfg.template.tpl | 16 ++++++++++ calico/values.yaml | 30 +++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/calico/templates/bird/_bird6_ipam.cfg.template.tpl b/calico/templates/bird/_bird6_ipam.cfg.template.tpl index fadf1eb5a5..a73a16acc6 100644 --- a/calico/templates/bird/_bird6_ipam.cfg.template.tpl +++ b/calico/templates/bird/_bird6_ipam.cfg.template.tpl @@ -8,7 +8,23 @@ function osh_filters () {{- end }} } +function apply_communities () +{ + # Set community value based on dictionary of cidrs +{{- $asnum := .Values.networking.bgp.asnumber }} +{{- range .Values.networking.bgp.ipv6.community_cidr_ref }} + {{- $community := .community }} + {{- $cidr := .cidr }} + {{- with .prefix }} + if ( net ~ {{ $cidr }} ) then { bgp_community.add(({{ . }}, {{ $community }})); } + {{- else }} + if ( net ~ {{ $cidr }} ) then { bgp_community.add(({{ $asnum }}, {{ $community }})); } + {{- end }} +{{- end }} +} + filter calico_pools { + apply_communities(); calico_aggr(); osh_filters(); {{`{{range ls "/pool"}}{{$data := json (getv (printf "/pool/%s" .))}}`}} diff --git a/calico/templates/bird/_bird_ipam.cfg.template.tpl b/calico/templates/bird/_bird_ipam.cfg.template.tpl index da74389090..2900856950 100644 --- a/calico/templates/bird/_bird_ipam.cfg.template.tpl +++ b/calico/templates/bird/_bird_ipam.cfg.template.tpl @@ -8,7 +8,23 @@ function osh_filters () {{- end }} } +function apply_communities () +{ + # Set community value based on dictionary of cidrs +{{- $asnum := .Values.networking.bgp.asnumber }} +{{- range .Values.networking.bgp.ipv4.community_cidr_ref }} + {{- $community := .community }} + {{- $cidr := .cidr }} + {{- with .prefix }} + if ( net ~ {{ $cidr }} ) then { bgp_community.add(({{ . }}, {{ $community }})); } + {{- else }} + if ( net ~ {{ $cidr }} ) then { bgp_community.add(({{ $asnum }}, {{ $community }})); } + {{- end }} +{{- end }} +} + filter calico_pools { + apply_communities(); calico_aggr(); osh_filters(); {{`{{range ls "/v1/ipam/v4/pool"}}{{$data := json (getv (printf "/v1/ipam/v4/pool/%s" .))}}`}} diff --git a/calico/values.yaml b/calico/values.yaml index b73e58820d..a46f751034 100644 --- a/calico/values.yaml +++ b/calico/values.yaml @@ -224,6 +224,21 @@ networking: # IPs within them on a host, we will announce the address in # addition to traditional pod workloads additional_cidrs: [] + # community_cidr_ref contains embedded objects that describe a + # BGP community that is to be associated with the supplied CIDR. + # The top-level key names are not important. + # + # The resulting BGP community will take the form of + # : + # If no prefix is specified then the asnumber is used + community_cidr_ref: +# cidr_community_description: +# cidr: 192.168.0.0/16 +# community: 54321 +# prefix: 55555 +# alpha: +# cidr: 10.0.0.0/16 +# community: 54322 port: neighbor: 179 listen: 179 @@ -247,6 +262,21 @@ networking: # IPs within them on a host, we will announce them in addition # to traditional pod workloads additional_cidrs: [] + # community_cidr_ref contains embedded objects that describe a + # BGP community that is to be associated with the supplied CIDR. + # The top-level key names are not important. + # + # The resulting BGP community will take the form of + # : + # If no prefix is specified then the asnumber is used + community_cidr_ref: +# cidr_community_description: +# cidr: 2600:1:2:3::abcd/28 +# community: 54321 +# prefix: 55555 +# alpha: +# cidr: 1400:a:2:3::abcd/26 +# community: 54322 port: neighbor: 179 listen: 179