Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Logstash crashes with env #7475

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/controller/logstash/initcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -32,7 +34,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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment explaining that Logstash rewrites the configuration file in the presence of environment variable and that that's why we have to copy it.

ln -sf ` + volume.InternalPipelineVolumeMountPath + `/` + PipelineFileName + ` $mount_path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are pipeline files not rewritten?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pipeline files are not rewritten


touch "${init_config_initialized_flag}"
Expand Down
34 changes: 28 additions & 6 deletions test/e2e/logstash/logstash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down