mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
Redact Host Collectors in Support Bundles (#614)
Add redactors for Host Collectors
This commit is contained in:
@@ -293,7 +293,7 @@ func (c *Collector) RunCollectorSync(clientConfig *rest.Config, client kubernete
|
||||
}
|
||||
|
||||
if c.Redact {
|
||||
err = redactResult(c.BundlePath, result, globalRedactors)
|
||||
err = RedactResult(c.BundlePath, result, globalRedactors)
|
||||
err = errors.Wrap(err, "failed to redact")
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/replicatedhq/troubleshoot/pkg/redact"
|
||||
)
|
||||
|
||||
func redactResult(bundlePath string, input CollectorResult, additionalRedactors []*troubleshootv1beta2.Redact) error {
|
||||
func RedactResult(bundlePath string, input CollectorResult, additionalRedactors []*troubleshootv1beta2.Redact) error {
|
||||
for k, v := range input {
|
||||
var reader io.Reader
|
||||
if v == nil {
|
||||
@@ -46,7 +46,7 @@ func redactResult(bundlePath string, input CollectorResult, additionalRedactors
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to decompress file")
|
||||
}
|
||||
err = redactResult(tmpDir, subResult, additionalRedactors)
|
||||
err = RedactResult(tmpDir, subResult, additionalRedactors)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to redact file")
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ func (c *RemoteCollector) RunCollectorSync(globalRedactors []*troubleshootv1beta
|
||||
return result, nil
|
||||
}
|
||||
|
||||
if err = redactResult("", result, globalRedactors); err != nil {
|
||||
if err = RedactResult("", result, globalRedactors); err != nil {
|
||||
// Returning result on error to be consistent with local collector.
|
||||
return result, errors.Wrap(err, "failed to redact")
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
func runHostCollectors(opts SupportBundleCreateOpts, hostCollectors []*troubleshootv1beta2.HostCollect, bundlePath string) (collect.CollectorResult, error) {
|
||||
func runHostCollectors(hostCollectors []*troubleshootv1beta2.HostCollect, additionalRedactors *troubleshootv1beta2.Redactor, bundlePath string, opts SupportBundleCreateOpts) (collect.CollectorResult, error) {
|
||||
collectSpecs := make([]*troubleshootv1beta2.HostCollect, 0, 0)
|
||||
collectSpecs = append(collectSpecs, hostCollectors...)
|
||||
|
||||
@@ -54,6 +54,19 @@ func runHostCollectors(opts SupportBundleCreateOpts, hostCollectors []*troublesh
|
||||
|
||||
collectResult = allCollectedData
|
||||
|
||||
globalRedactors := []*troubleshootv1beta2.Redact{}
|
||||
if additionalRedactors != nil {
|
||||
globalRedactors = additionalRedactors.Spec.Redactors
|
||||
}
|
||||
|
||||
if opts.Redact {
|
||||
err := collect.RedactResult(bundlePath, collectResult, globalRedactors)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "failed to redact")
|
||||
return collectResult, err
|
||||
}
|
||||
}
|
||||
|
||||
return collectResult, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ func CollectSupportBundleFromSpec(spec *troubleshootv1beta2.SupportBundleSpec, a
|
||||
return nil, errors.Wrap(err, "create bundle dir")
|
||||
}
|
||||
|
||||
hostFiles, err := runHostCollectors(opts, spec.HostCollectors, bundlePath)
|
||||
hostFiles, err := runHostCollectors(spec.HostCollectors, additionalRedactors, bundlePath, opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to run host collectors")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user