Skip to content

feat: add skipRedaction to collector spec [WIP] #1774

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion cmd/troubleshoot/cli/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ For more information on redactors visit https://troubleshoot.sh/docs/redact/
}

// 4. Perform redaction on the bundle
err = collect.RedactResult(bundleDir, collectorResult, redactors)
err = collect.RedactResult(bundleDir, collectorResult, redactors, nil)
if err != nil {
return errors.Wrap(err, "failed to redact support bundle")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyze/node_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func (a *AnalyzeNodeResources) Analyze(getFile getCollectedFileContents, findFil
return []*AnalyzeResult{result}, nil
}

func (a *AnalyzeNodeResources) analyzeNodeResources(analyzer *troubleshootv1beta2.NodeResources, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) {
func (a *AnalyzeNodeResources) analyzeNodeResources(analyzer *troubleshootv1beta2.NodeResources, getFile getCollectedFileContents) (*AnalyzeResult, error) {

collected, err := getCollectedFileContents(fmt.Sprintf("%s/%s.json", constants.CLUSTER_RESOURCES_DIR, constants.CLUSTER_RESOURCES_NODES))
collected, err := getFile(fmt.Sprintf("%s/%s.json", constants.CLUSTER_RESOURCES_DIR, constants.CLUSTER_RESOURCES_NODES))
if err != nil {
return nil, errors.Wrap(err, "failed to get contents of nodes.json")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/troubleshoot/v1beta2/collector_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
type CollectorMeta struct {
CollectorName string `json:"collectorName,omitempty" yaml:"collectorName,omitempty"`
// +optional
Exclude *multitype.BoolOrString `json:"exclude,omitempty" yaml:"exclude,omitempty"`
Exclude *multitype.BoolOrString `json:"exclude,omitempty" yaml:"exclude,omitempty"`
SkipRedaction bool `json:"skipRedaction,omitempty" yaml:"skipRedaction,omitempty"`
}

type ClusterInfo struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
type HostCollectorMeta struct {
CollectorName string `json:"collectorName,omitempty" yaml:"collectorName,omitempty"`
// +optional
Exclude *multitype.BoolOrString `json:"exclude,omitempty" yaml:"exclude,omitempty"`
Exclude *multitype.BoolOrString `json:"exclude,omitempty" yaml:"exclude,omitempty"`
SkipRedaction bool `json:"skipRedaction,omitempty" yaml:"skipRedaction,omitempty"`
}

type CPU struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ func (c *CollectCeph) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectCeph) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

func (c *CollectCeph) Collect(progressChan chan<- interface{}) (CollectorResult, error) {
ctx := context.TODO()

Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (c *CollectCertificates) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectCertificates) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

func (c *CollectCertificates) Collect(progressChan chan<- interface{}) (CollectorResult, error) {

output := NewResult()
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/cluster_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (c *CollectClusterInfo) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectClusterInfo) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

func (c *CollectClusterInfo) Collect(progressChan chan<- interface{}) (CollectorResult, error) {
client, err := kubernetes.NewForConfig(c.ClientConfig)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/cluster_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func (c *CollectClusterResources) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectClusterResources) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

func (c *CollectClusterResources) Merge(allCollectors []Collector) ([]Collector, error) {
var result []Collector
uniqueNamespaces := make(map[string]bool)
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/collectd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (c *CollectCollectd) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectCollectd) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

func (c *CollectCollectd) Collect(progressChan chan<- interface{}) (CollectorResult, error) {
copyFromHost := &troubleshootv1beta2.CopyFromHost{
CollectorMeta: c.Collector.CollectorMeta,
Expand Down
3 changes: 2 additions & 1 deletion pkg/collect/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type Collector interface {
Title() string
IsExcluded() (bool, error)
SkipRedaction() bool
GetRBACErrors() []error
HasRBACErrors() bool
CheckRBAC(ctx context.Context, c Collector, collector *troubleshootv1beta2.Collect, clientConfig *rest.Config, namespace string) error
Expand Down Expand Up @@ -52,7 +53,7 @@ func isExcluded(excludeVal *multitype.BoolOrString) (bool, error) {
return parsed, nil
}

func GetCollector(collector *troubleshootv1beta2.Collect, bundlePath string, namespace string, clientConfig *rest.Config, client kubernetes.Interface, sinceTime *time.Time) (interface{}, bool) {
func GetCollector(collector *troubleshootv1beta2.Collect, bundlePath string, namespace string, clientConfig *rest.Config, client kubernetes.Interface, sinceTime *time.Time) (Collector, bool) {

ctx := context.TODO()

Expand Down
8 changes: 3 additions & 5 deletions pkg/collect/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,15 @@ pwd=somethinggoeshere;`,

var result CollectorResult

collector, _ := GetCollector(tt.Collect, "", "", nil, nil, nil)
regCollector, _ := collector.(Collector)
regCollector, _ := GetCollector(tt.Collect, "", "", nil, nil, nil)

if excluded, err := regCollector.IsExcluded(); !excluded {
req.NoError(err)

result, err = regCollector.Collect(nil)
req.NoError(err)

err = RedactResult("", result, tt.Redactors)
err = RedactResult("", result, tt.Redactors, nil)

req.NoError(err)
}
Expand Down Expand Up @@ -346,8 +345,7 @@ pwd=somethinggoeshere;`,

var result CollectorResult

collector, _ := GetCollector(tt.Collect, "", "", nil, nil, nil)
regCollector, _ := collector.(Collector)
regCollector, _ := GetCollector(tt.Collect, "", "", nil, nil, nil)

if excluded, err := regCollector.IsExcluded(); !excluded {
req.NoError(err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func (c *CollectConfigMap) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectConfigMap) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

func (c *CollectConfigMap) Collect(progressChan chan<- interface{}) (CollectorResult, error) {
output := NewResult()

Expand Down
12 changes: 6 additions & 6 deletions pkg/collect/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (c *CollectCopy) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectCopy) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

// Copy function gets a file or folder from a container specified in the specs.
func (c *CollectCopy) Collect(progressChan chan<- interface{}) (CollectorResult, error) {
client, err := kubernetes.NewForConfig(c.ClientConfig)
Expand Down Expand Up @@ -101,10 +105,8 @@ func copyFilesFromPod(ctx context.Context, dstPath string, clientConfig *restcli
req.VersionedParams(&corev1.PodExecOptions{
Command: command,
Container: containerName,
Stdin: true,
Stdout: false,
Stdout: true,
Stderr: true,
TTY: false,
}, parameterCodec)

exec, err := remotecommand.NewSPDYExecutor(clientConfig, "POST", req.URL())
Expand Down Expand Up @@ -162,11 +164,9 @@ func copyFilesFromPod(ctx context.Context, dstPath string, clientConfig *restcli
}

var stderr bytes.Buffer
copyError = exec.Stream(remotecommand.StreamOptions{
Stdin: nil,
copyError = exec.StreamWithContext(ctx, remotecommand.StreamOptions{
Stdout: stdoutWriter,
Stderr: &stderr,
Tty: false,
})
if copyError != nil {
return result, stderr.Bytes(), errors.Wrap(copyError, "failed to stream command output")
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/copy_from_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (c *CollectCopyFromHost) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectCopyFromHost) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

// copies a file or directory from a host or hosts to include in the bundle.
func (c *CollectCopyFromHost) Collect(progressChan chan<- interface{}) (CollectorResult, error) {
var namespace string
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func (c *CollectData) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectData) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

func (c *CollectData) Collect(progressChan chan<- interface{}) (CollectorResult, error) {
bundlePath := filepath.Join(c.Collector.Name, c.Collector.CollectorName)

Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (c *CollectDNS) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectDNS) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

func (c *CollectDNS) Collect(progressChan chan<- interface{}) (CollectorResult, error) {

ctx, cancel := context.WithTimeout(c.Context, time.Duration(60*time.Second))
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (c *CollectEtcd) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectEtcd) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

func (c *CollectEtcd) Collect(progressChan chan<- interface{}) (CollectorResult, error) {
debugInstance := etcdDebug{
context: c.Context,
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func (c *CollectExec) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectExec) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

func (c *CollectExec) Collect(progressChan chan<- interface{}) (CollectorResult, error) {
if c.Collector.Timeout == "" {
return execWithoutTimeout(c.ClientConfig, c.BundlePath, c.Collector)
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/goldpinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (c *CollectGoldpinger) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectGoldpinger) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

func (c *CollectGoldpinger) Collect(progressChan chan<- interface{}) (CollectorResult, error) {
output := NewResult()
var results []byte
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (c *CollectHelm) IsExcluded() (bool, error) {
return isExcluded(c.Collector.Exclude)
}

func (c *CollectHelm) SkipRedaction() bool {
return c.Collector.SkipRedaction
}

func (c *CollectHelm) Collect(progressChan chan<- interface{}) (CollectorResult, error) {

output := NewResult()
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/host_block_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (c *CollectHostBlockDevices) IsExcluded() (bool, error) {
return isExcluded(c.hostCollector.Exclude)
}

func (c *CollectHostBlockDevices) SkipRedaction() bool {
return c.hostCollector.SkipRedaction
}

func (c *CollectHostBlockDevices) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
cmd := exec.Command("lsblk", "--noheadings", "--bytes", "--pairs", "-o", lsblkColumns)
stdout, err := cmd.Output()
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/host_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func (c *CollectHostCertificate) IsExcluded() (bool, error) {
return isExcluded(c.hostCollector.Exclude)
}

func (c *CollectHostCertificate) SkipRedaction() bool {
return c.hostCollector.SkipRedaction
}

func (c *CollectHostCertificate) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
var result = KeyPairValid

Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/host_certificates_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func (c *CollectHostCertificatesCollection) IsExcluded() (bool, error) {
return isExcluded(c.hostCollector.Exclude)
}

func (c *CollectHostCertificatesCollection) SkipRedaction() bool {
return c.hostCollector.SkipRedaction
}

func (c *CollectHostCertificatesCollection) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
var results []HostCertificatesCollection

Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/host_cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func (c *CollectHostCGroups) IsExcluded() (bool, error) {
return isExcluded(c.hostCollector.Exclude)
}

func (c *CollectHostCGroups) SkipRedaction() bool {
return c.hostCollector.SkipRedaction
}

func (c *CollectHostCGroups) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
// https://man7.org/linux/man-pages/man7/cgroups.7.html
// Implementation is based on https://github.com/k0sproject/k0s/blob/main/internal/pkg/sysinfo/probes/linux/cgroups.go
Expand Down
1 change: 1 addition & 0 deletions pkg/collect/host_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
type HostCollector interface {
Title() string
IsExcluded() (bool, error)
SkipRedaction() bool
Collect(progressChan chan<- interface{}) (map[string][]byte, error)
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/host_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func (c *CollectHostCopy) IsExcluded() (bool, error) {
return isExcluded(c.hostCollector.Exclude)
}

func (c *CollectHostCopy) SkipRedaction() bool {
return c.hostCollector.SkipRedaction
}

func (c *CollectHostCopy) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
// 1. Construct subdirectory path in the bundle path to copy files into
// output.SaveResult() will create the directory if it doesn't exist
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/host_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (c *CollectHostCPU) IsExcluded() (bool, error) {
return isExcluded(c.hostCollector.Exclude)
}

func (c *CollectHostCPU) SkipRedaction() bool {
return c.hostCollector.SkipRedaction
}

func (c *CollectHostCPU) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
cpuInfo := CPUInfo{}

Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/host_disk_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func (c *CollectHostDiskUsage) IsExcluded() (bool, error) {
return isExcluded(c.hostCollector.Exclude)
}

func (c *CollectHostDiskUsage) SkipRedaction() bool {
return c.hostCollector.SkipRedaction
}

func (c *CollectHostDiskUsage) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
result := map[string][]byte{}

Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/host_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func (c *CollectHostDNS) IsExcluded() (bool, error) {
return isExcluded(c.hostCollector.Exclude)
}

func (c *CollectHostDNS) SkipRedaction() bool {
return c.hostCollector.SkipRedaction
}

func (c *CollectHostDNS) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {

names := c.hostCollector.Hostnames
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/host_filesystem_performance.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (c *CollectHostFilesystemPerformance) IsExcluded() (bool, error) {
return isExcluded(c.hostCollector.Exclude)
}

func (c *CollectHostFilesystemPerformance) SkipRedaction() bool {
return c.hostCollector.SkipRedaction
}

func (c *CollectHostFilesystemPerformance) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
return collectHostFilesystemPerformance(c.hostCollector, c.BundlePath)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/host_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func (c *CollectHostHTTP) IsExcluded() (bool, error) {
return isExcluded(c.hostCollector.Exclude)
}

func (c *CollectHostHTTP) SkipRedaction() bool {
return c.hostCollector.SkipRedaction
}

func (c *CollectHostHTTP) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
httpCollector := c.hostCollector

Expand Down
4 changes: 4 additions & 0 deletions pkg/collect/host_httploadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func (c *CollectHostHTTPLoadBalancer) IsExcluded() (bool, error) {
return isExcluded(c.hostCollector.Exclude)
}

func (c *CollectHostHTTPLoadBalancer) SkipRedaction() bool {
return c.hostCollector.SkipRedaction
}

func (c *CollectHostHTTPLoadBalancer) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
listenAddress := fmt.Sprintf("0.0.0.0:%d", c.hostCollector.Port)

Expand Down
Loading
Loading