Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sc-20056] Low resource preset should take precedence over kernel 5.11 overrides #298

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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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()
Expand Down
14 changes: 13 additions & 1 deletion pkg/helm/tune.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package helm
import (
"embed"

"github.com/blang/semver/v4"
"groundcover.com/pkg/k8s"
"k8s.io/apimachinery/pkg/api/resource"
)
Expand All @@ -17,6 +18,13 @@ const (
AGENT_DEFAULT_MEMORY_THRESHOLD = "1024Mi"
AGENT_LOW_RESOURCES_PATH = "presets/agent/low-resources.yaml"

// 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"

BACKEND_DEFAULT_TOTAL_CPU_THRESHOLD = "12000m"
Expand All @@ -39,7 +47,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)

Expand All @@ -50,6 +58,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
}

Expand Down
34 changes: 32 additions & 2 deletions pkg/helm/tune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ package helm_test
import (
"testing"

"github.com/blang/semver/v4"
"github.com/stretchr/testify/assert"
"groundcover.com/pkg/helm"
"groundcover.com/pkg/k8s"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
)

var (
Kernel510Semver = semver.MustParse("5.10.0")
Kernel511Semver = semver.MustParse("5.11.0")
)

func TestTuneResourcesValuesAgentLow(t *testing.T) {
// arrange
agentLowCpu := resource.MustParse(helm.AGENT_DEFAULT_CPU_THRESHOLD)
Expand All @@ -28,7 +34,7 @@ func TestTuneResourcesValuesAgentLow(t *testing.T) {
resources := helm.CalcAllocatableResources(lowNodeReport)

// act
cpu := helm.GetAgentResourcePresetPath(resources)
cpu := helm.GetAgentResourcePresetPath(resources, Kernel510Semver)

// assert
assert.Equal(t, helm.AGENT_LOW_RESOURCES_PATH, cpu)
Expand All @@ -52,12 +58,36 @@ func TestTuneResourcesValuesAgentDefault(t *testing.T) {
resources := helm.CalcAllocatableResources(defaultNodeReport)

// act
cpu := helm.GetAgentResourcePresetPath(resources)
cpu := helm.GetAgentResourcePresetPath(resources, Kernel510Semver)

// 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, Kernel511Semver)

// 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)
Expand Down
Loading