Skip to content

Commit

Permalink
e2e: Fix fluend test failure due to directory permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu committed Feb 4, 2025
1 parent f8d5a20 commit c3a0db4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
24 changes: 22 additions & 2 deletions cmd/fluent/fluent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -85,6 +87,25 @@ func TestFluentE2E(t *testing.T) {
helm := testkit.NewHelm(kc.KubeconfigPath)
helm.AddRepo(t, "chatwork", "https://chatwork.github.io/charts")

// We need to create a pod to alter the /var/log/fluentd-s3 directory
// because the fluentd pod cannot create the directory.
// Note that the fluentd pod uses:
// uid=999(fluent) gid=999(fluent) groups=999(fluent)
kctl := testkit.NewKubectl(kc.KubeconfigPath)
podYamlFile, err := filepath.Abs(filepath.Join("testdata", "fluentd-alter-log-dir.pod.yaml"))
require.NoError(t, err)
require.FileExists(t, podYamlFile)
kctl.Capture(t,
"create", "-f", podYamlFile,
)
t.Cleanup(func() {
kctl.Capture(t, "delete", "-f", podYamlFile)
})

testkit.PollUntil(t, func() bool {
return strings.Contains(kctl.Capture(t, "get", "pod", "fluentd-alter-log-dir"), "Completed")
}, 30*time.Second)

fluentdNs := "default"
logsPath := "logs"
helm.UpgradeOrInstall(t, "fluentd", "chatwork/fluentd", func(hc *testkit.HelmConfig) {
Expand All @@ -102,7 +123,7 @@ func TestFluentE2E(t *testing.T) {
"daemonset.conf": `<source>
@type tail
path /var/log/containers/*.log
pos_file /var/log/containers.log.pos
pos_file /var/log/fluentd/containers.log.pos
tag kube.*
exclude_path ["/var/log/containers/fluent*"]
read_from_head true
Expand Down Expand Up @@ -139,7 +160,6 @@ func TestFluentE2E(t *testing.T) {

fluentdClusterRoleBindingName := "fluentd-cluster-admin-binding"

kctl := testkit.NewKubectl(kc.KubeconfigPath)
defer func() {
if h.CleanupNeeded(t.Failed()) {
kctl.Capture(t, "delete", "clusterrolebinding", fluentdClusterRoleBindingName)
Expand Down
18 changes: 18 additions & 0 deletions cmd/fluent/testdata/fluentd-alter-log-dir.pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Pod
metadata:
name: fluentd-alter-log-dir
spec:
containers:
- name: aws-cli
image: amazon/aws-cli
command: ["sh", "-c", "mkdir -p /var/log/fluentd-s3 && chown -R 999:999 /var/log/fluentd-s3 && mkdir -p /var/log/fluentd && chown -R 999:999 /var/log/fluentd"]
volumeMounts:
- name: fluentd-log-dir
mountPath: /var/log/fluentd-s3
volumes:
- name: fluentd-log-dir
hostPath:
path: /var/log
type: DirectoryOrCreate
restartPolicy: Never

0 comments on commit c3a0db4

Please sign in to comment.