Skip to content

Commit

Permalink
Add resource requirements to sidecar agent (#401)
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Brown <gary@brownuk.com>
  • Loading branch information
objectiser authored May 9, 2019
1 parent 97350c6 commit a7bd08e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/inject/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ func container(jaeger *v1.Jaeger) corev1.Container {
jgCompactTrft := util.GetPort("--processor.jaeger-compact.server-host-port=", args, 6831)
jgBinaryTrft := util.GetPort("--processor.jaeger-binary.server-host-port=", args, 6832)

commonSpec := util.Merge([]v1.JaegerCommonSpec{jaeger.Spec.Agent.JaegerCommonSpec, jaeger.Spec.JaegerCommonSpec})

// ensure we have a consistent order of the arguments
// see https://github.com/jaegertracing/jaeger-operator/issues/334
sort.Strings(args)
Expand All @@ -130,6 +132,7 @@ func container(jaeger *v1.Jaeger) corev1.Container {
Name: "jg-binary-trft",
},
},
Resources: commonSpec.Resources,
}
}

Expand Down
37 changes: 37 additions & 0 deletions pkg/inject/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
Expand Down Expand Up @@ -275,6 +276,42 @@ func TestSidecarOverrideReporter(t *testing.T) {
assert.Equal(t, "--reporter.type=thrift", dep.Spec.Template.Spec.Containers[1].Args[1])
}

func TestSidecarAgentResources(t *testing.T) {
jaeger := v1.NewJaeger("TestSidecarAgentResources")
jaeger.Spec.Resources = corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceLimitsCPU: *resource.NewQuantity(1024, resource.BinarySI),
corev1.ResourceLimitsEphemeralStorage: *resource.NewQuantity(512, resource.DecimalSI),
},
Requests: corev1.ResourceList{
corev1.ResourceRequestsCPU: *resource.NewQuantity(1024, resource.BinarySI),
corev1.ResourceRequestsEphemeralStorage: *resource.NewQuantity(512, resource.DecimalSI),
},
}
jaeger.Spec.Agent.Resources = corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceLimitsCPU: *resource.NewQuantity(2048, resource.BinarySI),
corev1.ResourceLimitsMemory: *resource.NewQuantity(123, resource.DecimalSI),
},
Requests: corev1.ResourceList{
corev1.ResourceRequestsCPU: *resource.NewQuantity(2048, resource.BinarySI),
corev1.ResourceRequestsMemory: *resource.NewQuantity(123, resource.DecimalSI),
},
}

dep := dep(map[string]string{Annotation: jaeger.Name}, map[string]string{})
dep = Sidecar(jaeger, dep)

assert.Len(t, dep.Spec.Template.Spec.Containers, 2, "Expected 2 containers")
assert.Equal(t, "jaeger-agent", dep.Spec.Template.Spec.Containers[1].Name)
assert.Equal(t, *resource.NewQuantity(2048, resource.BinarySI), dep.Spec.Template.Spec.Containers[1].Resources.Limits[corev1.ResourceLimitsCPU])
assert.Equal(t, *resource.NewQuantity(2048, resource.BinarySI), dep.Spec.Template.Spec.Containers[1].Resources.Requests[corev1.ResourceRequestsCPU])
assert.Equal(t, *resource.NewQuantity(123, resource.DecimalSI), dep.Spec.Template.Spec.Containers[1].Resources.Limits[corev1.ResourceLimitsMemory])
assert.Equal(t, *resource.NewQuantity(123, resource.DecimalSI), dep.Spec.Template.Spec.Containers[1].Resources.Requests[corev1.ResourceRequestsMemory])
assert.Equal(t, *resource.NewQuantity(512, resource.DecimalSI), dep.Spec.Template.Spec.Containers[1].Resources.Limits[corev1.ResourceLimitsEphemeralStorage])
assert.Equal(t, *resource.NewQuantity(512, resource.DecimalSI), dep.Spec.Template.Spec.Containers[1].Resources.Requests[corev1.ResourceRequestsEphemeralStorage])
}

func dep(annotations map[string]string, labels map[string]string) *appsv1.Deployment {
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit a7bd08e

Please sign in to comment.