From 5416ffd559f1cf3a6f4024e17aa9fc6fbdb7f413 Mon Sep 17 00:00:00 2001 From: Aviv Zohari Date: Sun, 13 Oct 2024 13:36:51 +0000 Subject: [PATCH 1/2] Low resource preset should take precedence over kernel 5.11 overrides --- CHANGELOG.md | 2 ++ cmd/deploy.go | 8 +------- pkg/helm/tune.go | 9 ++++++++- pkg/helm/tune_test.go | 34 ++++++++++++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e546d87..84e6147 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ We use the following categories for changes: ### Fixed +- Low resource preset should take precedence over kernel 5.11 overrides [#sc-20056] + ### Removed ### Deprecated diff --git a/cmd/deploy.go b/cmd/deploy.go index 9d5d4f9..69679c6 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -6,7 +6,6 @@ import ( "strconv" "time" - "github.com/blang/semver/v4" "github.com/getsentry/sentry-go" "github.com/imdario/mergo" "github.com/pkg/errors" @@ -46,7 +45,6 @@ const ( HELM_REPO_URL = "https://helm.groundcover.com" CLUSTER_URL_FORMAT = "%s/?clusterId=%s&viewType=Overview" QUAY_REGISTRY_PRESET_PATH = "presets/quay.yaml" - AGENT_KERNEL_5_11_PRESET_PATH = "presets/agent/kernel-5-11.yaml" CUSTOM_METRICS_PRESET_PATH = "presets/backend/custom-metrics.yaml" KUBE_STATE_METRICS_PRESET_PATH = "presets/backend/kube-state-metrics.yaml" STORAGE_CLASS_TEMPLATE_PATH = "templates/backend/storage-class.yaml" @@ -607,7 +605,7 @@ func generateChartValues(chartValues map[string]interface{}, apiKey, installatio helm.BACKEND_LOW_RESOURCES_PATH, } } else { - agentPresetPath := helm.GetAgentResourcePresetPath(allocatableResources) + agentPresetPath := helm.GetAgentResourcePresetPath(allocatableResources, nodesReport.MaximalKernelVersion()) if agentPresetPath != helm.DEFAULT_PRESET { overridePaths = append(overridePaths, agentPresetPath) } @@ -632,10 +630,6 @@ func generateChartValues(chartValues map[string]interface{}, apiKey, installatio overridePaths = append(overridePaths, KUBE_STATE_METRICS_PRESET_PATH) } - if semver.MustParseRange(">=5.11.0")(nodesReport.MaximalKernelVersion()) { - overridePaths = append(overridePaths, AGENT_KERNEL_5_11_PRESET_PATH) - } - if len(overridePaths) > 0 { sentryHelmContext.ResourcesPresets = overridePaths sentryHelmContext.SetOnCurrentScope() diff --git a/pkg/helm/tune.go b/pkg/helm/tune.go index 6c61457..70d227c 100644 --- a/pkg/helm/tune.go +++ b/pkg/helm/tune.go @@ -3,6 +3,7 @@ package helm import ( "embed" + "github.com/blang/semver/v4" "groundcover.com/pkg/k8s" "k8s.io/apimachinery/pkg/api/resource" ) @@ -16,6 +17,8 @@ const ( AGENT_DEFAULT_CPU_THRESHOLD = "1000m" AGENT_DEFAULT_MEMORY_THRESHOLD = "1024Mi" AGENT_LOW_RESOURCES_PATH = "presets/agent/low-resources.yaml" + AGENT_KERNEL_5_11_PRESET_PATH = "presets/agent/kernel-5-11.yaml" + KERNEL_5_11_SEMVER_EXPRESSION = ">=5.11.0" EMPTYDIR_STORAGE_PATH = "presets/backend/emptydir-storage.yaml" @@ -39,7 +42,7 @@ type AllocatableResources struct { NodeCount int } -func GetAgentResourcePresetPath(allocatableResources *AllocatableResources) string { +func GetAgentResourcePresetPath(allocatableResources *AllocatableResources, maxKernelVersion semver.Version) string { defaultCpuThreshold := resource.MustParse(AGENT_DEFAULT_CPU_THRESHOLD) defaultMemoryThreshold := resource.MustParse(AGENT_DEFAULT_MEMORY_THRESHOLD) @@ -50,6 +53,10 @@ func GetAgentResourcePresetPath(allocatableResources *AllocatableResources) stri return AGENT_LOW_RESOURCES_PATH } + if semver.MustParseRange(KERNEL_5_11_SEMVER_EXPRESSION)(maxKernelVersion) { + return AGENT_KERNEL_5_11_PRESET_PATH + } + return DEFAULT_PRESET } diff --git a/pkg/helm/tune_test.go b/pkg/helm/tune_test.go index 6a35db9..abfd1dd 100644 --- a/pkg/helm/tune_test.go +++ b/pkg/helm/tune_test.go @@ -3,6 +3,7 @@ package helm_test import ( "testing" + "github.com/blang/semver/v4" "github.com/stretchr/testify/assert" "groundcover.com/pkg/helm" "groundcover.com/pkg/k8s" @@ -10,6 +11,11 @@ import ( "k8s.io/apimachinery/pkg/api/resource" ) +var ( + OldKernelSemver = semver.MustParse("5.10.0") + NewKernelSemver = semver.MustParse("5.11.0") +) + func TestTuneResourcesValuesAgentLow(t *testing.T) { // arrange agentLowCpu := resource.MustParse(helm.AGENT_DEFAULT_CPU_THRESHOLD) @@ -28,7 +34,7 @@ func TestTuneResourcesValuesAgentLow(t *testing.T) { resources := helm.CalcAllocatableResources(lowNodeReport) // act - cpu := helm.GetAgentResourcePresetPath(resources) + cpu := helm.GetAgentResourcePresetPath(resources, OldKernelSemver) // assert assert.Equal(t, helm.AGENT_LOW_RESOURCES_PATH, cpu) @@ -52,12 +58,36 @@ func TestTuneResourcesValuesAgentDefault(t *testing.T) { resources := helm.CalcAllocatableResources(defaultNodeReport) // act - cpu := helm.GetAgentResourcePresetPath(resources) + cpu := helm.GetAgentResourcePresetPath(resources, OldKernelSemver) // assert assert.Equal(t, helm.DEFAULT_PRESET, cpu) } +func TestTuneResourcesValuesAgentNewKernel(t *testing.T) { + // arrange + agentDefaultCpu := resource.MustParse(helm.AGENT_DEFAULT_CPU_THRESHOLD) + agentDefaultCpu.Add(*resource.NewMilliQuantity(1, resource.DecimalSI)) + + agentDefaultMemory := resource.MustParse(helm.AGENT_DEFAULT_MEMORY_THRESHOLD) + agentDefaultMemory.Add(*resource.NewQuantity(1, resource.BinarySI)) + + defaultNodeReport := []*k8s.NodeSummary{ + { + CPU: &agentDefaultCpu, + Memory: &agentDefaultMemory, + }, + } + + resources := helm.CalcAllocatableResources(defaultNodeReport) + + // act + cpu := helm.GetAgentResourcePresetPath(resources, NewKernelSemver) + + // assert + assert.Equal(t, helm.AGENT_KERNEL_5_11_PRESET_PATH, cpu) +} + func TestTuneResourcesValuesBackendLow(t *testing.T) { // arrange backendLowCpu := resource.MustParse(helm.BACKEND_DEFAULT_TOTAL_CPU_THRESHOLD) From 5e42acfa1efbda1afcd096f42e852fb11cadd4a6 Mon Sep 17 00:00:00 2001 From: Aviv Zohari Date: Mon, 21 Oct 2024 07:21:43 +0000 Subject: [PATCH 2/2] cr fixes --- pkg/helm/tune.go | 9 +++++++-- pkg/helm/tune_test.go | 10 +++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/helm/tune.go b/pkg/helm/tune.go index 70d227c..bd9851b 100644 --- a/pkg/helm/tune.go +++ b/pkg/helm/tune.go @@ -17,8 +17,13 @@ const ( AGENT_DEFAULT_CPU_THRESHOLD = "1000m" AGENT_DEFAULT_MEMORY_THRESHOLD = "1024Mi" AGENT_LOW_RESOURCES_PATH = "presets/agent/low-resources.yaml" - AGENT_KERNEL_5_11_PRESET_PATH = "presets/agent/kernel-5-11.yaml" - KERNEL_5_11_SEMVER_EXPRESSION = ">=5.11.0" + + // Starting from Linux kernel version 5.11, eBPF maps are accounted for in the memory cgroup + // of the process that created them. For this reason we need to increase the memory limit for + // the agent. + // https://github.com/cilium/ebpf/blob/v0.16.0/docs/ebpf/concepts/rlimit.md#resource-limits + AGENT_KERNEL_5_11_PRESET_PATH = "presets/agent/kernel-5-11.yaml" + KERNEL_5_11_SEMVER_EXPRESSION = ">=5.11.0" EMPTYDIR_STORAGE_PATH = "presets/backend/emptydir-storage.yaml" diff --git a/pkg/helm/tune_test.go b/pkg/helm/tune_test.go index abfd1dd..957d3b6 100644 --- a/pkg/helm/tune_test.go +++ b/pkg/helm/tune_test.go @@ -12,8 +12,8 @@ import ( ) var ( - OldKernelSemver = semver.MustParse("5.10.0") - NewKernelSemver = semver.MustParse("5.11.0") + Kernel510Semver = semver.MustParse("5.10.0") + Kernel511Semver = semver.MustParse("5.11.0") ) func TestTuneResourcesValuesAgentLow(t *testing.T) { @@ -34,7 +34,7 @@ func TestTuneResourcesValuesAgentLow(t *testing.T) { resources := helm.CalcAllocatableResources(lowNodeReport) // act - cpu := helm.GetAgentResourcePresetPath(resources, OldKernelSemver) + cpu := helm.GetAgentResourcePresetPath(resources, Kernel510Semver) // assert assert.Equal(t, helm.AGENT_LOW_RESOURCES_PATH, cpu) @@ -58,7 +58,7 @@ func TestTuneResourcesValuesAgentDefault(t *testing.T) { resources := helm.CalcAllocatableResources(defaultNodeReport) // act - cpu := helm.GetAgentResourcePresetPath(resources, OldKernelSemver) + cpu := helm.GetAgentResourcePresetPath(resources, Kernel510Semver) // assert assert.Equal(t, helm.DEFAULT_PRESET, cpu) @@ -82,7 +82,7 @@ func TestTuneResourcesValuesAgentNewKernel(t *testing.T) { resources := helm.CalcAllocatableResources(defaultNodeReport) // act - cpu := helm.GetAgentResourcePresetPath(resources, NewKernelSemver) + cpu := helm.GetAgentResourcePresetPath(resources, Kernel511Semver) // assert assert.Equal(t, helm.AGENT_KERNEL_5_11_PRESET_PATH, cpu)