Skip to content

Commit

Permalink
Add support for affinity and tolerations (#361)
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Brown <[email protected]>
  • Loading branch information
objectiser authored and jpkrohling committed Apr 5, 2019
1 parent 922d562 commit 390d5d4
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 0 deletions.
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
52 changes: 52 additions & 0 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,58 @@ 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 do not need to be unique, so should be aggregation of all tolerations
// See https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ for more details
assert.Len(t, merged.Tolerations, 3)
assert.Equal(t, "toleration1", merged.Tolerations[0].Key)
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

0 comments on commit 390d5d4

Please sign in to comment.