diff --git a/pkg/inject/sidecar.go b/pkg/inject/sidecar.go index 3b7da1715..c6ff52fef 100644 --- a/pkg/inject/sidecar.go +++ b/pkg/inject/sidecar.go @@ -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) @@ -130,6 +132,7 @@ func container(jaeger *v1.Jaeger) corev1.Container { Name: "jg-binary-trft", }, }, + Resources: commonSpec.Resources, } } diff --git a/pkg/inject/sidecar_test.go b/pkg/inject/sidecar_test.go index cd289b3ef..bb2ecb57a 100644 --- a/pkg/inject/sidecar_test.go +++ b/pkg/inject/sidecar_test.go @@ -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" @@ -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{