@@ -168,12 +168,17 @@ func (r *ClTcProgramReconciler) updateLinks(ctx context.Context, isBeingDeleted
168
168
169
169
if r .currentProgram .TC != nil && r .currentProgram .TC .Links != nil {
170
170
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 )
174
175
}
175
176
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
+ }
177
182
if index != nil {
178
183
// Link already exists, so set ShouldAttach to true.
179
184
r .currentProgramState .TC .Links [* index ].AttachInfoStateCommon .ShouldAttach = true
@@ -194,18 +199,36 @@ func (r *ClTcProgramReconciler) updateLinks(ctx context.Context, isBeingDeleted
194
199
return nil
195
200
}
196
201
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 )
198
220
for i , a := range r .currentProgramState .TC .Links {
199
221
// 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 &&
202
225
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
206
229
}
207
230
}
208
- return nil
231
+ return nil , nil
209
232
}
210
233
211
234
// processLinks calls reconcileBpfLink() for each link. It
@@ -291,22 +314,24 @@ func (r *ClTcProgramReconciler) getExpectedLinks(ctx context.Context, attachInfo
291
314
292
315
// Handle interface discovery
293
316
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 ))
298
319
for _ , intf := range discoveredInterfaces {
299
320
nodeLinks = append (nodeLinks , createLinkEntry (intf .interfaceName , intf .netNSPath ))
300
321
}
322
+ r .Logger .V (1 ).Info ("getExpectedLinks-discovery" , "Links created" , len (nodeLinks ))
301
323
return nodeLinks , nil
302
324
}
303
325
304
326
// Fetch interfaces if discovery is disabled
305
327
interfaces , err := getInterfaces (& attachInfo .InterfaceSelector , r .ourNode )
306
328
if err != nil {
329
+ r .Logger .V (1 ).Info ("getExpectedLinks failed to get interfaces" , "error" , err )
307
330
return nil , fmt .Errorf ("failed to get interfaces for XdpProgram: %w" , err )
308
331
}
309
332
333
+ r .Logger .Info ("getExpectedLinks" , "Number of interfaces" , len (interfaces ))
334
+
310
335
// Handle network namespaces if provided
311
336
if attachInfo .NetworkNamespaces != nil {
312
337
containerInfo , err := r .Containers .GetContainers (
@@ -317,6 +342,7 @@ func (r *ClTcProgramReconciler) getExpectedLinks(ctx context.Context, attachInfo
317
342
r .Logger ,
318
343
)
319
344
if err != nil {
345
+ r .Logger .V (1 ).Info ("getExpectedLinks failed to get container pids" , "error" , err )
320
346
return nil , fmt .Errorf ("failed to get container pids: %w" , err )
321
347
}
322
348
@@ -332,6 +358,7 @@ func (r *ClTcProgramReconciler) getExpectedLinks(ctx context.Context, attachInfo
332
358
nodeLinks = append (nodeLinks , createLinkEntry (iface , netnsPath ))
333
359
}
334
360
}
361
+ r .Logger .V (1 ).Info ("getExpectedLinks" , "Links created" , len (nodeLinks ))
335
362
return nodeLinks , nil
336
363
}
337
364
@@ -340,6 +367,7 @@ func (r *ClTcProgramReconciler) getExpectedLinks(ctx context.Context, attachInfo
340
367
nodeLinks = append (nodeLinks , createLinkEntry (iface , "" ))
341
368
}
342
369
370
+ r .Logger .V (1 ).Info ("getExpectedLinks" , "Links created" , len (nodeLinks ))
343
371
return nodeLinks , nil
344
372
}
345
373
0 commit comments