@@ -234,32 +234,32 @@ func (c *Controller) handleApplicationProfile(applicationProfileUnstructured *un
234
234
containersMap := make (map [string ]collector.ContainerProfile )
235
235
236
236
// Merge all the container information of all the pods
237
- for _ , pod := range pods .Items {
238
- appProfileNameForPod := fmt .Sprintf ("pod-%s" , pod .GetName ())
239
- typedObj , err := c .dynamicClient .Resource (collector .AppProfileGvr ).Namespace (pod .GetNamespace ()).Get (context .TODO (), appProfileNameForPod , metav1.GetOptions {})
237
+ for i := 0 ; i < len ( pods .Items ); i ++ {
238
+ appProfileNameForPod := fmt .Sprintf ("pod-%s" , pods . Items [ i ] .GetName ())
239
+ typedObj , err := c .dynamicClient .Resource (collector .AppProfileGvr ).Namespace (pods . Items [ i ] .GetNamespace ()).Get (context .TODO (), appProfileNameForPod , metav1.GetOptions {})
240
240
if err != nil {
241
- log .Printf ("ApplicationProfile for pod %v doesn't exist" , pod .GetName ())
241
+ log .Printf ("ApplicationProfile for pod %v doesn't exist" , pods . Items [ i ] .GetName ())
242
242
return
243
243
}
244
244
podApplicationProfileObj , err := getApplicationProfileFromUnstructured (typedObj )
245
245
if err != nil {
246
- log .Printf ("ApplicationProfile for pod %v doesn't exist" , pod .GetName ())
246
+ log .Printf ("ApplicationProfile for pod %v doesn't exist" , pods . Items [ i ] .GetName ())
247
247
return
248
248
}
249
249
250
250
// TODO: Make this code more efficient and less repetitive.
251
- for _ , container := range podApplicationProfileObj .Spec .Containers {
251
+ for containerIndex := 0 ; containerIndex < len ( podApplicationProfileObj .Spec .Containers ); containerIndex ++ {
252
252
// Merge containers
253
- if mapContainer , exists := containersMap [container .Name ]; exists {
253
+ if mapContainer , exists := containersMap [podApplicationProfileObj . Spec . Containers [ containerIndex ] .Name ]; exists {
254
254
// Merge SysCalls
255
- for _ , sysCall := range container .SysCalls {
255
+ for _ , sysCall := range podApplicationProfileObj . Spec . Containers [ containerIndex ] .SysCalls {
256
256
if ! slices .Contains (mapContainer .SysCalls , sysCall ) {
257
257
mapContainer .SysCalls = append (mapContainer .SysCalls , sysCall )
258
258
}
259
259
}
260
260
261
261
// Merge Execs
262
- for _ , exec := range container .Execs {
262
+ for _ , exec := range podApplicationProfileObj . Spec . Containers [ containerIndex ] .Execs {
263
263
contains := false
264
264
for _ , mapExec := range mapContainer .Execs {
265
265
if mapExec .Equals (exec ) {
@@ -273,7 +273,7 @@ func (c *Controller) handleApplicationProfile(applicationProfileUnstructured *un
273
273
}
274
274
275
275
// Merge Capabilities
276
- for _ , capability := range container .Capabilities {
276
+ for _ , capability := range podApplicationProfileObj . Spec . Containers [ containerIndex ] .Capabilities {
277
277
contains := false
278
278
for _ , mapCapability := range mapContainer .Capabilities {
279
279
if mapCapability .Equals (capability ) {
@@ -287,7 +287,7 @@ func (c *Controller) handleApplicationProfile(applicationProfileUnstructured *un
287
287
}
288
288
289
289
// Merge Opens
290
- for _ , open := range container .Opens {
290
+ for _ , open := range podApplicationProfileObj . Spec . Containers [ containerIndex ] .Opens {
291
291
contains := false
292
292
for _ , mapOpen := range mapContainer .Opens {
293
293
if mapOpen .Equals (open ) {
@@ -301,7 +301,7 @@ func (c *Controller) handleApplicationProfile(applicationProfileUnstructured *un
301
301
}
302
302
303
303
// Merge Dns
304
- for _ , dns := range container .Dns {
304
+ for _ , dns := range podApplicationProfileObj . Spec . Containers [ containerIndex ] .Dns {
305
305
contains := false
306
306
for _ , mapDns := range mapContainer .Dns {
307
307
if mapDns .Equals (dns ) {
@@ -315,7 +315,7 @@ func (c *Controller) handleApplicationProfile(applicationProfileUnstructured *un
315
315
}
316
316
317
317
// Merge Network
318
- for _ , network := range container .NetworkActivity .Incoming {
318
+ for _ , network := range podApplicationProfileObj . Spec . Containers [ containerIndex ] .NetworkActivity .Incoming {
319
319
contains := false
320
320
for _ , mapNetwork := range mapContainer .NetworkActivity .Incoming {
321
321
if mapNetwork .Equals (network ) {
@@ -328,7 +328,7 @@ func (c *Controller) handleApplicationProfile(applicationProfileUnstructured *un
328
328
}
329
329
}
330
330
331
- for _ , network := range container .NetworkActivity .Outgoing {
331
+ for _ , network := range podApplicationProfileObj . Spec . Containers [ containerIndex ] .NetworkActivity .Outgoing {
332
332
contains := false
333
333
for _ , mapNetwork := range mapContainer .NetworkActivity .Outgoing {
334
334
if mapNetwork .Equals (network ) {
@@ -341,9 +341,9 @@ func (c *Controller) handleApplicationProfile(applicationProfileUnstructured *un
341
341
}
342
342
}
343
343
344
- containersMap [container .Name ] = mapContainer
344
+ containersMap [podApplicationProfileObj . Spec . Containers [ containerIndex ] .Name ] = mapContainer
345
345
} else {
346
- containersMap [container . Name ] = container
346
+ containersMap [podApplicationProfileObj . Spec . Containers [ containerIndex ]. Name ] = podApplicationProfileObj . Spec . Containers [ containerIndex ]
347
347
}
348
348
}
349
349
}
0 commit comments