Skip to content

Commit 4f9b43f

Browse files
authored
Merge pull request #52 from kubescape/bugfix/open-limit
Adding a label of failed in case of open limit reached
2 parents 2bed7f6 + dd650e3 commit 4f9b43f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/collector/collector.go

+14
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ func (cm *CollectorManager) CollectContainerEvents(id *ContainerId) {
435435
if containerState.attached {
436436
appProfile.ObjectMeta.Labels = map[string]string{"kapprofiler.kubescape.io/partial": "true"}
437437
}
438+
// Check if we have over the limit of open events, if so, mark as failed.
439+
if len(containerProfile.Opens) >= MaxOpenEvents {
440+
appProfile.ObjectMeta.Labels = map[string]string{"kapprofiler.kubescape.io/failed": "true"}
441+
}
438442
appProfileRawNew, err := runtime.DefaultUnstructuredConverter.ToUnstructured(appProfile)
439443
if err != nil {
440444
log.Printf("error converting application profile: %s\n", err)
@@ -467,6 +471,16 @@ func (cm *CollectorManager) CollectContainerEvents(id *ContainerId) {
467471
return
468472
}
469473

474+
// Check if we have over the limit of open events, if so, mark as failed.
475+
if len(containerProfile.Opens) >= MaxOpenEvents {
476+
// Mark as failed
477+
_, err = cm.dynamicClient.Resource(AppProfileGvr).Namespace(id.Namespace).Patch(context.Background(),
478+
appProfileName, apitypes.MergePatchType, []byte("{\"metadata\":{\"labels\":{\"kapprofiler.kubescape.io/failed\":\"true\"}}}"), v1.PatchOptions{})
479+
if err != nil {
480+
log.Printf("error patching application profile: %s\n", err)
481+
}
482+
}
483+
470484
// Add the container profile into the application profile. If the container profile already exists, it will be merged.
471485
existingApplicationProfileObject := &ApplicationProfile{}
472486
err = runtime.DefaultUnstructuredConverter.FromUnstructured(existingApplicationProfile.Object, existingApplicationProfileObject)

0 commit comments

Comments
 (0)