@@ -168,12 +168,17 @@ func (r *ClTcProgramReconciler) updateLinks(ctx context.Context, isBeingDeleted
168168
169169 if r .currentProgram .TC != nil && r .currentProgram .TC .Links != nil {
170170 for _ , attachInfo := range r .currentProgram .TC .Links {
171- expectedLinks , error := r .getExpectedLinks (ctx , attachInfo )
172- if error != nil {
173- return fmt .Errorf ("failed to get node links: %v" , error )
171+ expectedLinks , err := r .getExpectedLinks (ctx , attachInfo )
172+ if err != nil {
173+ r .Logger .V (1 ).Info ("updateLinks() failed" , "error" , err )
174+ return fmt .Errorf ("failed to get node links: %v" , err )
174175 }
175176 for _ , link := range expectedLinks {
176- index := r .findLink (link )
177+ index , err := r .findLink (link )
178+ if err != nil {
179+ r .Logger .Info ("Error" , "Invalid link" , r .printAttachInfo (link ), "Error" , err )
180+ continue
181+ }
177182 if index != nil {
178183 // Link already exists, so set ShouldAttach to true.
179184 r .currentProgramState .TC .Links [* index ].AttachInfoStateCommon .ShouldAttach = true
@@ -194,18 +199,36 @@ func (r *ClTcProgramReconciler) updateLinks(ctx context.Context, isBeingDeleted
194199 return nil
195200}
196201
197- func (r * ClTcProgramReconciler ) findLink (attachInfoState bpfmaniov1alpha1.ClTcAttachInfoState ) * int {
202+ func (r * ClTcProgramReconciler ) printAttachInfo (attachInfoState bpfmaniov1alpha1.ClTcAttachInfoState ) string {
203+ var netnsPath string
204+ if attachInfoState .NetnsPath == "" {
205+ netnsPath = "host"
206+ } else {
207+ netnsPath = attachInfoState .NetnsPath
208+ }
209+
210+ return fmt .Sprintf ("interfaceName: %s, netnsPath: %s, direction: %s, priority: %d" ,
211+ attachInfoState .InterfaceName , netnsPath , attachInfoState .Direction , attachInfoState .Priority )
212+ }
213+
214+ func (r * ClTcProgramReconciler ) findLink (attachInfoState bpfmaniov1alpha1.ClTcAttachInfoState ) (* int , error ) {
215+ newNetnsId := r .getNetnsId (attachInfoState .NetnsPath )
216+ if newNetnsId == nil {
217+ return nil , fmt .Errorf ("failed to get netnsId for path %s" , attachInfoState .NetnsPath )
218+ }
219+ r .Logger .V (1 ).Info ("findlink" , "New Path" , attachInfoState .NetnsPath , "NetnsId" , newNetnsId )
198220 for i , a := range r .currentProgramState .TC .Links {
199221 // attachInfoState is the same as a if the the following fields are the
200- // same: InterfaceName, Direction, Priority, NetnsPath, and ProceedOn.
201- if a .InterfaceName == attachInfoState .InterfaceName && a .Direction == attachInfoState .Direction &&
222+ // same: InterfaceName, Direction, Priority, ProceedOn, and network namespace.
223+ if a .InterfaceName == attachInfoState .InterfaceName &&
224+ a .Direction == attachInfoState .Direction &&
202225 a .Priority == attachInfoState .Priority &&
203- reflect .DeepEqual (a .NetnsPath , attachInfoState .NetnsPath ) &&
204- reflect .DeepEqual (a . ProceedOn , attachInfoState . ProceedOn ) {
205- return & i
226+ reflect .DeepEqual (a .ProceedOn , attachInfoState .ProceedOn ) &&
227+ reflect .DeepEqual (r . getNetnsId ( a . NetnsPath ), newNetnsId ) {
228+ return & i , nil
206229 }
207230 }
208- return nil
231+ return nil , nil
209232}
210233
211234// processLinks calls reconcileBpfLink() for each link. It
@@ -291,22 +314,24 @@ func (r *ClTcProgramReconciler) getExpectedLinks(ctx context.Context, attachInfo
291314
292315 // Handle interface discovery
293316 if isInterfacesDiscoveryEnabled (& attachInfo .InterfaceSelector ) {
294- discoveredInterfaces , err := getDiscoveredInterfaces (& attachInfo .InterfaceSelector , r .Interfaces )
295- if err != nil {
296- return nil , fmt .Errorf ("failed to discover interfaces: %w" , err )
297- }
317+ discoveredInterfaces := getDiscoveredInterfaces (& attachInfo .InterfaceSelector , r .Interfaces )
318+ r .Logger .Info ("getExpectedLinks" , "num discoveredInterfaces" , len (discoveredInterfaces ))
298319 for _ , intf := range discoveredInterfaces {
299320 nodeLinks = append (nodeLinks , createLinkEntry (intf .interfaceName , intf .netNSPath ))
300321 }
322+ r .Logger .V (1 ).Info ("getExpectedLinks-discovery" , "Links created" , len (nodeLinks ))
301323 return nodeLinks , nil
302324 }
303325
304326 // Fetch interfaces if discovery is disabled
305327 interfaces , err := getInterfaces (& attachInfo .InterfaceSelector , r .ourNode )
306328 if err != nil {
329+ r .Logger .V (1 ).Info ("getExpectedLinks failed to get interfaces" , "error" , err )
307330 return nil , fmt .Errorf ("failed to get interfaces for XdpProgram: %w" , err )
308331 }
309332
333+ r .Logger .Info ("getExpectedLinks" , "Number of interfaces" , len (interfaces ))
334+
310335 // Handle network namespaces if provided
311336 if attachInfo .NetworkNamespaces != nil {
312337 containerInfo , err := r .Containers .GetContainers (
@@ -317,6 +342,7 @@ func (r *ClTcProgramReconciler) getExpectedLinks(ctx context.Context, attachInfo
317342 r .Logger ,
318343 )
319344 if err != nil {
345+ r .Logger .V (1 ).Info ("getExpectedLinks failed to get container pids" , "error" , err )
320346 return nil , fmt .Errorf ("failed to get container pids: %w" , err )
321347 }
322348
@@ -332,6 +358,7 @@ func (r *ClTcProgramReconciler) getExpectedLinks(ctx context.Context, attachInfo
332358 nodeLinks = append (nodeLinks , createLinkEntry (iface , netnsPath ))
333359 }
334360 }
361+ r .Logger .V (1 ).Info ("getExpectedLinks" , "Links created" , len (nodeLinks ))
335362 return nodeLinks , nil
336363 }
337364
@@ -340,6 +367,7 @@ func (r *ClTcProgramReconciler) getExpectedLinks(ctx context.Context, attachInfo
340367 nodeLinks = append (nodeLinks , createLinkEntry (iface , "" ))
341368 }
342369
370+ r .Logger .V (1 ).Info ("getExpectedLinks" , "Links created" , len (nodeLinks ))
343371 return nodeLinks , nil
344372}
345373
0 commit comments