Skip to content

Commit

Permalink
Better defaults for PodLogOptions
Browse files Browse the repository at this point in the history
Fixes #475

Signed-off-by: Chuck Ha <[email protected]>
  • Loading branch information
Chuck Ha authored and chuckha committed Jul 11, 2018
1 parent 5b6f30f commit 5a2bbf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
26 changes: 16 additions & 10 deletions pkg/discovery/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ const (
PodLogsLocation = "podlogs"
)

// Only set values if they have values greater than 0 (as in they user specified).
func getPodLogOptions(container string, limitBytes, sinceSeconds int64) *v1.PodLogOptions {
options := &v1.PodLogOptions{
Container: container,
}
if limitBytes > 0 {
options.LimitBytes = &limitBytes
}
if sinceSeconds > 0 {
options.SinceSeconds = &sinceSeconds
}
return options
}

// gatherPodLogs will loop through collecting pod logs and placing them into a directory tree
func gatherPodLogs(kubeClient kubernetes.Interface, ns string, opts metav1.ListOptions, cfg *config.Config) error {
// 1 - Collect the list of pods
Expand All @@ -56,19 +70,11 @@ func gatherPodLogs(kubeClient kubernetes.Interface, ns string, opts metav1.ListO
continue
}
for _, container := range pod.Spec.Containers {
body, err := kubeClient.CoreV1().Pods(ns).GetLogs(
pod.Name,
&v1.PodLogOptions{
Container: container.Name,
LimitBytes: &limitBytes,
SinceSeconds: &limitTime,
},
).Do().Raw()

options := getPodLogOptions(container.Name, limitBytes, limitTime)
body, err := kubeClient.CoreV1().Pods(ns).GetLogs(pod.Name, options).DoRaw()
if err != nil {
return errors.WithStack(err)
}

outdir := path.Join(cfg.OutputDir(), PodLogsLocation, ns, pod.Name, "logs")
if err = os.MkdirAll(outdir, 0755); err != nil {
return errors.WithStack(err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/discovery/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,14 @@ func QueryClusterResources(kubeClient kubernetes.Interface, recorder *QueryRecor
// is odd and would pollute some of the output.

start := time.Now()
// TODO(chuckha) look at FieldSelector for list options{}
nodeList, err := kubeClient.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
errlog.LogError(fmt.Errorf("failed to get node list: %v", err))
// Do not return or continue because we also want to query nodes as resources
break
}
nodeNames := make([]string, nodeList.Size())
nodeNames := make([]string, len(nodeList.Items))
for i, node := range nodeList.Items {
nodeNames[i] = node.Name
}
Expand Down

0 comments on commit 5a2bbf1

Please sign in to comment.