Skip to content

Commit

Permalink
chore: Possible fix for size/RSS issue
Browse files Browse the repository at this point in the history
Using scheme package increases the binary size because it includes
additional code and dependencies related to Kubernetes. It also
increases the RSS memory.

Because we don't need the entire scheme package, only
apimachinery/runtime package was used to create a new scheme.

commit: 3b5175d (main), cherry-pick
  • Loading branch information
rscampos committed Jun 19, 2024
1 parent 5e2938c commit 2d8d4a3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ require (
k8s.io/apimachinery v0.28.3
k8s.io/client-go v0.28.3
k8s.io/cri-api v0.29.0
k8s.io/kubectl v0.27.7
kernel.org/pub/linux/libs/security/libcap/cap v1.2.68
sigs.k8s.io/controller-runtime v0.16.3
)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,6 @@ k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ=
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM=
k8s.io/kubectl v0.27.7 h1:HTEDa4s/oWjB3t5ysdW1yKlcNl9bzigcqWBq0LIIe3k=
k8s.io/kubectl v0.27.7/go.mod h1:Xb1Ubc8uN1i2RvSN1HCgSHTtzgX0woihMk/gW7XbjJU=
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrCM8P2RJ0yroCyIk=
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
kernel.org/pub/linux/libs/security/libcap/cap v1.2.68 h1:137hV1K92dqIjdd46hSJbiKodzfo3pju8uiG6zj1qHY=
Expand Down
7 changes: 4 additions & 3 deletions pkg/k8s/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package k8s
import (
"context"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/rest"
"k8s.io/kubectl/pkg/scheme"

"github.com/aquasecurity/tracee/pkg/k8s/apis/tracee.aquasec.com/v1beta1"
)
Expand All @@ -20,15 +20,16 @@ func New() (*Client, error) {
return nil, err
}

err = v1beta1.AddToScheme(scheme.Scheme)
scheme := runtime.NewScheme()
err = v1beta1.AddToScheme(scheme)
if err != nil {
return nil, err
}

crdConfig := *config
crdConfig.ContentConfig.GroupVersion = &v1beta1.GroupVersion
crdConfig.APIPath = "/apis"
crdConfig.NegotiatedSerializer = serializer.NewCodecFactory(scheme.Scheme)
crdConfig.NegotiatedSerializer = serializer.NewCodecFactory(scheme)
crdConfig.UserAgent = rest.DefaultKubernetesUserAgent()

client, err := rest.UnversionedRESTClientFor(&crdConfig)
Expand Down

0 comments on commit 2d8d4a3

Please sign in to comment.