Skip to content

Commit

Permalink
fix: Panic on null resource limits (#80)
Browse files Browse the repository at this point in the history
This PR fixes a bug where instrumentation would panic when a deployment
/ statefulset has a null `.spec.containers[].resources.limits`
  • Loading branch information
edeNFed committed Mar 2, 2023
1 parent d35908b commit 970f842
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions instrumentor/patch/dotnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func (d *dotNetPatcher) Patch(podSpec *v1.PodTemplateSpec, instrumentation *odig
var modifiedContainers []v1.Container
for _, container := range podSpec.Spec.Containers {
if shouldPatch(instrumentation, common.DotNetProgrammingLanguage, container.Name) {
if container.Resources.Limits == nil {
container.Resources.Limits = make(map[v1.ResourceName]resource.Quantity)
}

container.Resources.Limits["instrumentation.odigos.io/dotnet"] = resource.MustParse("1")
}

Expand Down
2 changes: 1 addition & 1 deletion instrumentor/patch/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
const (
golangKernelDebugVolumeName = "kernel-debug"
golangKernelDebugHostPath = "/sys/kernel/debug"
golangAgentName = "keyval/otel-go-agent:v0.6.3"
golangAgentName = "keyval/otel-go-agent:v0.6.4"
golangExporterEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT"
golangServiceNameEnv = "OTEL_SERVICE_NAME"
golangTargetExeEnv = "OTEL_TARGET_EXE"
Expand Down
4 changes: 4 additions & 0 deletions instrumentor/patch/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func (j *javaPatcher) Patch(podSpec *v1.PodTemplateSpec, instrumentation *odigos
var modifiedContainers []v1.Container
for _, container := range podSpec.Spec.Containers {
if shouldPatch(instrumentation, common.JavaProgrammingLanguage, container.Name) {
if container.Resources.Limits == nil {
container.Resources.Limits = make(map[v1.ResourceName]resource.Quantity)
}

container.Resources.Limits["instrumentation.odigos.io/java"] = resource.MustParse("1")
}

Expand Down
4 changes: 4 additions & 0 deletions instrumentor/patch/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func (n *nodeJsPatcher) Patch(podSpec *v1.PodTemplateSpec, instrumentation *odig
var modifiedContainers []v1.Container
for _, container := range podSpec.Spec.Containers {
if shouldPatch(instrumentation, common.JavascriptProgrammingLanguage, container.Name) {
if container.Resources.Limits == nil {
container.Resources.Limits = make(map[v1.ResourceName]resource.Quantity)
}

container.Resources.Limits["instrumentation.odigos.io/nodejs"] = resource.MustParse("1")
}

Expand Down
4 changes: 4 additions & 0 deletions instrumentor/patch/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (p *pythonPatcher) Patch(podSpec *v1.PodTemplateSpec, instrumentation *odig
var modifiedContainers []v1.Container
for _, container := range podSpec.Spec.Containers {
if shouldPatch(instrumentation, common.PythonProgrammingLanguage, container.Name) {
if container.Resources.Limits == nil {
container.Resources.Limits = make(map[v1.ResourceName]resource.Quantity)
}

container.Resources.Limits["instrumentation.odigos.io/python"] = resource.MustParse("1")
}

Expand Down
2 changes: 1 addition & 1 deletion odiglet/example-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ spec:
fieldRef:
fieldPath: metadata.namespace
- name: grpc-instrumentation
image: keyval/otel-go-agent:v0.6.3
image: keyval/otel-go-agent:v0.6.4
env:
- name: OTEL_TARGET_EXE
value: /workspace/app
Expand Down

0 comments on commit 970f842

Please sign in to comment.