Skip to content

Commit

Permalink
Persist the object into the backend storage if RPC resource is exhausted
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny-Wei committed Feb 8, 2025
1 parent da05d02 commit 1c94b0c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/apm/apm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"strings"

"github.com/go-logr/logr"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
k8errors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"
Expand Down Expand Up @@ -121,12 +123,16 @@ func PersistArmorProfileModel(varmorInterface varmorinterface.CrdV1beta1Interfac
return apm, nil
}

if !k8errors.IsRequestEntityTooLargeError(err) {
isResourceExhausted := false
s, ok := status.FromError(err)
if ok && s.Code() == codes.ResourceExhausted {
isResourceExhausted = true
}
if !k8errors.IsRequestEntityTooLargeError(err) && !isResourceExhausted {
return apm, err
}
}

// The limit of object is 3145728.
// Persist the object into the backend storage
fileName := path.Join(varmorconfig.BehaviorDataDirectory, apm.Name)
logger.Info("Persist the data into a local file because the data is too large to store into an ArmorProfileModel object",
Expand Down

0 comments on commit 1c94b0c

Please sign in to comment.