@@ -23,20 +23,20 @@ import (
2323
2424 bgpapi "github.com/osrg/gobgp/v3/api"
2525 "github.com/pkg/errors"
26- "github.com/projectcalico/calico/libcalico-go/lib/backend/model"
2726 "github.com/sirupsen/logrus"
2827 "golang.org/x/net/context"
2928
29+ calicov3cli "github.com/projectcalico/calico/libcalico-go/lib/clientv3"
30+ "github.com/projectcalico/calico/libcalico-go/lib/options"
31+ "gopkg.in/tomb.v2"
32+
3033 "github.com/projectcalico/vpp-dataplane/v3/calico-vpp-agent/common"
3134 "github.com/projectcalico/vpp-dataplane/v3/config"
32-
33- calicocli "github.com/projectcalico/calico/libcalico-go/lib/client"
34- "gopkg.in/tomb.v2"
3535)
3636
3737type PrefixWatcher struct {
3838 log * logrus.Entry
39- client * calicocli. Client
39+ clientv3 calicov3cli. Interface
4040 nodeBGPSpec * common.LocalNodeSpec
4141}
4242
@@ -108,36 +108,34 @@ func (w *PrefixWatcher) WatchPrefix(t *tomb.Tomb) error {
108108 return nil
109109}
110110
111- // getAssignedPrefixes retrives prefixes assigned to the node and returns them as a
112- // list of BGP path.
113- // using backend directly since libcalico-go doesn't seem to have a method to return
114- // assigned prefixes yet.
111+ // getAssignedPrefixes retrieves prefixes assigned to the node and returns them as a
112+ // list of strings.
113+ // using v3 client BlockAffinities interface to fetch block affinities for this host.
115114func (w * PrefixWatcher ) getAssignedPrefixes () ([]string , error ) {
116115 var ps []string
117116
118117 f := func (ipVersion int ) error {
119- blockList , err := w .client .Backend .List (
118+ // List block affinities for this host
119+ blockAffinities , err := w .clientv3 .BlockAffinities ().List (
120120 context .Background (),
121- model.BlockAffinityListOptions {Host : * config .NodeName , IPVersion : ipVersion },
122- "" ,
121+ options.ListOptions {},
123122 )
124123 if err != nil {
125124 return err
126125 }
127- for _ , block := range blockList .KVPairs {
128- w .log .Debugf ("Found assigned prefix: %+v" , block )
129- key , ok := block .Key .(model.BlockAffinityKey )
130- if ! ok {
131- w .log .Errorf ("block.Key is not a model.BlockAffinity %v" , block .Key )
132- continue
133- }
134- value , ok := block .Value .(* model.BlockAffinity )
135- if ! ok {
136- w .log .Errorf ("block.Value is not a model.BlockAffinity %v" , block .Value )
137- continue
138- }
139- if value .State == model .StateConfirmed && ! value .Deleted {
140- ps = append (ps , key .CIDR .String ())
126+
127+ for _ , blockAffinity := range blockAffinities .Items {
128+ w .log .Debugf ("Found assigned prefix: %+v" , blockAffinity )
129+ // Check if this block affinity is for our node and the correct IP version
130+ if blockAffinity .Spec .Node == * config .NodeName &&
131+ blockAffinity .Spec .State == "confirmed" &&
132+ blockAffinity .Spec .Deleted != "true" {
133+ // Check IP version of the CIDR
134+ cidr := blockAffinity .Spec .CIDR
135+ if (ipVersion == 4 && ! strings .Contains (cidr , ":" )) ||
136+ (ipVersion == 6 && strings .Contains (cidr , ":" )) {
137+ ps = append (ps , cidr )
138+ }
141139 }
142140 }
143141 return nil
@@ -260,10 +258,10 @@ func (w *PrefixWatcher) SetOurBGPSpec(nodeBGPSpec *common.LocalNodeSpec) {
260258 w .nodeBGPSpec = nodeBGPSpec
261259}
262260
263- func NewPrefixWatcher (client * calicocli. Client , log * logrus.Entry ) * PrefixWatcher {
261+ func NewPrefixWatcher (clientv3 calicov3cli. Interface , log * logrus.Entry ) * PrefixWatcher {
264262 w := PrefixWatcher {
265- client : client ,
266- log : log ,
263+ clientv3 : clientv3 ,
264+ log : log ,
267265 }
268266 return & w
269267}
0 commit comments