Skip to content

Commit

Permalink
Add resource limits for spark dependencies cronjob
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <[email protected]>
  • Loading branch information
rubenvp8510 committed Aug 27, 2019
1 parent dcd7873 commit 49de25d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/jaegertracing/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ type JaegerDependenciesSpec struct {

// +optional
TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished,omitempty"`

// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`
}

// JaegerEsIndexCleanerSpec holds the options related to es-index-cleaner
Expand Down
1 change: 1 addition & 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.

6 changes: 5 additions & 1 deletion pkg/cronjob/spark_dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
"github.com/jaegertracing/jaeger-operator/pkg/storage"
"github.com/jaegertracing/jaeger-operator/pkg/util"
)

var supportedStorageTypes = map[string]bool{"elasticsearch": true, "cassandra": true}
Expand All @@ -33,6 +34,8 @@ func CreateSparkDependencies(jaeger *v1.Jaeger) *batchv1beta1.CronJob {
trueVar := true
one := int32(1)
name := fmt.Sprintf("%s-spark-dependencies", jaeger.Name)
resources := jaeger.Spec.Storage.Dependencies.Resources
util.MergeResources(&resources, jaeger.Spec.Resources)
return &batchv1beta1.CronJob{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down Expand Up @@ -68,7 +71,8 @@ func CreateSparkDependencies(jaeger *v1.Jaeger) *batchv1beta1.CronJob {
Image: jaeger.Spec.Storage.Dependencies.Image,
Name: name,
// let spark job use its default values
Env: removeEmptyVars(envVars),
Env: removeEmptyVars(envVars),
Resources: resources,
},
},
RestartPolicy: corev1.RestartPolicyNever,
Expand Down
64 changes: 64 additions & 0 deletions pkg/cronjob/spark_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"

v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
)
Expand Down Expand Up @@ -83,3 +84,66 @@ func TestSparkDependencies(t *testing.T) {
cjob := CreateSparkDependencies(j)
assert.Equal(t, j.Namespace, cjob.Namespace)
}

func TestSparkDependenciesResources(t *testing.T) {

parentResources := 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),
},
}

dependencyResources := corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceLimitsCPU: *resource.NewQuantity(2048, resource.BinarySI),
corev1.ResourceLimitsEphemeralStorage: *resource.NewQuantity(1024, resource.DecimalSI),
},
Requests: corev1.ResourceList{
corev1.ResourceRequestsCPU: *resource.NewQuantity(2048, resource.BinarySI),
corev1.ResourceRequestsEphemeralStorage: *resource.NewQuantity(1024, resource.DecimalSI),
},
}

tests := []struct {
jaeger *v1.Jaeger
expected corev1.ResourceRequirements
}{
{
jaeger: &v1.Jaeger{Spec: v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Type: "elasticsearch"}}},
expected: corev1.ResourceRequirements{},
},
{
jaeger: &v1.Jaeger{Spec: v1.JaegerSpec{
Storage: v1.JaegerStorageSpec{Type: "elasticsearch"},
JaegerCommonSpec: v1.JaegerCommonSpec{
Resources: parentResources,
},
}},
expected: parentResources,
},
{
jaeger: &v1.Jaeger{Spec: v1.JaegerSpec{
Storage: v1.JaegerStorageSpec{
Type: "elasticsearch",
Dependencies: v1.JaegerDependenciesSpec{
Resources: dependencyResources,
},
},
JaegerCommonSpec: v1.JaegerCommonSpec{
Resources: parentResources,
},
}},
expected: dependencyResources,
},
}
for _, test := range tests {
cjob := CreateSparkDependencies(test.jaeger)
assert.Equal(t, test.expected, cjob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Resources)

}
}
5 changes: 3 additions & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec {
volumes = append(volumes, commonSpec.Volumes...)

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

// Set the affinity based on the most specific definition available
if affinity == nil {
Expand Down Expand Up @@ -104,7 +104,8 @@ func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec {
}
}

func mergeResources(resources *corev1.ResourceRequirements, res corev1.ResourceRequirements) {
// MergeResources returns a merged version of two resource requirements
func MergeResources(resources *corev1.ResourceRequirements, res corev1.ResourceRequirements) {

for k, v := range res.Limits {
if _, ok := resources.Limits[k]; !ok {
Expand Down

0 comments on commit 49de25d

Please sign in to comment.