Skip to content

Commit

Permalink
fix application profile and NN patching (#335)
Browse files Browse the repository at this point in the history
Signed-off-by: Amir Malka <amirm@armosec.io>
  • Loading branch information
amirmalka authored Aug 6, 2024
1 parent e5ce394 commit 3274822
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,18 @@ func (am *ApplicationProfileManager) monitorContainer(ctx context.Context, conta
}

am.saveProfile(ctx, watchedContainer, container.K8s.Namespace)
return nil
return err
case errors.Is(err, utils.ContainerReachedMaxTime):
watchedContainer.SetStatus(utils.WatchedContainerStatusCompleted)
am.saveProfile(ctx, watchedContainer, container.K8s.Namespace)
return nil
return err
case errors.Is(err, utils.ObjectCompleted):
watchedContainer.SetStatus(utils.WatchedContainerStatusCompleted)
return nil
return err
case errors.Is(err, utils.TooLargeObjectError):
logger.L().Debug("ApplicationProfileManager - object is too large")
watchedContainer.SetStatus(utils.WatchedContainerStatusTooLarge)
return nil
return err
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/networkmanager/v2/network_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,17 @@ func (nm *NetworkManager) monitorContainer(ctx context.Context, container *conta
watchedContainer.SetStatus(utils.WatchedContainerStatusCompleted)
}
nm.saveNetworkEvents(ctx, watchedContainer, container.K8s.Namespace)
return nil
return err
case errors.Is(err, utils.ContainerReachedMaxTime):
watchedContainer.SetStatus(utils.WatchedContainerStatusCompleted)
nm.saveNetworkEvents(ctx, watchedContainer, container.K8s.Namespace)
return nil
return err
case errors.Is(err, utils.ObjectCompleted):
watchedContainer.SetStatus(utils.WatchedContainerStatusCompleted)
return nil
return err
case errors.Is(err, utils.TooLargeObjectError):
watchedContainer.SetStatus(utils.WatchedContainerStatusTooLarge)
return nil
return err
}
}
}
Expand Down
21 changes: 10 additions & 11 deletions pkg/storage/v1/applicationprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,25 @@ func (sc Storage) patchApplicationProfile(name, namespace string, operations []u
if err != nil {
return fmt.Errorf("patch application profile: %w", err)
}

// check if returned profile is full
if s, ok := profile.Annotations[helpers.StatusMetadataKey]; ok {
if s == helpers.TooLarge {
if channel != nil {
channel <- utils.TooLargeObjectError
}
if status, ok := profile.Annotations[helpers.StatusMetadataKey]; ok && status == helpers.TooLarge {
if channel != nil {
channel <- utils.TooLargeObjectError
}
return nil
}

// check if returned profile is completed
if c, ok := profile.Annotations[helpers.CompletionMetadataKey]; ok {
if s, ok := profile.Annotations[helpers.StatusMetadataKey]; ok {
if s == helpers.Complete && c == helpers.Completed {
if channel != nil {
channel <- utils.ObjectCompleted
}
if s, ok := profile.Annotations[helpers.StatusMetadataKey]; ok && s == helpers.Complete && c == helpers.Completed {
if channel != nil {
channel <- utils.ObjectCompleted
}
return nil
}
return nil
}

// check if returned profile is too big
if s, ok := profile.Annotations[helpers.ResourceSizeMetadataKey]; ok {
size, err := strconv.Atoi(s)
Expand Down
19 changes: 8 additions & 11 deletions pkg/storage/v1/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,22 @@ func (sc Storage) patchNetworkNeighborhood(name, namespace string, operations []
return fmt.Errorf("patch application neighborhood: %w", err)
}
// check if returned neighborhood is full
if s, ok := neighborhood.Annotations[helpers.StatusMetadataKey]; ok {
if s == helpers.TooLarge {
if channel != nil {
channel <- utils.TooLargeObjectError
}
if status, ok := neighborhood.Annotations[helpers.StatusMetadataKey]; ok && status == helpers.TooLarge {
if channel != nil {
channel <- utils.TooLargeObjectError
}
return nil
}
// check if returned profile is completed
if c, ok := neighborhood.Annotations[helpers.CompletionMetadataKey]; ok {
if s, ok := neighborhood.Annotations[helpers.StatusMetadataKey]; ok {
if s == helpers.Complete && c == helpers.Completed {
if channel != nil {
channel <- utils.ObjectCompleted
}
if s, ok := neighborhood.Annotations[helpers.StatusMetadataKey]; ok && s == helpers.Complete && c == helpers.Completed {
if channel != nil {
channel <- utils.ObjectCompleted
}
return nil
}
return nil
}

// check if returned neighborhood is too big
if s, ok := neighborhood.Annotations[helpers.ResourceSizeMetadataKey]; ok {
size, err := strconv.Atoi(s)
Expand Down
2 changes: 2 additions & 0 deletions pkg/storage/v1/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ func CreateStorage(namespace string) (*Storage, error) {
if err != nil {
maxApplicationProfileSize = DefaultMaxApplicationProfileSize
}
logger.L().Debug("maxApplicationProfileSize", helpers.Int("size", maxApplicationProfileSize))

maxNetworkNeighborhoodSize, err := strconv.Atoi(os.Getenv("MAX_NETWORK_NEIGHBORHOOD_SIZE"))
if err != nil {
maxNetworkNeighborhoodSize = DefaultMaxNetworkNeighborhoodSize
}
logger.L().Debug("maxNetworkNeighborhoodSize", helpers.Int("size", maxNetworkNeighborhoodSize))

// wait for storage to be ready
if err := backoff.RetryNotify(func() error {
Expand Down

0 comments on commit 3274822

Please sign in to comment.