diff --git a/pkg/apis/troubleshoot/v1beta1/collector_shared.go b/pkg/apis/troubleshoot/v1beta1/collector_shared.go index 98410a23..e75d7c1a 100644 --- a/pkg/apis/troubleshoot/v1beta1/collector_shared.go +++ b/pkg/apis/troubleshoot/v1beta1/collector_shared.go @@ -32,6 +32,12 @@ type Logs struct { Limits *LogLimits `json:"limits,omitempty" yaml:"omitempty"` } +type Data struct { + CollectorMeta `json:",inline" yaml:",inline"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` + Data string `json:"data" yaml:"data"` +} + type Run struct { CollectorMeta `json:",inline" yaml:",inline"` Name string `json:"name,omitempty" yaml:"name,omitempty"` @@ -98,6 +104,7 @@ type Collect struct { Logs *Logs `json:"logs,omitempty" yaml:"logs,omitempty"` Run *Run `json:"run,omitempty" yaml:"run,omitempty"` Exec *Exec `json:"exec,omitempty" yaml:"exec,omitempty"` + Data *Data `json:"data,omitempty" yaml:"data,omitempty"` Copy *Copy `json:"copy,omitempty" yaml:"copy,omitempty"` HTTP *HTTP `json:"http,omitempty" yaml:"http,omitempty"` } diff --git a/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go b/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go index 3b2950e8..ea330dfa 100644 --- a/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go @@ -435,6 +435,11 @@ func (in *Collect) DeepCopyInto(out *Collect) { *out = new(Exec) (*in).DeepCopyInto(*out) } + if in.Data != nil { + in, out := &in.Data, &out.Data + *out = new(Data) + **out = **in + } if in.Copy != nil { in, out := &in.Copy, &out.Copy *out = new(Copy) @@ -778,6 +783,22 @@ func (in *CustomResourceDefinition) DeepCopy() *CustomResourceDefinition { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Data) DeepCopyInto(out *Data) { + *out = *in + out.CollectorMeta = in.CollectorMeta +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Data. +func (in *Data) DeepCopy() *Data { + if in == nil { + return nil + } + out := new(Data) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DeploymentStatus) DeepCopyInto(out *DeploymentStatus) { *out = *in diff --git a/pkg/collect/collector.go b/pkg/collect/collector.go index f997c8bc..a07b0f82 100644 --- a/pkg/collect/collector.go +++ b/pkg/collect/collector.go @@ -40,6 +40,9 @@ func (c *Collector) RunCollectorSync() ([]byte, error) { if c.Collect.Exec != nil { return Exec(c.GetContext(), c.Collect.Exec) } + if c.Collect.Data != nil { + return Data(c.GetContext(), c.Collect.Data) + } if c.Collect.Copy != nil { return Copy(c.GetContext(), c.Collect.Copy) } diff --git a/pkg/collect/data.go b/pkg/collect/data.go new file mode 100644 index 00000000..8c40548f --- /dev/null +++ b/pkg/collect/data.go @@ -0,0 +1,24 @@ +package collect + +import ( + "encoding/json" + "path/filepath" + + troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1" +) + +type DataOutput map[string][]byte + +func Data(ctx *Context, dataCollector *troubleshootv1beta1.Data) ([]byte, error) { + bundlePath := filepath.Join(dataCollector.Name, dataCollector.CollectorName) + dataOutput := DataOutput{ + bundlePath: []byte(dataCollector.Data), + } + + b, err := json.MarshalIndent(dataOutput, "", " ") + if err != nil { + return nil, err + } + + return b, nil +}