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 support for affinity and tolerations #361

Merged
merged 2 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions pkg/apis/jaegertracing/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ type JaegerCommonSpec struct {
VolumeMounts []v1.VolumeMount `json:"volumeMounts"`
Annotations map[string]string `json:"annotations,omitempty"`
Resources v1.ResourceRequirements `json:"resources,omitempty"`
Affinity *v1.Affinity `json:"affinity,omitempty"`
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
}

// JaegerQuerySpec defines the options to be used when deploying the query
Expand Down
12 changes: 12 additions & 0 deletions pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/deployment/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ func (a *Agent) Get() *appsv1.DaemonSet {
},
Resources: commonSpec.Resources,
}},
Affinity: commonSpec.Affinity,
Tolerations: commonSpec.Tolerations,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/deployment/all-in-one.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func (a *AllInOne) Get() *appsv1.Deployment {
}},
Volumes: commonSpec.Volumes,
ServiceAccountName: account.JaegerServiceAccountFor(a.jaeger),
Affinity: commonSpec.Affinity,
Tolerations: commonSpec.Tolerations,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/deployment/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ func (c *Collector) Get() *appsv1.Deployment {
}},
Volumes: commonSpec.Volumes,
ServiceAccountName: account.JaegerServiceAccountFor(c.jaeger),
Affinity: commonSpec.Affinity,
Tolerations: commonSpec.Tolerations,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/deployment/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ func (i *Ingester) Get() *appsv1.Deployment {
}},
Volumes: commonSpec.Volumes,
ServiceAccountName: account.JaegerServiceAccountFor(i.jaeger),
Affinity: commonSpec.Affinity,
Tolerations: commonSpec.Tolerations,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/deployment/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ func (q *Query) Get() *appsv1.Deployment {
}},
Volumes: commonSpec.Volumes,
ServiceAccountName: account.JaegerServiceAccountFor(q.jaeger),
Affinity: commonSpec.Affinity,
Tolerations: commonSpec.Tolerations,
},
},
},
Expand Down
11 changes: 11 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec {
var volumeMounts []corev1.VolumeMount
var volumes []corev1.Volume
resources := &corev1.ResourceRequirements{}
var affinity *corev1.Affinity
var tolerations []corev1.Toleration

for _, commonSpec := range commonSpecs {
// Merge annotations
Expand All @@ -62,13 +64,22 @@ func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec {

// Merge resources
mergeResources(resources, commonSpec.Resources)

// Set the affinity based on the most specific definition available
if affinity == nil {
affinity = commonSpec.Affinity
}

tolerations = append(tolerations, commonSpec.Tolerations...)
}

return &v1.JaegerCommonSpec{
Annotations: annotations,
VolumeMounts: removeDuplicatedVolumeMounts(volumeMounts),
Volumes: removeDuplicatedVolumes(volumes),
Resources: *resources,
Affinity: affinity,
Tolerations: tolerations,
}
}

Expand Down
51 changes: 51 additions & 0 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,57 @@ func TestMergeResourceRequests(t *testing.T) {
assert.Equal(t, *resource.NewQuantity(123, resource.DecimalSI), merged.Resources.Requests[corev1.ResourceRequestsEphemeralStorage])
}

func TestAffinityDefault(t *testing.T) {
generalSpec := v1.JaegerCommonSpec{}
specificSpec := v1.JaegerCommonSpec{}

merged := Merge([]v1.JaegerCommonSpec{specificSpec, generalSpec})

assert.Nil(t, merged.Affinity)
}

func TestAffinityOverride(t *testing.T) {
generalSpec := v1.JaegerCommonSpec{
Affinity: &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{},
},
}
specificSpec := v1.JaegerCommonSpec{
Affinity: &corev1.Affinity{
PodAffinity: &corev1.PodAffinity{},
},
}

merged := Merge([]v1.JaegerCommonSpec{specificSpec, generalSpec})

assert.NotNil(t, merged.Affinity)
assert.NotNil(t, merged.Affinity.PodAffinity)
assert.Nil(t, merged.Affinity.NodeAffinity)
}

func TestMergeTolerations(t *testing.T) {
generalSpec := v1.JaegerCommonSpec{
Tolerations: []corev1.Toleration{{
Key: "toleration1",
}},
}
specificSpec := v1.JaegerCommonSpec{
Tolerations: []corev1.Toleration{{
Key: "toleration1",
}, {
Key: "toleration2",
}},
}

merged := Merge([]v1.JaegerCommonSpec{specificSpec, generalSpec})

// Keys are not unique, so should be aggregation of all tolerations
assert.Len(t, merged.Tolerations, 3)
assert.Equal(t, "toleration1", merged.Tolerations[0].Key)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks wrong at a first glance, but reading the docs makes it clear that it's OK to have two entries with the same key/operator/value, as long as the effect is different. Perhaps add a link to the relevant docs, to avoid future confusion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

assert.Equal(t, "toleration2", merged.Tolerations[1].Key)
assert.Equal(t, "toleration1", merged.Tolerations[2].Key)
}

func TestGetEsHostname(t *testing.T) {
tests := []struct {
underTest map[string]string
Expand Down