Skip to content

Commit 785c3e9

Browse files
committed
Moor redact
1 parent 7416987 commit 785c3e9

16 files changed

+299
-97
lines changed

config/crds/troubleshoot.replicated.com_collectors.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,29 @@ spec:
415415
required:
416416
- selector
417417
type: object
418+
run:
419+
properties:
420+
args:
421+
items:
422+
type: string
423+
type: array
424+
command:
425+
items:
426+
type: string
427+
type: array
428+
image:
429+
type: string
430+
name:
431+
type: string
432+
namespace:
433+
type: string
434+
timeout:
435+
type: string
436+
required:
437+
- name
438+
- namespace
439+
- image
440+
type: object
418441
secret:
419442
properties:
420443
includeValue:

config/crds/troubleshoot.replicated.com_preflights.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,29 @@ spec:
637637
required:
638638
- selector
639639
type: object
640+
run:
641+
properties:
642+
args:
643+
items:
644+
type: string
645+
type: array
646+
command:
647+
items:
648+
type: string
649+
type: array
650+
image:
651+
type: string
652+
name:
653+
type: string
654+
namespace:
655+
type: string
656+
timeout:
657+
type: string
658+
required:
659+
- name
660+
- namespace
661+
- image
662+
type: object
640663
secret:
641664
properties:
642665
includeValue:

config/crds/zz_generated.deepcopy.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ func (in *Collect) DeepCopyInto(out *Collect) {
348348
*out = new(Logs)
349349
(*in).DeepCopyInto(*out)
350350
}
351+
if in.Run != nil {
352+
in, out := &in.Run, &out.Run
353+
*out = new(Run)
354+
(*in).DeepCopyInto(*out)
355+
}
351356
}
352357

353358
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Collect.
@@ -934,6 +939,31 @@ func (in *PreflightStatus) DeepCopy() *PreflightStatus {
934939
return out
935940
}
936941

942+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
943+
func (in *Run) DeepCopyInto(out *Run) {
944+
*out = *in
945+
if in.Command != nil {
946+
in, out := &in.Command, &out.Command
947+
*out = make([]string, len(*in))
948+
copy(*out, *in)
949+
}
950+
if in.Args != nil {
951+
in, out := &in.Args, &out.Args
952+
*out = make([]string, len(*in))
953+
copy(*out, *in)
954+
}
955+
}
956+
957+
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Run.
958+
func (in *Run) DeepCopy() *Run {
959+
if in == nil {
960+
return nil
961+
}
962+
out := new(Run)
963+
in.DeepCopyInto(out)
964+
return out
965+
}
966+
937967
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
938968
func (in *Secret) DeepCopyInto(out *Secret) {
939969
*out = *in

config/samples/troubleshoot_v1beta1_collector.yaml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ spec:
99
# name: illmannered-cricket-mysql
1010
# namespace: default
1111
# key: mysql-password
12-
- logs:
13-
selector:
14-
- name=nginx-ingress-microk8s
12+
# - logs:
13+
# selector:
14+
# - name=nginx-ingress-microk8s
15+
# namespace: default
16+
# limits:
17+
# maxAge: 30d
18+
# maxLines: 10000
19+
- run:
20+
name: ping-google
1521
namespace: default
16-
limits:
17-
maxAge: 30d
18-
maxLines: 10000
22+
image: ubuntu:latest
23+
command: ["ping"]
24+
args: ["www.google.com"]
25+
timeout: 5s

pkg/apis/troubleshoot/v1beta1/collector_shared.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,19 @@ type Logs struct {
2424
Limits *LogLimits `json:"limits,omitempty" yaml:"omitempty"`
2525
}
2626

27+
type Run struct {
28+
Name string `json:"name" yaml:"name"`
29+
Namespace string `json:"namespace" yaml:"namespace"`
30+
Image string `json:"image" yaml:"image"`
31+
Command []string `json:"command,omitempty" yaml:"command,omitempty"`
32+
Args []string `json:"args,omitempty" yaml:"args,omitempty"`
33+
Timeout string `json:"timeout,omitempty" yaml:"timeout,omitempty"`
34+
}
35+
2736
type Collect struct {
2837
ClusterInfo *ClusterInfo `json:"clusterInfo,omitempty" yaml:"clusterInfo,omitempty"`
2938
ClusterResources *ClusterResources `json:"clusterResources,omitempty" yaml:"clusterResources,omitempty"`
3039
Secret *Secret `json:"secret,omitempty" yaml:"secret,omitempty"`
3140
Logs *Logs `json:"logs,omitempty" yaml:"logs,omitempty"`
41+
Run *Run `json:"run,omitempty" yaml:"run,omitempty"`
3242
}

pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ func (in *Collect) DeepCopyInto(out *Collect) {
364364
*out = new(Logs)
365365
(*in).DeepCopyInto(*out)
366366
}
367+
if in.Run != nil {
368+
in, out := &in.Run, &out.Run
369+
*out = new(Run)
370+
(*in).DeepCopyInto(*out)
371+
}
367372
}
368373

369374
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Collect.
@@ -950,6 +955,31 @@ func (in *PreflightStatus) DeepCopy() *PreflightStatus {
950955
return out
951956
}
952957

958+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
959+
func (in *Run) DeepCopyInto(out *Run) {
960+
*out = *in
961+
if in.Command != nil {
962+
in, out := &in.Command, &out.Command
963+
*out = make([]string, len(*in))
964+
copy(*out, *in)
965+
}
966+
if in.Args != nil {
967+
in, out := &in.Args, &out.Args
968+
*out = make([]string, len(*in))
969+
copy(*out, *in)
970+
}
971+
}
972+
973+
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Run.
974+
func (in *Run) DeepCopy() *Run {
975+
if in == nil {
976+
return nil
977+
}
978+
out := new(Run)
979+
in.DeepCopyInto(out)
980+
return out
981+
}
982+
953983
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
954984
func (in *Secret) DeepCopyInto(out *Secret) {
955985
*out = *in

pkg/collect/cluster_resources.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,3 @@ func (c *ClusterResourcesOutput) Redact() (*ClusterResourcesOutput, error) {
270270
CustomResourceDefinitions: crds,
271271
}, nil
272272
}
273-
274-
func redactMap(input map[string][]byte) (map[string][]byte, error) {
275-
result := make(map[string][]byte)
276-
for k, v := range input {
277-
redacted, err := redact.Redact(v)
278-
if err != nil {
279-
return nil, err
280-
}
281-
result[k] = redacted
282-
}
283-
return result, nil
284-
}

pkg/collect/collector.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ func (c *Collector) RunCollectorSync() error {
2525
return ClusterResources(c.Redact)
2626
}
2727
if collect.Secret != nil {
28-
return Secret(collect.Secret)
28+
return Secret(collect.Secret, c.Redact)
2929
}
3030
if collect.Logs != nil {
31-
return Logs(collect.Logs)
31+
return Logs(collect.Logs, c.Redact)
32+
}
33+
if collect.Run != nil {
34+
return Run(collect.Run, c.Redact)
3235
}
3336

3437
return errors.New("no spec found to run")

pkg/collect/logs.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type LogsOutput struct {
1919
PodLogs map[string][]byte `json:"logs/,omitempty"`
2020
}
2121

22-
func Logs(logsCollector *troubleshootv1beta1.Logs) error {
22+
func Logs(logsCollector *troubleshootv1beta1.Logs, redact bool) error {
2323
cfg, err := config.GetConfig()
2424
if err != nil {
2525
return err
@@ -35,7 +35,7 @@ func Logs(logsCollector *troubleshootv1beta1.Logs) error {
3535
return err
3636
}
3737

38-
logsOutput := LogsOutput{
38+
logsOutput := &LogsOutput{
3939
PodLogs: make(map[string][]byte),
4040
}
4141
for _, pod := range pods {
@@ -49,6 +49,13 @@ func Logs(logsCollector *troubleshootv1beta1.Logs) error {
4949
}
5050
}
5151

52+
if redact {
53+
logsOutput, err = logsOutput.Redact()
54+
if err != nil {
55+
return err
56+
}
57+
}
58+
5259
b, err := json.MarshalIndent(logsOutput, "", " ")
5360
if err != nil {
5461
return err
@@ -114,3 +121,14 @@ func getPodLogs(client *kubernetes.Clientset, pod corev1.Pod, limits *troublesho
114121
fmt.Sprintf("%s/%s.txt", pod.Namespace, pod.Name): buf.Bytes(),
115122
}, nil
116123
}
124+
125+
func (l *LogsOutput) Redact() (*LogsOutput, error) {
126+
podLogs, err := redactMap(l.PodLogs)
127+
if err != nil {
128+
return nil, err
129+
}
130+
131+
return &LogsOutput{
132+
PodLogs: podLogs,
133+
}, nil
134+
}

pkg/collect/redact.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package collect
2+
3+
import (
4+
"github.com/replicatedhq/troubleshoot/pkg/redact"
5+
)
6+
7+
func redactMap(input map[string][]byte) (map[string][]byte, error) {
8+
result := make(map[string][]byte)
9+
for k, v := range input {
10+
redacted, err := redact.Redact(v)
11+
if err != nil {
12+
return nil, err
13+
}
14+
result[k] = redacted
15+
}
16+
return result, nil
17+
}

0 commit comments

Comments
 (0)