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

Support bypass params when using mounted-file type #381

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 16 additions & 4 deletions config-reloader/processors/mounted_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ const mountedFileSourceType = "mounted-file"

// ContainerFile stores parsed info from a <source> @type mounted-file...
type ContainerFile struct {
Labels map[string]string
AddedLabels map[string]string
Path string
Parse *fluentd.Directive
Labels map[string]string
AddedLabels map[string]string
Path string
Parse *fluentd.Directive
BypassParams map[string]string
}

type mountedFileState struct {
Expand Down Expand Up @@ -69,6 +70,13 @@ func (state *mountedFileState) Prepare(input fluentd.Fragment) (fluentd.Fragment
}
cf.Path = paramPath

cf.BypassParams = map[string]string{}
for k, el := range frag.Params {
if !contains([]string{"labels", "add_labels", "path"}, k) {
cf.BypassParams[el.Name] = el.Value
}
}

if len(frag.Nested) == 1 {
cf.Parse = frag.Nested[0]
} else if len(frag.Nested) >= 2 {
Expand Down Expand Up @@ -105,6 +113,10 @@ func (state *mountedFileState) convertToFragement(cf *ContainerFile) fluentd.Fra
}
dir.SetParam("@type", "tail")

for k, el := range cf.BypassParams {
dir.SetParam(k, el)
}

hostPath := state.makeHostPath(cf, hm, mc)
pos := util.Hash(state.Context.DeploymentID, fmt.Sprintf("%s-%s-%s", mc.PodID, mc.Name, hostPath))
tag := fmt.Sprintf("kube.%s.%s.%s-%s", state.Context.Namespace, mc.PodName, mc.Name, pos)
Expand Down
6 changes: 6 additions & 0 deletions config-reloader/processors/mounted_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ func TestProcessMountedFile(t *testing.T) {
@type mounted-file
path /var/log/redis.log
labels app=redis
read_from_head false
refresh_interval 1s
multiline_flush_interval 1s
</source>

<source>
Expand Down Expand Up @@ -366,6 +369,9 @@ func TestProcessMountedFile(t *testing.T) {
assert.Equal(t, "/kubelet-root/pods/123-id/volumes/kubernetes.io~empty-dir/logs/redis.log", prep[0].Param("path"))
assert.Equal(t, "/kubelet-root/pods/abc-id/volumes/kubernetes.io~empty-dir/logs/nginx.log", prep[2].Param("path"))
assert.Equal(t, "/kubelet-root/pods/abc-sub-id/volumes/kubernetes.io~empty-dir/logs/files/nginx.log", prep[4].Param("path"))
assert.Equal(t, "true", prep[0].Param("read_from_head"))
assert.Equal(t, "1s", prep[0].Param("refresh_interval"))
assert.Equal(t, "1s", prep[0].Param("multiline_flush_interval"))

payload := prep.String()
assert.True(t, strings.Contains(payload, "'container_image'=>'image-c2'"))
Expand Down