Skip to content

Commit

Permalink
Configure index cleaner properly when rollover is enabled (#587)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <[email protected]>
  • Loading branch information
pavolloffay authored Aug 9, 2019
1 parent c367de1 commit cbb3610
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/cronjob/es_index_cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cronjob
import (
"fmt"
"strconv"
"strings"

batchv1 "k8s.io/api/batch/v1"
batchv1beta1 "k8s.io/api/batch/v1beta1"
Expand Down Expand Up @@ -32,6 +33,10 @@ func CreateEsIndexCleaner(jaeger *v1.Jaeger) *batchv1beta1.CronJob {
},
})
}
envs := esScriptEnvVars(jaeger.Spec.Storage.Options)
if val, ok := jaeger.Spec.Storage.Options.Map()["es.use-aliases"]; ok && strings.EqualFold(val, "true") {
envs = append(envs, corev1.EnvVar{Name: "ROLLOVER", Value: "true"})
}

return &batchv1beta1.CronJob{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -68,7 +73,7 @@ func CreateEsIndexCleaner(jaeger *v1.Jaeger) *batchv1beta1.CronJob {
Name: name,
Image: jaeger.Spec.Storage.EsIndexCleaner.Image,
Args: []string{strconv.Itoa(*jaeger.Spec.Storage.EsIndexCleaner.NumberOfDays), esUrls},
Env: esScriptEnvVars(jaeger.Spec.Storage.Options),
Env: envs,
EnvFrom: envFromSource,
},
},
Expand Down
33 changes: 33 additions & 0 deletions pkg/cronjob/es_index_cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

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

v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
Expand Down Expand Up @@ -33,3 +34,35 @@ func TestEsIndexCleanerSecrets(t *testing.T) {
cronJob := CreateEsIndexCleaner(jaeger)
assert.Equal(t, secret, cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].EnvFrom[0].SecretRef.LocalObjectReference.Name)
}

func TestEsIndexCleanerEnvVars(t *testing.T) {
tests := []struct {
opts map[string]interface{}
envs []corev1.EnvVar
}{
{
// empty options do not add any env vars
},
{
opts: map[string]interface{}{"es.index-prefix": "foo", "es.username": "joe", "es.password": "pass"},
envs: []corev1.EnvVar{{Name: "INDEX_PREFIX", Value: "foo"}, {Name: "ES_USERNAME", Value: "joe"}, {Name: "ES_PASSWORD", Value: "pass"}},
},
{
opts: map[string]interface{}{"es.index-prefix": "foo", "es.username": "joe", "es.password": "pass", "es.use-aliases": "false"},
envs: []corev1.EnvVar{{Name: "INDEX_PREFIX", Value: "foo"}, {Name: "ES_USERNAME", Value: "joe"}, {Name: "ES_PASSWORD", Value: "pass"}},
},
{
opts: map[string]interface{}{"es.index-prefix": "foo", "es.username": "joe", "es.password": "pass", "es.use-aliases": "true"},
envs: []corev1.EnvVar{{Name: "INDEX_PREFIX", Value: "foo"}, {Name: "ES_USERNAME", Value: "joe"}, {Name: "ES_PASSWORD", Value: "pass"}, {Name: "ROLLOVER", Value: "true"}},
},
}

for _, test := range tests {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestEsIndexCleanerSecrets"})
days := 0
jaeger.Spec.Storage.EsIndexCleaner.NumberOfDays = &days
jaeger.Spec.Storage.Options = v1.NewOptions(test.opts)
cronJob := CreateEsIndexCleaner(jaeger)
assert.Equal(t, test.envs, cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Env)
}
}

0 comments on commit cbb3610

Please sign in to comment.