Skip to content

Commit

Permalink
Properly set imagePullPolicy and containerSecurityContext for EsIndex…
Browse files Browse the repository at this point in the history
…Cleaner cronjob container (#2224)

Signed-off-by: Michal Schott <[email protected]>
Co-authored-by: Ben B <[email protected]>
  • Loading branch information
michalschott and frzifus authored Jun 14, 2023
1 parent 6538461 commit 723105f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pkg/cronjob/es_index_cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ func CreateEsIndexCleaner(jaeger *v1.Jaeger) runtime.Object {
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: util.Truncate(name, 63),
Image: util.ImageName(jaeger.Spec.Storage.EsIndexCleaner.Image, "jaeger-es-index-cleaner-image"),
Args: []string{strconv.Itoa(*jaeger.Spec.Storage.EsIndexCleaner.NumberOfDays), esUrls},
Env: util.RemoveEmptyVars(envs),
EnvFrom: envFromSource,
Resources: commonSpec.Resources,
VolumeMounts: commonSpec.VolumeMounts,
Name: util.Truncate(name, 63),
Image: util.ImageName(jaeger.Spec.Storage.EsIndexCleaner.Image, "jaeger-es-index-cleaner-image"),
ImagePullPolicy: jaeger.Spec.Storage.EsIndexCleaner.ImagePullPolicy,
Args: []string{strconv.Itoa(*jaeger.Spec.Storage.EsIndexCleaner.NumberOfDays), esUrls},
Env: util.RemoveEmptyVars(envs),
EnvFrom: envFromSource,
SecurityContext: jaeger.Spec.Storage.EsIndexCleaner.ContainerSecurityContext,
Resources: commonSpec.Resources,
VolumeMounts: commonSpec.VolumeMounts,
},
},
ImagePullSecrets: commonSpec.ImagePullSecrets,
Expand Down
31 changes: 31 additions & 0 deletions pkg/cronjob/es_index_cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,34 @@ func TestEsIndexCleanerImagePullSecrets(t *testing.T) {

assert.Equal(t, pullSecret, esIndexCleaner.Spec.JobTemplate.Spec.Template.Spec.ImagePullSecrets[0].Name)
}

func TestEsIndexCleanerImagePullPolicy(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestEsIndexCleanerImagePullPolicy"})
days := 0
jaeger.Spec.Storage.EsIndexCleaner.NumberOfDays = &days

const ImagePullPolicy = corev1.PullPolicy("Always")
jaeger.Spec.Storage.EsIndexCleaner.NumberOfDays = &days
jaeger.Spec.Storage.EsIndexCleaner.ImagePullPolicy = corev1.PullPolicy("Always")

esIndexCleaner := CreateEsIndexCleaner(jaeger).(*batchv1.CronJob)

assert.Equal(t, ImagePullPolicy, esIndexCleaner.Spec.JobTemplate.Spec.Template.Spec.Containers[0].ImagePullPolicy)
}

func TestEsIndexCleaneContainerSecurityContext(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestEsIndexCleanerContainerSecurityContext"})
days := 0
jaeger.Spec.Storage.EsIndexCleaner.NumberOfDays = &days

true := true
ContainerSecurityContext := &corev1.SecurityContext{
ReadOnlyRootFilesystem: &true,
}
jaeger.Spec.Storage.EsIndexCleaner.NumberOfDays = &days
jaeger.Spec.Storage.EsIndexCleaner.ContainerSecurityContext = ContainerSecurityContext

esIndexCleaner := CreateEsIndexCleaner(jaeger).(*batchv1.CronJob)

assert.Equal(t, ContainerSecurityContext, esIndexCleaner.Spec.JobTemplate.Spec.Template.Spec.Containers[0].SecurityContext)
}

0 comments on commit 723105f

Please sign in to comment.