Skip to content
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

feat(support-bundle): add runHostCollectorsInPod in spec #1608

Merged
merged 20 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 4 additions & 3 deletions pkg/collect/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
var (
// ErrCollectorNotFound is returned when an undefined host collector is
// specified by the user.
ErrHostCollectorNotFound = errors.New("unrecognized host collector")
ErrInsufficientPermissionsToRun = errors.New("insufficient permissions to run all collectors")
ErrHostCollectorNotFound = errors.New("unrecognized host collector")
ErrInsufficientPermissionsToRun = errors.New("insufficient permissions to run all collectors")
ErrRemoteCollectorNotImplemented = errors.New("unimplemented remote collector")
)

type CollectorRunOpts struct {
Expand All @@ -28,7 +29,7 @@ type CollectorRunOpts struct {
PullPolicy string
LabelSelector string
Timeout time.Duration
ProgressChan chan interface{}
ProgressChan chan<- interface{}
NamePrefix string
}

Expand Down
6 changes: 1 addition & 5 deletions pkg/collect/host_block_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,5 @@ func parseLsblkOutput(output []byte) ([]BlockDeviceInfo, error) {
}

func (c *CollectHostBlockDevices) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostBlockDevices) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
8 changes: 1 addition & 7 deletions pkg/collect/host_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"path/filepath"
"strings"

"github.com/pkg/errors"

troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
)

Expand Down Expand Up @@ -81,9 +79,5 @@ func isEncryptedKey(filename string) (bool, error) {
}

func (c *CollectHostCertificate) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostCertificate) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
7 changes: 1 addition & 6 deletions pkg/collect/host_certificates_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"
"time"

"github.com/pkg/errors"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
)

Expand Down Expand Up @@ -107,9 +106,5 @@ func HostCertsParser(certPath string) HostCertificatesCollection {
}

func (c *CollectHostCertificatesCollection) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostCertificatesCollection) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
7 changes: 1 addition & 6 deletions pkg/collect/host_cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"io"
"strings"

"github.com/pkg/errors"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -100,9 +99,5 @@ func parseV1ControllerNames(r io.Reader) ([]string, error) {
}

func (c *CollectHostCGroups) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostCGroups) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
1 change: 0 additions & 1 deletion pkg/collect/host_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ type HostCollector interface {
IsExcluded() (bool, error)
Collect(progressChan chan<- interface{}) (map[string][]byte, error)
RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) // RemoteCollect is used to priviledge pods to collect data from different nodes
HasRemoted() bool // HasRemoted returns true if the collector has a remote collector implementation
}

func GetHostCollector(collector *troubleshootv1beta2.HostCollect, bundlePath string) (HostCollector, bool) {
Expand Down
7 changes: 1 addition & 6 deletions pkg/collect/host_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"path/filepath"
"strings"

"github.com/pkg/errors"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -140,9 +139,5 @@ func (c *CollectHostCopy) copyDir(src, dst string, result CollectorResult) error
}

func (c *CollectHostCopy) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostCopy) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,5 @@ func (c *CollectHostCPU) Collect(progressChan chan<- interface{}) (map[string][]
}

func (c *CollectHostCPU) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostCPU) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_disk_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,5 @@ func traverseFiletreeDirExists(filename string) (string, error) {
}

func (c *CollectHostDiskUsage) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostDiskUsage) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_filesystem_performance.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,5 @@ func collectFioResults(ctx context.Context, hostCollector *troubleshootv1beta2.F
}

func (c *CollectHostFilesystemPerformance) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostFilesystemPerformance) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,5 @@ func (c *CollectHostHTTP) Collect(progressChan chan<- interface{}) (map[string][
}

func (c *CollectHostHTTP) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostHTTP) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_httploadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,5 @@ func attemptPOST(address string, request []byte, response []byte) NetworkStatus
}

func (c *CollectHostHTTPLoadBalancer) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostHTTPLoadBalancer) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_ipv4interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,5 @@ func (c *CollectHostIPV4Interfaces) Collect(progressChan chan<- interface{}) (ma
}

func (c *CollectHostIPV4Interfaces) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostIPV4Interfaces) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_journald.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,5 @@ func getTimeout(timeout string) (time.Duration, error) {
}

func (c *CollectHostJournald) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostJournald) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_kernel_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,5 @@ func parseKConfigs(r io.Reader) (KConfigs, error) {
}

func (c *CollectHostKernelConfigs) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostKernelConfigs) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_kernel_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,5 @@ func (l kernelModulesLoaded) collect() (map[string]KernelModuleInfo, error) {
}

func (c *CollectHostKernelModules) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostKernelModules) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,5 @@ func (c *CollectHostMemory) Collect(progressChan chan<- interface{}) (map[string
}

func (c *CollectHostMemory) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostMemory) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
15 changes: 2 additions & 13 deletions pkg/collect/host_os_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type HostOSInfo struct {
const HostOSInfoPath = `host-collectors/system/hostos_info.json`

type NodeInfo struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot see where this is used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

HostOSInfo HostOSInfo `json:"host-collectors/system/hostos_info.json"`
HostOSInfo HostOSInfo
}
type CollectHostOS struct {
hostCollector *troubleshootv1beta2.HostOS
Expand Down Expand Up @@ -63,20 +63,13 @@ func (c *CollectHostOS) RemoteCollect(progressChan chan<- interface{}) (map[stri
return nil, errors.Wrap(err, "failed to convert kube flags to rest config")
}

progressCh := make(chan interface{})
defer close(progressCh)
go func() {
for range progressCh {
}
}()

createOpts := CollectorRunOpts{
KubernetesRestConfig: restConfig,
Image: "replicated/troubleshoot:latest",
Namespace: "default",
Timeout: defaultTimeout,
NamePrefix: "hostos-remote",
ProgressChan: progressCh,
ProgressChan: progressChan,
}

remoteCollector := &troubleshootv1beta2.RemoteCollector{
Expand Down Expand Up @@ -122,7 +115,3 @@ func (c *CollectHostOS) RemoteCollect(progressChan chan<- interface{}) (map[stri

return nil, errors.New("failed to find host os info")
}

func (c *CollectHostOS) HasRemoted() bool {
return true
}
6 changes: 1 addition & 5 deletions pkg/collect/host_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,5 @@ func (c *CollectHostRun) attemptToConvertCmdToAbsPath() string {
}

func (c *CollectHostRun) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostRun) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,5 @@ func (c *CollectHostServices) Collect(progressChan chan<- interface{}) (map[stri
}

func (c *CollectHostServices) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostServices) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_subnetavailable.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,5 @@ func netOverlaps(n1, n2 *net.IPNet) bool {
}

func (c *CollectHostSubnetAvailable) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostSubnetAvailable) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_system_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,5 @@ func matchMajorVersion(version string, major string) bool {
}

func (c *CollectHostSystemPackages) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostSystemPackages) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_tcp_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,5 @@ func attemptConnect(address string, timeout time.Duration) NetworkStatus {
}

func (c *CollectHostTCPConnect) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostTCPConnect) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_tcploadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,5 @@ func (c *CollectHostTCPLoadBalancer) Collect(progressChan chan<- interface{}) (m
}

func (c *CollectHostTCPLoadBalancer) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostTCPLoadBalancer) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_tcpportstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,5 @@ func getLocalIPv4() (net.IP, error) {
}

func (c *CollectHostTCPPortStatus) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostTCPPortStatus) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,5 @@ func (c *CollectHostTime) Collect(progressChan chan<- interface{}) (map[string][
}

func (c *CollectHostTime) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostTime) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
6 changes: 1 addition & 5 deletions pkg/collect/host_udpportstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,5 @@ func (c *CollectHostUDPPortStatus) Collect(progressChan chan<- interface{}) (map
}

func (c *CollectHostUDPPortStatus) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
return nil, errors.New("not implemented")
}

func (c *CollectHostUDPPortStatus) HasRemoted() bool {
return false
return nil, ErrRemoteCollectorNotImplemented
}
Loading
Loading