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

Add resource requirements to sidecar agent #401

Merged
merged 1 commit into from
May 9, 2019
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
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})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do? Why isn't it enough to use just Spec.Agent.Resources?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It allows common resource requirements to be defined in jaeger.Spec.Resources and only agent specific requirements defined in jaeger.Spec.Agent.Resources. Its a pattern used for all parts of the common spec (e.g. volumnes, mounts, annotations, etc).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if no agent resources are specified would it use ones from jaeger.Spec.Resources?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It has been done from a consistency perspective - but if is not reasonable, then we just need to make sure it is documented clearly that for agent as a sidecar (or agent in general), the parent resources are not inherited.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe prefer applying only resources on the agent spec as sidecar can populate to a lot of pods but I don't have strong objections.


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