Skip to content

Commit

Permalink
Increase the cpu/memory requests for the init container + create new …
Browse files Browse the repository at this point in the history
…configs to set the limits
  • Loading branch information
iamluc committed Oct 18, 2024
1 parent 53d7246 commit 5ea4dd9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
mountPath = "/datadog-lib"

// defaultMilliCPURequest defines default milli cpu request number.
defaultMilliCPURequest int64 = 50 // 0.05 core
defaultMilliCPURequest int64 = 300 // 0.3 core
// defaultMemoryRequest defines default memory request size.
defaultMemoryRequest int64 = 100 * 1024 * 1024 // 100 MB (recommended minimum by Alpine)

Expand Down Expand Up @@ -651,7 +651,6 @@ func (w *Webhook) injectAutoInstruConfig(pod *corev1.Pod, config extractedPodLib
}

func initResources() (corev1.ResourceRequirements, error) {

var resources = corev1.ResourceRequirements{Limits: corev1.ResourceList{}, Requests: corev1.ResourceList{}}

if pkgconfigsetup.Datadog().IsSet("admission_controller.auto_instrumentation.init_resources.cpu") {
Expand All @@ -660,10 +659,16 @@ func initResources() (corev1.ResourceRequirements, error) {
return resources, err
}
resources.Requests[corev1.ResourceCPU] = quantity
resources.Limits[corev1.ResourceCPU] = quantity
} else {
resources.Requests[corev1.ResourceCPU] = *resource.NewMilliQuantity(defaultMilliCPURequest, resource.DecimalSI)
resources.Limits[corev1.ResourceCPU] = *resource.NewMilliQuantity(defaultMilliCPURequest, resource.DecimalSI)
}

if pkgconfigsetup.Datadog().IsSet("admission_controller.auto_instrumentation.init_resources.cpu_limit") {
quantity, err := resource.ParseQuantity(pkgconfigsetup.Datadog().GetString("admission_controller.auto_instrumentation.init_resources.cpu_limit"))
if err != nil {
return resources, err
}
resources.Limits[corev1.ResourceCPU] = quantity
}

if pkgconfigsetup.Datadog().IsSet("admission_controller.auto_instrumentation.init_resources.memory") {
Expand All @@ -672,10 +677,16 @@ func initResources() (corev1.ResourceRequirements, error) {
return resources, err
}
resources.Requests[corev1.ResourceMemory] = quantity
resources.Limits[corev1.ResourceMemory] = quantity
} else {
resources.Requests[corev1.ResourceMemory] = *resource.NewQuantity(defaultMemoryRequest, resource.DecimalSI)
resources.Limits[corev1.ResourceMemory] = *resource.NewQuantity(defaultMemoryRequest, resource.DecimalSI)
}

if pkgconfigsetup.Datadog().IsSet("admission_controller.auto_instrumentation.init_resources.memory_limit") {
quantity, err := resource.ParseQuantity(pkgconfigsetup.Datadog().GetString("admission_controller.auto_instrumentation.init_resources.memory_limit"))
if err != nil {
return resources, err
}
resources.Limits[corev1.ResourceMemory] = quantity
}

return resources, nil
Expand Down
16 changes: 14 additions & 2 deletions pkg/config/config_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3108,16 +3108,28 @@ api_key:

## @param cpu - string - optional
## @env DD_ADMISSION_CONTROLLER_AUTO_INSTRUMENTATION_INIT_RESOURCES_CPU - string - optional
## Configures the CPU request and limit for the init containers.
## Configures the CPU request for the init containers.
#
# cpu:

## @param cpu_limit - string - optional
## @env DD_ADMISSION_CONTROLLER_AUTO_INSTRUMENTATION_INIT_RESOURCES_CPU_LIMIT - string - optional
## Configures the CPU limit for the init containers.
#
# cpu:

## @param memory - string - optional
## @env DD_ADMISSION_CONTROLLER_AUTO_INSTRUMENTATION_INIT_RESOURCES_MEMORY - string - optional
## Configures the memory request and limit for the init containers.
## Configures the memory request for the init containers.
#
# memory:

## @param memory_limit - string - optional
## @env DD_ADMISSION_CONTROLLER_AUTO_INSTRUMENTATION_INIT_RESOURCES_MEMORY_LIMIT - string - optional
## Configures the memory limit for the init containers.
#
# memory_limit:

## @param init_security_context - json - optional
## @env DD_ADMISSION_CONTROLLER_AUTO_INSTRUMENTATION_INIT_SECURITY_CONTEXT - json - optional
## Security context for the init containers in JSON format. Follows the Kubernetes security context spec,
Expand Down

0 comments on commit 5ea4dd9

Please sign in to comment.