Skip to content

Commit

Permalink
Fix: add podNamespace as prefix of source name when pod is matched by…
Browse files Browse the repository at this point in the history
… clusterlogconfig (#613)
  • Loading branch information
ethfoo committed Aug 4, 2023
1 parent 35220b1 commit 452ee1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/discovery/kubernetes/controller/selectpodhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (c *Controller) makeConfigPerSource(s *source.Config, pod *corev1.Pod, lgc
}

// change the source name, add pod.Name-containerName as prefix, since there maybe multiple containers in pod
filesrc.Name = helper.GenTypePodSourceName(pod.Name, status.Name, filesrc.Name)
filesrc.Name = helper.GenTypePodSourceName(lgc.Namespace, pod.Namespace, pod.Name, status.Name, filesrc.Name)

// inject default pod metadata
if err := c.injectTypePodFields(c.config.DynamicContainerLog, filesrc, extra, pod, lgc, status.Name); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion pkg/discovery/kubernetes/helper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ func ToPipelineInterceptor(interceptorsRaw string, interceptorRef string, interc
return interConfList, nil
}

func GenTypePodSourceName(podName string, containerName string, sourceName string) string {
func GenTypePodSourceName(lgcNamespace string, podNamespace string, podName string, containerName string, sourceName string) string {
// if lgcNamespace is empty, we use podNamespace as the first part of the source name,
// because this is the pod matched by clusterLogConfig, if the pod namespace is not added, it may cause the source to be duplicated
if lgcNamespace == "" {
return fmt.Sprintf("%s/%s/%s/%s", podNamespace, podName, containerName, sourceName)
}
return fmt.Sprintf("%s/%s/%s", podName, containerName, sourceName)
}

Expand Down

0 comments on commit 452ee1d

Please sign in to comment.