Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for data collector #82

Merged
merged 1 commit into from
Nov 12, 2019
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
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
}