Skip to content

Commit cab3fc7

Browse files
Redact Host Collectors in Support Bundles (#614)
Add redactors for Host Collectors
1 parent 3ff0e82 commit cab3fc7

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

pkg/collect/collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (c *Collector) RunCollectorSync(clientConfig *rest.Config, client kubernete
293293
}
294294

295295
if c.Redact {
296-
err = redactResult(c.BundlePath, result, globalRedactors)
296+
err = RedactResult(c.BundlePath, result, globalRedactors)
297297
err = errors.Wrap(err, "failed to redact")
298298
}
299299

pkg/collect/redact.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/replicatedhq/troubleshoot/pkg/redact"
1616
)
1717

18-
func redactResult(bundlePath string, input CollectorResult, additionalRedactors []*troubleshootv1beta2.Redact) error {
18+
func RedactResult(bundlePath string, input CollectorResult, additionalRedactors []*troubleshootv1beta2.Redact) error {
1919
for k, v := range input {
2020
var reader io.Reader
2121
if v == nil {
@@ -46,7 +46,7 @@ func redactResult(bundlePath string, input CollectorResult, additionalRedactors
4646
if err != nil {
4747
return errors.Wrap(err, "failed to decompress file")
4848
}
49-
err = redactResult(tmpDir, subResult, additionalRedactors)
49+
err = RedactResult(tmpDir, subResult, additionalRedactors)
5050
if err != nil {
5151
return errors.Wrap(err, "failed to redact file")
5252
}

pkg/collect/remote_collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (c *RemoteCollector) RunCollectorSync(globalRedactors []*troubleshootv1beta
107107
return result, nil
108108
}
109109

110-
if err = redactResult("", result, globalRedactors); err != nil {
110+
if err = RedactResult("", result, globalRedactors); err != nil {
111111
// Returning result on error to be consistent with local collector.
112112
return result, errors.Wrap(err, "failed to redact")
113113
}

pkg/supportbundle/collect.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"k8s.io/client-go/kubernetes"
2121
)
2222

23-
func runHostCollectors(opts SupportBundleCreateOpts, hostCollectors []*troubleshootv1beta2.HostCollect, bundlePath string) (collect.CollectorResult, error) {
23+
func runHostCollectors(hostCollectors []*troubleshootv1beta2.HostCollect, additionalRedactors *troubleshootv1beta2.Redactor, bundlePath string, opts SupportBundleCreateOpts) (collect.CollectorResult, error) {
2424
collectSpecs := make([]*troubleshootv1beta2.HostCollect, 0, 0)
2525
collectSpecs = append(collectSpecs, hostCollectors...)
2626

@@ -54,6 +54,19 @@ func runHostCollectors(opts SupportBundleCreateOpts, hostCollectors []*troublesh
5454

5555
collectResult = allCollectedData
5656

57+
globalRedactors := []*troubleshootv1beta2.Redact{}
58+
if additionalRedactors != nil {
59+
globalRedactors = additionalRedactors.Spec.Redactors
60+
}
61+
62+
if opts.Redact {
63+
err := collect.RedactResult(bundlePath, collectResult, globalRedactors)
64+
if err != nil {
65+
err = errors.Wrap(err, "failed to redact")
66+
return collectResult, err
67+
}
68+
}
69+
5770
return collectResult, nil
5871
}
5972

pkg/supportbundle/supportbundle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func CollectSupportBundleFromSpec(spec *troubleshootv1beta2.SupportBundleSpec, a
8686
return nil, errors.Wrap(err, "create bundle dir")
8787
}
8888

89-
hostFiles, err := runHostCollectors(opts, spec.HostCollectors, bundlePath)
89+
hostFiles, err := runHostCollectors(spec.HostCollectors, additionalRedactors, bundlePath, opts)
9090
if err != nil {
9191
return nil, errors.Wrap(err, "failed to run host collectors")
9292
}

0 commit comments

Comments
 (0)