Skip to content

Commit

Permalink
Kamel Dump command: Added log lines parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
oscerd committed Mar 25, 2021
1 parent 3397ce0 commit f64b6b9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ func newCmdDump(rootCmdOptions *RootCmdOptions) (*cobra.Command, *dumpCmdOptions
RunE: options.dump,
}

cmd.Flags().Int("logLines", 100, "Number of log lines to dump")
return &cmd, &options
}

type dumpCmdOptions struct {
*RootCmdOptions
LogLines int `mapstructure:"logLines"`
}

func (o *dumpCmdOptions) dump(_ *cobra.Command, args []string) error {
Expand All @@ -62,15 +64,15 @@ func (o *dumpCmdOptions) dump(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
dumpNamespace(o.Context, c, o.Namespace, writer)
dumpNamespace(o.Context, c, o.Namespace, writer, o.LogLines)
defer writer.Close()
} else {
dumpNamespace(o.Context, c, o.Namespace, os.Stdout)
dumpNamespace(o.Context, c, o.Namespace, os.Stdout, o.LogLines)
}
return nil
}

func dumpNamespace(ctx context.Context, c client.Client, ns string, out *os.File) error {
func dumpNamespace(ctx context.Context, c client.Client, ns string, out *os.File, logLines int) error {

camelClient, err := versioned.NewForConfig(c.GetConfig())
if err != nil {
Expand Down Expand Up @@ -162,7 +164,7 @@ func dumpNamespace(ctx context.Context, c client.Client, ns string, out *os.File
for _, container := range allContainers {
pad := " "
fmt.Fprintf(out, "%s%s\n", pad, container.Name)
err := dumpLogs(ctx, c, fmt.Sprintf("%s> ", pad), ns, pod.Name, container.Name, out)
err := dumpLogs(ctx, c, fmt.Sprintf("%s> ", pad), ns, pod.Name, container.Name, out, logLines)
if err != nil {
fmt.Fprintf(out, "%sERROR while reading the logs: %v\n", pad, err)
}
Expand All @@ -177,8 +179,8 @@ func dumpConditions(prefix string, conditions []v1.PodCondition, out *os.File) {
}
}

func dumpLogs(ctx context.Context, c client.Client, prefix string, ns string, name string, container string, out *os.File) error {
lines := int64(50)
func dumpLogs(ctx context.Context, c client.Client, prefix string, ns string, name string, container string, out *os.File, logLines int) error {
lines := int64(logLines)
stream, err := c.CoreV1().Pods(ns).GetLogs(name, &v1.PodLogOptions{
Container: container,
TailLines: &lines,
Expand Down

0 comments on commit f64b6b9

Please sign in to comment.