From 79914eabf455dc8b8fa3344238959851faff5ec7 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 17 Jan 2024 14:08:32 +0000 Subject: [PATCH 1/2] fix init container to copy logstash.yml --- pkg/controller/logstash/initcontainer.go | 2 +- test/e2e/logstash/logstash_test.go | 34 +++++++++++++++++++----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/pkg/controller/logstash/initcontainer.go b/pkg/controller/logstash/initcontainer.go index d9dce7ab9f..9268102ce4 100644 --- a/pkg/controller/logstash/initcontainer.go +++ b/pkg/controller/logstash/initcontainer.go @@ -32,7 +32,7 @@ mount_path=` + volume.InitContainerConfigVolumeMountPath + ` 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 55b1276b5a..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{ @@ -35,9 +57,9 @@ func TestLogstashWithCustomService(t *testing.T) { }, }, } - logstashBuilder := (logstash.NewBuilder(name). + logstashBuilder := logstash.NewBuilder(name). WithNodeCount(1). - WithServices(service)) + WithServices(service) test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) } @@ -55,13 +77,13 @@ func TestLogstashWithReworkedApiService(t *testing.T) { }, }, } - logstashBuilder := (logstash.NewBuilder(name). + logstashBuilder := logstash.NewBuilder(name). WithNodeCount(1). // Change the Logstash API service port WithConfig(map[string]interface{}{ "api.http.port": 9200, }). - WithServices(service)) + WithServices(service) test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) } @@ -91,13 +113,13 @@ func TestLogstashWithCustomServiceAndAmendedApi(t *testing.T) { }, } - logstashBuilder := (logstash.NewBuilder(name). + logstashBuilder := logstash.NewBuilder(name). WithNodeCount(1). // Change the Logstash API service port WithConfig(map[string]interface{}{ "api.http.port": 9601, }). - WithServices(apiService, customService)) + WithServices(apiService, customService) test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) } From e7c02ca2e6b9d7bb7735cf87cd92676a8c4c13c1 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 23 Jan 2024 18:18:21 +0000 Subject: [PATCH 2/2] add comment --- pkg/controller/logstash/initcontainer.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/controller/logstash/initcontainer.go b/pkg/controller/logstash/initcontainer.go index 9268102ce4..857783a428 100644 --- a/pkg/controller/logstash/initcontainer.go +++ b/pkg/controller/logstash/initcontainer.go @@ -16,6 +16,8 @@ const ( InitConfigContainerName = "logstash-internal-init-config" // 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