Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions internal/controller/ebpf/agent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const (
envKafkaSASLIDPath = "KAFKA_SASL_CLIENT_ID_PATH"
envKafkaSASLSecretPath = "KAFKA_SASL_CLIENT_SECRET_PATH"
envLogLevel = "LOG_LEVEL"
envGoMemLimit = "GOMEMLIMIT"
envEnablePktDrop = "ENABLE_PKT_DROPS"
envEnableDNSTracking = "ENABLE_DNS_TRACKING"
envEnableFlowRTT = "ENABLE_RTT"
Expand Down Expand Up @@ -730,16 +729,8 @@ func getEnvConfig(coll *flowslatest.FlowCollector, cinfo *cluster.Info) []corev1
})
}

// set GOMEMLIMIT which allows specifying a soft memory cap to force GC when resource limit is reached
// to prevent OOM
if coll.Spec.Agent.EBPF.Resources.Limits.Memory() != nil {
if memLimit, ok := coll.Spec.Agent.EBPF.Resources.Limits.Memory().AsInt64(); ok {
// we will set the GOMEMLIMIT to current memlimit - 10% as a headroom to account for
// memory sources the Go runtime is unaware of
memLimit -= int64(float64(memLimit) * 0.1)
config = append(config, corev1.EnvVar{Name: envGoMemLimit, Value: fmt.Sprint(memLimit)})
}
}
// set GOMEMLIMIT which allows specifying a soft memory cap to force GC when resource limit is reached to prevent OOM
config = helper.EnvFromReqsLimits(config, &coll.Spec.Agent.EBPF.Resources)

if coll.Spec.Agent.EBPF.IsPktDropEnabled() {
config = append(config, corev1.EnvVar{
Expand Down
8 changes: 5 additions & 3 deletions internal/controller/ebpf/agent_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
)
Expand Down Expand Up @@ -98,7 +99,6 @@ func TestGetEnvConfig_Default(t *testing.T) {

env := getEnvConfig(&fc, &cluster.Info{})
assert.Equal(t, []corev1.EnvVar{
{Name: "GOMEMLIMIT", Value: "0"},
{Name: "METRICS_ENABLE", Value: "true"},
{Name: "METRICS_SERVER_PORT", Value: "9400"},
{Name: "METRICS_PREFIX", Value: "netobserv_agent_"},
Expand Down Expand Up @@ -129,6 +129,9 @@ func TestGetEnvConfig_WithOverrides(t *testing.T) {
"TC_ATTACH_MODE": "any",
},
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("800Mi")},
},
Metrics: flowslatest.EBPFMetrics{
Enable: ptr.To(false),
},
Expand All @@ -148,7 +151,7 @@ func TestGetEnvConfig_WithOverrides(t *testing.T) {

env := getEnvConfig(&fc, &cluster.Info{})
assert.Equal(t, []corev1.EnvVar{
{Name: "GOMEMLIMIT", Value: "0"},
{Name: "GOMEMLIMIT", Value: "754974720"},
{Name: "FLOW_FILTER_RULES", Value: `[{"ip_cidr":"0.0.0.0/0","action":"Accept"}]`},
{Name: "AGENT_IP", Value: "",
ValueFrom: &corev1.EnvVarSource{
Expand Down Expand Up @@ -177,7 +180,6 @@ func TestGetEnvConfig_OCP4_14(t *testing.T) {
info.Mock("4.14.5", "")
env := getEnvConfig(&fc, &info)
assert.Equal(t, []corev1.EnvVar{
{Name: "GOMEMLIMIT", Value: "0"},
{Name: "METRICS_ENABLE", Value: "true"},
{Name: "METRICS_SERVER_PORT", Value: "9400"},
{Name: "METRICS_PREFIX", Value: "netobserv_agent_"},
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/flp/flp_common_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ func podTemplate(
}
envs = append(envs, constants.EnvNoHTTP2)

envs = helper.EnvFromReqsLimits(envs, &desired.Processor.Resources)

container := corev1.Container{
Name: constants.FLPName,
Image: imageName,
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/flp/flp_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ func ControllerSpecs() {
Protocol: "TCP",
}))
g.Expect(cnt.Env).To(Equal([]v1.EnvVar{
{Name: "GOGC", Value: "400"}, {Name: "GOMAXPROCS", Value: "33"}, {Name: "GODEBUG", Value: "http2server=0"},
{Name: "GOGC", Value: "400"},
{Name: "GOMAXPROCS", Value: "33"},
{Name: "GODEBUG", Value: "http2server=0"},
}))

By("Allocating the proper toleration to allow its placement in the master nodes")
Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/helper/comparators.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ func volumesChanged(old, n *corev1.PodTemplateSpec, report *ChangeReport) bool {
func containerChanged(old, n *corev1.Container, report *ChangeReport) bool {
return report.Check("Image changed", n.Image != old.Image) ||
report.Check("Pull policy changed", n.ImagePullPolicy != old.ImagePullPolicy) ||
report.Check("Args changed", !deepDerivative(n.Args, old.Args)) ||
report.Check("Args changed", !deepEqual(n.Args, old.Args)) ||
report.Check("Resources req/limit changed", !deepDerivative(n.Resources, old.Resources)) ||
report.Check("Env changed", !deepEqual(n.Env, old.Env)) ||
report.Check("Liveness probe changed", probeChanged(n.LivenessProbe, old.LivenessProbe)) ||
report.Check("Startup probe changed", probeChanged(n.StartupProbe, old.StartupProbe))
}
Expand Down
15 changes: 15 additions & 0 deletions internal/pkg/helper/env.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package helper

import (
"fmt"

corev1 "k8s.io/api/core/v1"
)

Expand All @@ -24,3 +26,16 @@ func BuildEnvFromDefaults(config, defaults map[string]string) []corev1.EnvVar {
}
return result
}

func EnvFromReqsLimits(envs []corev1.EnvVar, reqs *corev1.ResourceRequirements) []corev1.EnvVar {
// set GOMEMLIMIT which allows specifying a soft memory cap to force GC when resource limit is reached to prevent OOM
if reqs.Limits.Memory() != nil {
if memLimit, ok := reqs.Limits.Memory().AsInt64(); ok && memLimit > 0 {
// we will set the GOMEMLIMIT to current memlimit - 10% as a headroom to account for
// memory sources the Go runtime is unaware of
memLimit -= int64(float64(memLimit) * 0.1)
envs = append(envs, corev1.EnvVar{Name: "GOMEMLIMIT", Value: fmt.Sprint(memLimit)})
}
}
return envs
}