Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var generateCmd = &cobra.Command{

var bundlePath string
var skipDefault bool
var timeoutSeconds int

func init() {
RootCmd.AddCommand(generateCmd)
Expand All @@ -54,6 +55,7 @@ func init() {

generateCmd.Flags().StringVar(&bundlePath, "out", "supportbundle.tar.gz", "Path where the generated bundle should be stored")
generateCmd.Flags().BoolVarP(&skipDefault, "skipdefault", "s", false, "If present, skip the default support bundle files")
generateCmd.Flags().IntVar(&timeoutSeconds, "timeout", 60, "The overall support bundle generation timeout")
}

func generate(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -96,7 +98,7 @@ func generate(cmd *cobra.Command, args []string) error {

var tasks = planner.Plan(specs)

if err := bundle.Generate(tasks, time.Duration(time.Second*15), bundlePath); err != nil {
if err := bundle.Generate(tasks, time.Duration(time.Second*time.Duration(timeoutSeconds)), bundlePath); err != nil {
jww.ERROR.Fatal(err)
}

Expand Down
13 changes: 12 additions & 1 deletion plans/byte-source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plans
import (
"context"
"errors"
"time"

"github.com/replicatedcom/support-bundle/types"
)
Expand All @@ -27,6 +28,9 @@ type ByteSource struct {
// copy of the structured data. If HumanPath is defined and Parser is not,
// it will get a copy of the raw data.
HumanPath string
// If Timeout is defined, it will be used rather than the context provided
// to Exec.
Timeout time.Duration
}

func (task *ByteSource) Exec(ctx context.Context, rootDir string) []*types.Result {
Expand Down Expand Up @@ -63,7 +67,14 @@ func (task *ByteSource) Exec(ctx context.Context, rootDir string) []*types.Resul
return resultsWithErr(err, results)
}

data, err := task.Producer(ctx)
useCtx := ctx
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not

if task.Timeout != 0 {
    ctx, _ = context.WithTimeout(ctx, task.Timeout)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now changed

if task.Timeout != 0 {
var cancel context.CancelFunc
useCtx, cancel = context.WithTimeout(useCtx, task.Timeout)
defer cancel()
}

data, err := task.Producer(useCtx)
if err != nil {
return resultsWithErr(err, results)
}
Expand Down
13 changes: 12 additions & 1 deletion plans/stream-source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"io"
"os"
"time"

"github.com/replicatedcom/support-bundle/types"
)
Expand All @@ -21,6 +22,9 @@ type StreamSource struct {
JSONPath string
// If HumanPath is defined it will get a copy of the data
HumanPath string
// If Timeout is defined, it will be used rather than the context provided
// to Exec.
Timeout time.Duration
}

func (task *StreamSource) Exec(ctx context.Context, rootDir string) []*types.Result {
Expand Down Expand Up @@ -52,7 +56,14 @@ func (task *StreamSource) Exec(ctx context.Context, rootDir string) []*types.Res
return results
}

data, err := task.Producer(ctx)
useCtx := ctx
if task.Timeout != 0 {
var cancel context.CancelFunc
useCtx, cancel = context.WithTimeout(useCtx, task.Timeout)
defer cancel()
}

data, err := task.Producer(useCtx)
if err != nil {
return resultsWithErr(err, results)
}
Expand Down
13 changes: 12 additions & 1 deletion plans/structured-source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plans
import (
"context"
"errors"
"time"

"github.com/replicatedcom/support-bundle/types"
)
Expand All @@ -23,6 +24,9 @@ type StructuredSource struct {
// HumanPath is defined and a Template is not, it will get the data as
// YAML.
HumanPath string
// If Timeout is defined, it will be used rather than the context provided
// to Exec.
Timeout time.Duration
}

func (task *StructuredSource) Exec(ctx context.Context, rootDir string) []*types.Result {
Expand Down Expand Up @@ -52,7 +56,14 @@ func (task *StructuredSource) Exec(ctx context.Context, rootDir string) []*types
return resultsWithErr(err, results)
}

data, err := task.Producer(ctx)
useCtx := ctx
if task.Timeout != 0 {
var cancel context.CancelFunc
useCtx, cancel = context.WithTimeout(useCtx, task.Timeout)
defer cancel()
}

data, err := task.Producer(useCtx)
if err != nil {
return resultsWithErr(err, results)
}
Expand Down
5 changes: 5 additions & 0 deletions plugins/core/planners/read-command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package planners

import (
"errors"
"time"

"github.com/replicatedcom/support-bundle/plans"
"github.com/replicatedcom/support-bundle/plugins/core/producers"
Expand All @@ -23,5 +24,9 @@ func ReadCommand(spec types.Spec) []types.Task {
HumanPath: spec.Human,
}

if spec.TimeoutSeconds != 0 {
task.Timeout = time.Duration(spec.TimeoutSeconds) * time.Second
}

return []types.Task{task}
}
5 changes: 5 additions & 0 deletions plugins/core/planners/read-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package planners

import (
"errors"
"time"

"github.com/replicatedcom/support-bundle/plans"
"github.com/replicatedcom/support-bundle/plugins/core/producers"
Expand All @@ -23,5 +24,9 @@ func ReadFile(spec types.Spec) []types.Task {
HumanPath: spec.Human,
}

if spec.TimeoutSeconds != 0 {
task.Timeout = time.Duration(spec.TimeoutSeconds) * time.Second
}

return []types.Task{task}
}
6 changes: 6 additions & 0 deletions plugins/docker/planners/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package planners

import (
"path/filepath"
"time"

"github.com/replicatedcom/support-bundle/plans"
"github.com/replicatedcom/support-bundle/types"
Expand Down Expand Up @@ -32,6 +33,11 @@ func (d *Docker) Daemon(spec types.Spec) []types.Task {
HumanPath: maybePath(spec.Human, "docker_ps_all"),
}

if spec.TimeoutSeconds != 0 {
info.Timeout = time.Duration(spec.TimeoutSeconds) * time.Second
ps.Timeout = time.Duration(spec.TimeoutSeconds) * time.Second
}

return []types.Task{
info,
ps,
Expand Down
18 changes: 10 additions & 8 deletions plugins/docker/planners/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package planners

import (
"errors"
"time"

"github.com/replicatedcom/support-bundle/plans"
"github.com/replicatedcom/support-bundle/types"
Expand All @@ -15,20 +16,21 @@ func (d *Docker) Inspect(spec types.Spec) []types.Task {
return []types.Task{task}
}

producer := d.producers.Inspect(spec.Config.ContainerID)

if spec.Config.ContainerName != "" {
producer = d.producers.InspectName(spec.Config.ContainerName)
}

task := &plans.StructuredSource{
Producer: d.producers.Inspect(spec.Config.ContainerID),
Producer: producer,
RawPath: spec.Raw,
JSONPath: spec.JSON,
HumanPath: spec.Human,
}

if spec.Config.ContainerName != "" {
task = &plans.StructuredSource{
Producer: d.producers.InspectName(spec.Config.ContainerName),
RawPath: spec.Raw,
JSONPath: spec.JSON,
HumanPath: spec.Human,
}
if spec.TimeoutSeconds != 0 {
task.Timeout = time.Duration(spec.TimeoutSeconds) * time.Second
}

return []types.Task{task}
Expand Down
18 changes: 10 additions & 8 deletions plugins/docker/planners/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package planners

import (
"errors"
"time"

"github.com/replicatedcom/support-bundle/plans"
"github.com/replicatedcom/support-bundle/types"
Expand All @@ -15,20 +16,21 @@ func (d *Docker) Logs(spec types.Spec) []types.Task {
return []types.Task{task}
}

producer := d.producers.Logs(spec.Config.ContainerID)

if spec.Config.ContainerName != "" {
producer = d.producers.LogsName(spec.Config.ContainerName)
}

task := &plans.StreamSource{
Producer: d.producers.Logs(spec.Config.ContainerID),
Producer: producer,
RawPath: spec.Raw,
JSONPath: spec.JSON,
HumanPath: spec.Human,
}

if spec.Config.ContainerName != "" {
task = &plans.StreamSource{
Producer: d.producers.LogsName(spec.Config.ContainerName),
RawPath: spec.Raw,
JSONPath: spec.JSON,
HumanPath: spec.Human,
}
if spec.TimeoutSeconds != 0 {
task.Timeout = time.Duration(spec.TimeoutSeconds) * time.Second
}

return []types.Task{task}
Expand Down
18 changes: 10 additions & 8 deletions plugins/docker/planners/read-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package planners

import (
"errors"
"time"

"github.com/replicatedcom/support-bundle/plans"
"github.com/replicatedcom/support-bundle/types"
Expand All @@ -15,20 +16,21 @@ func (d *Docker) ReadFile(spec types.Spec) []types.Task {
return []types.Task{task}
}

producer := d.producers.ReadFile(spec.Config.ContainerID, spec.Config.FilePath)

if spec.Config.ContainerName != "" {
producer = d.producers.ReadFileByName(spec.Config.ContainerName, spec.Config.FilePath)
}

task := &plans.StreamSource{
Producer: d.producers.ReadFile(spec.Config.ContainerID, spec.Config.FilePath),
Producer: producer,
RawPath: spec.Raw,
JSONPath: spec.JSON,
HumanPath: spec.Human,
}

if spec.Config.ContainerName != "" {
task = &plans.StreamSource{
Producer: d.producers.ReadFileByName(spec.Config.ContainerName, spec.Config.FilePath),
RawPath: spec.Raw,
JSONPath: spec.JSON,
HumanPath: spec.Human,
}
if spec.TimeoutSeconds != 0 {
task.Timeout = time.Duration(spec.TimeoutSeconds) * time.Second
}

return []types.Task{task}
Expand Down
4 changes: 4 additions & 0 deletions plugins/docker/planners/run-command.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (d *Docker) RunCommand(spec types.Spec) []types.Task {
// }
// }

// if spec.TimeoutSeconds != 0 {
// task.Timeout = time.Duration(spec.TimeoutSeconds) * time.Second
// }

err := errors.New("This task type not yet implemented")
task := plans.PreparedError(err, spec)

Expand Down
2 changes: 1 addition & 1 deletion spec/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Doc struct {

func Parse(doc []byte) ([]types.Spec, error) {
d := &Doc{}
if err := yaml.Unmarshal(doc, d); err != nil {
if err := yaml.UnmarshalStrict(doc, d); err != nil {
return nil, errors.Wrap(err, "parse yaml spec")
}

Expand Down