Skip to content

Commit

Permalink
Merge pull request #82 from replicatedhq/divolgin/data
Browse files Browse the repository at this point in the history
support for data collector
  • Loading branch information
divolgin committed Nov 12, 2019
2 parents cd43fd6 + 353569d commit 58ed4c8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/apis/troubleshoot/v1beta1/collector_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
}
21 changes: 21 additions & 0 deletions pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/collect/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/collect/data.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 58ed4c8

Please sign in to comment.