diff --git a/pkg/controller/logstash/initcontainer.go b/pkg/controller/logstash/initcontainer.go index 1479a6d98b..d290cd36ad 100644 --- a/pkg/controller/logstash/initcontainer.go +++ b/pkg/controller/logstash/initcontainer.go @@ -18,6 +18,8 @@ const ( UseTLSEnv = "USE_TLS" // InitConfigScript is a small bash script to prepare the logstash configuration directory + // Logstash rewrites the configuration file (logstash.yml) in the presence of ${VAR} environment variable, + // therefore the file is copied to the path instead of creating symbolic link. InitConfigScript = `#!/usr/bin/env bash set -eu @@ -46,7 +48,7 @@ echo "Setup Logstash configuration" cp -f /usr/share/logstash/config/*.* "$mount_path" -ln -sf ` + volume.InternalConfigVolumeMountPath + `/` + ConfigFileName + ` $mount_path +cp ` + volume.InternalConfigVolumeMountPath + `/` + ConfigFileName + ` $mount_path ln -sf ` + volume.InternalPipelineVolumeMountPath + `/` + PipelineFileName + ` $mount_path touch "${init_config_initialized_flag}" diff --git a/test/e2e/logstash/logstash_test.go b/test/e2e/logstash/logstash_test.go index 6540d3cbbc..c915624492 100644 --- a/test/e2e/logstash/logstash_test.go +++ b/test/e2e/logstash/logstash_test.go @@ -23,6 +23,28 @@ func TestSingleLogstash(t *testing.T) { test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) } +func TestLogstashWithEnv(t *testing.T) { + name := "test-env-logstash" + logstashBuilder := logstash.NewBuilder(name). + WithNodeCount(1). + WithPodTemplate(corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "logstash", + Env: []corev1.EnvVar{ + { + Name: "NODE_NAME", + Value: "node01", + }, + }, + }, + }, + }, + }) + test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) +} + func TestLogstashWithCustomService(t *testing.T) { name := "test-multiple-custom-logstash" service := logstashv1alpha1.LogstashService{