Skip to content

Commit 395186b

Browse files
pillai-ashwintklauser
authored andcommitted
cilium-cli: Fix CNI config file collection in sysdump
The SubmitCniConflistSubtask function was failing when listing CNI config files because strings.SplitSeq can yield empty strings from trailing newlines in the 'ls' command output. When an empty filename is passed to path.Join with the directory path, it returns just the directory path, and attempting to 'cat' a directory results in an error: failed to copy CNI config file "" from directory "/etc/cni/net.d/": command terminated with exit code 1: "/usr/bin/cat: /etc/cni/net.d: Is a directory" This fix adds a check to skip empty filenames before attempting to copy CNI config files, preventing the error while still collecting all valid CNI configuration files. Additionally, use 'ls -1' to ensure one file per line output regardless of terminal width, which is important when multiple CNI config files exist in the directory. Fixes: cilium#41833 Signed-off-by: Ashwin Pillai <pillaiashwin96@gmail.com>
1 parent 0532a11 commit 395186b

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

cilium-cli/sysdump/sysdump.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,12 +2569,17 @@ func (c *Collector) SubmitCniConflistSubtask(pods []*corev1.Pod, containerName s
25692569
if err := c.Pool.Submit(fmt.Sprintf("cniconflist-%s", p.GetName()), func(ctx context.Context) error {
25702570
outputStr, err := c.Client.ExecInPod(ctx, p.GetNamespace(), p.GetName(), containerName, []string{
25712571
lsCommand,
2572+
"-1",
25722573
c.Options.CNIConfigDirectory,
25732574
})
25742575
if err != nil {
25752576
return err
25762577
}
25772578
for cniFileName := range strings.SplitSeq(strings.TrimSpace(outputStr.String()), "\n") {
2579+
// Skip empty filenames (from trailing newlines or extra whitespace)
2580+
if cniFileName == "" {
2581+
continue
2582+
}
25782583
cniConfigPath := path.Join(c.Options.CNIConfigDirectory, cniFileName)
25792584
if err := c.WithFileSink(fmt.Sprintf(cniConfigFileName, cniFileName, p.GetName()), func(out io.Writer) error {
25802585
return c.Client.ExecInPodWithWriters(ctx, nil, p.GetNamespace(), p.GetName(), containerName, []string{

0 commit comments

Comments
 (0)