Redact Host Collectors in Support Bundles (#614)

Add redactors for Host Collectors
This commit is contained in:
Diamon Wiggins
2022-07-01 18:57:58 -04:00
committed by GitHub
parent 3ff0e82fcc
commit cab3fc7f4e
5 changed files with 19 additions and 6 deletions
+1 -1
View File
@@ -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")
}
+2 -2
View File
@@ -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")
}
+1 -1
View 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")
}
+14 -1
View File
@@ -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
}
+1 -1
View File
@@ -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")
}