forked from kubernetes-sigs/kind
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package common | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"sigs.k8s.io/kind/pkg/cluster/nodes" | ||
"sigs.k8s.io/kind/pkg/errors" | ||
"sigs.k8s.io/kind/pkg/exec" | ||
) | ||
|
||
// CollectLogs provides the common functionality | ||
// to get various debug info from the node | ||
func CollectLogs(n nodes.Node, dir string) error { | ||
execToPathFn := func(cmd exec.Cmd, path string) func() error { | ||
return func() error { | ||
f, err := FileOnHost(filepath.Join(dir, path)) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
return cmd.SetStdout(f).SetStderr(f).Run() | ||
} | ||
} | ||
return errors.AggregateConcurrent([]func() error{ | ||
// record info about the node container | ||
execToPathFn( | ||
n.Command("cat", "/kind/version"), | ||
"kubernetes-version.txt", | ||
), | ||
execToPathFn( | ||
n.Command("journalctl", "--no-pager"), | ||
"journal.log", | ||
), | ||
execToPathFn( | ||
n.Command("journalctl", "--no-pager", "-u", "kubelet.service"), | ||
"kubelet.log", | ||
), | ||
execToPathFn( | ||
n.Command("journalctl", "--no-pager", "-u", "containerd.service"), | ||
"containerd.log", | ||
), | ||
}) | ||
} | ||
|
||
// FileOnHost is a helper to create a file at path | ||
// even if the parent directory doesn't exist | ||
// in which case it will be created with ModePerm | ||
func FileOnHost(path string) (*os.File, error) { | ||
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil { | ||
return nil, err | ||
} | ||
return os.Create(path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters