Skip to content
Merged
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
32 changes: 29 additions & 3 deletions examples/collect/host/all-collectors.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
name: all-collectors-test
name: all-host-collectors
spec:
hostCollectors:
# System Info Collectors
Expand Down Expand Up @@ -46,25 +46,51 @@ spec:
fileSize: 10Mi
operationSizeBytes: 2300

# Certificate
# Certificate Collectors
- certificate:
collectorName: test-cert
certificatePath: /etc/ssl/certs/ca-certificates.crt
- certificatesCollection:
collectorName: certs-collection
paths:
- /etc/ssl/certs

# Network Tests
- tcpPortStatus:
collectorName: ssh-port
port: 22
- udpPortStatus:
collectorName: dns-port
port: 53
- tcpConnect:
collectorName: localhost-ssh
address: 127.0.0.1:22
- tcpLoadBalancer:
collectorName: lb-test
address: 127.0.0.1
port: 80
- httpLoadBalancer:
collectorName: http-lb-test
address: 127.0.0.1
port: 80
path: /healthz
- http:
collectorName: google
get:
url: https://www.google.com
- dns:
collectorName: dns-google
hostname: google.com
hostnames:
- google.com
- subnetAvailable:
collectorName: subnet-check
CIDRRangeAlloc: 10.0.0.0/16
desiredCIDR: 24
- networkNamespaceConnectivity:
collectorName: netns-connectivity
fromCIDR: 10.0.0.0/8
toCIDR: 192.168.0.0/16
port: 80

# Custom Commands
- run:
Expand Down
170 changes: 170 additions & 0 deletions examples/collect/host/all-kubernetes-collectors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
name: all-kubernetes-collectors
spec:
collectors:
# Cluster Info Collectors (2)
- clusterInfo: {}
- clusterResources: {}

# Metrics Collectors (2)
- customMetrics:
collectorName: custom-metrics
metricRequests:
- resourceMetricName: example-metric
- nodeMetrics: {}

# ConfigMap and Secret Collectors (2)
- configMap:
collectorName: example-configmap
name: example-configmap
namespace: default
includeValue: false
- secret:
collectorName: example-secret
name: example-secret
namespace: default
includeValue: false

# Logs Collector (1)
- logs:
collectorName: example-logs
selector:
- app=example
namespace: default
limits:
maxAge: 720h
maxLines: 10000

# Pod Execution Collectors (4)
- run:
collectorName: run-example
name: run-example
namespace: default
image: busybox:latest
command: ["echo"]
args: ["hello from run"]
- runPod:
collectorName: run-pod-example
name: run-pod-example
namespace: default
podSpec:
containers:
- name: example
image: busybox:latest
command: ["echo", "hello from runPod"]
- runDaemonSet:
collectorName: run-daemonset-example
name: run-daemonset-example
namespace: default
podSpec:
containers:
- name: example
image: busybox:latest
command: ["echo", "hello from runDaemonSet"]
- exec:
collectorName: exec-example
name: exec-example
selector:
- app=example
namespace: default
command: ["echo"]
args: ["hello from exec"]

# Data Collector (1)
- data:
collectorName: static-data
name: static-data.txt
data: "This is static data"

# Copy Collectors (2)
- copy:
collectorName: copy-example
selector:
- app=example
namespace: default
containerPath: /tmp
- copyFromHost:
collectorName: copy-from-host-example
name: copy-from-host-example
namespace: default
image: busybox:latest
hostPath: /tmp/example

# HTTP Collector (1)
- http:
collectorName: http-get-example
get:
url: https://www.google.com
insecureSkipVerify: false

# Database Collectors (4)
- postgres:
collectorName: postgres-example
uri: postgresql://user:password@localhost:5432/dbname
- mysql:
collectorName: mysql-example
uri: user:password@tcp(localhost:3306)/dbname
- mssql:
collectorName: mssql-example
uri: sqlserver://user:password@localhost:1433?database=dbname
- redis:
collectorName: redis-example
uri: redis://localhost:6379

# Storage and System Collectors (3)
- collectd:
collectorName: collectd-example
namespace: default
image: busybox:latest
hostPath: /var/lib/collectd
- ceph:
collectorName: ceph-example
namespace: rook-ceph
- longhorn:
collectorName: longhorn-example
namespace: longhorn-system

# Registry and Image Collector (1)
- registryImages:
collectorName: registry-images-example
namespace: default
images:
- busybox:latest

# Sysctl Collector (1)
- sysctl:
collectorName: sysctl-example
name: sysctl-example
namespace: default
image: busybox:latest

# Certificate Collector (1)
- certificates:
collectorName: certificates-example
secrets:
- name: tls-secret
namespaces:
- default

# Application-Specific Collectors (3)
- helm:
collectorName: helm-example
namespace: default
releaseName: example-release
collectValues: false
- goldpinger:
collectorName: goldpinger-example
namespace: default
- sonobuoy:
collectorName: sonobuoy-example
namespace: sonobuoy

# DNS and Network Collectors (2)
- dns:
collectorName: dns-example
timeout: 10s
- etcd:
collectorName: etcd-example
image: quay.io/coreos/etcd:latest
4 changes: 3 additions & 1 deletion pkg/collect/host_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ func (c *CollectHostCertificate) IsExcluded() (bool, error) {

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

_, err := tls.LoadX509KeyPair(c.hostCollector.CertificatePath, c.hostCollector.KeyPath)
if err != nil {
collectorErr = err
if strings.Contains(err.Error(), "no such file") {
result = KeyPairMissing
} else if strings.Contains(err.Error(), "PEM inputs may have been switched") {
Expand Down Expand Up @@ -67,7 +69,7 @@ func (c *CollectHostCertificate) Collect(progressChan chan<- interface{}) (map[s

return map[string][]byte{
name: b,
}, nil
}, collectorErr
}

func isEncryptedKey(filename string) (bool, error) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/collect/host_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func (c *CollectHostCopy) Collect(progressChan chan<- interface{}) (map[string][
klog.Errorf("Failed to copy files from %q to %q: %v", c.hostCollector.Path, "<bundle>/"+bundleRelPath, err)
fileName := fmt.Sprintf("%s/errors.json", c.relBundlePath(bundlePathDest))
output := NewResult()
err := output.SaveResult(c.BundlePath, fileName, marshalErrors([]string{err.Error()}))
if err != nil {
return nil, err
saveErr := output.SaveResult(c.BundlePath, fileName, marshalErrors([]string{err.Error()}))
if saveErr != nil {
return nil, saveErr
}
return output, nil
return output, err
}

return result, nil
Expand Down
9 changes: 7 additions & 2 deletions pkg/collect/host_httploadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,15 @@ func (c *CollectHostHTTPLoadBalancer) Collect(progressChan chan<- interface{}) (
}()

var networkStatus NetworkStatus
var errorMessage string
var collectorErr error

stopAfter := time.Now().Add(timeout)
for {
if len(listenErr) > 0 {
err := <-listenErr
errorMessage = err.Error()
collectorErr = errors.Wrap(err, "failed to listen on HTTP port")
if strings.Contains(err.Error(), "address already in use") {
networkStatus = NetworkStatusAddressInUse
break
Expand Down Expand Up @@ -113,7 +117,8 @@ func (c *CollectHostHTTPLoadBalancer) Collect(progressChan chan<- interface{}) (
}

result := NetworkStatusResult{
Status: networkStatus,
Status: networkStatus,
Message: errorMessage,
}

b, err := json.Marshal(result)
Expand All @@ -132,7 +137,7 @@ func (c *CollectHostHTTPLoadBalancer) Collect(progressChan chan<- interface{}) (

return map[string][]byte{
name: b,
}, nil
}, collectorErr
}

func attemptPOST(address string, request []byte, response []byte) NetworkStatus {
Expand Down
19 changes: 11 additions & 8 deletions pkg/collect/host_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package collect

import (
"bytes"
"fmt"
"net"
"regexp"
"strconv"
Expand Down Expand Up @@ -70,19 +71,20 @@ func isValidLoadBalancerAddress(address string) bool {
return len(errs) == 0
}

func checkTCPConnection(progressChan chan<- interface{}, listenAddress string, dialAddress string, timeout time.Duration) (NetworkStatus, error) {
func checkTCPConnection(progressChan chan<- interface{}, listenAddress string, dialAddress string, timeout time.Duration) (NetworkStatus, string, error) {

if !isValidLoadBalancerAddress(dialAddress) {
return NetworkStatusInvalidAddress, errors.Errorf("Invalid Load Balancer Address: %v", dialAddress)
errMsg := fmt.Sprintf("Invalid Load Balancer Address: %v", dialAddress)
return NetworkStatusInvalidAddress, errMsg, errors.New(errMsg)
}

lstn, err := net.Listen("tcp", listenAddress)
if err != nil {
if strings.Contains(err.Error(), "address already in use") {
return NetworkStatusAddressInUse, nil
return NetworkStatusAddressInUse, err.Error(), errors.Wrap(err, "failed to create listener")
}

return NetworkStatusErrorOther, errors.Wrap(err, "failed to create listener")
return NetworkStatusErrorOther, err.Error(), errors.Wrap(err, "failed to create listener")
}
defer lstn.Close()

Expand Down Expand Up @@ -110,7 +112,8 @@ func checkTCPConnection(progressChan chan<- interface{}, listenAddress string, d
if time.Now().After(stopAfter) {
debug.Printf("Timeout")

return NetworkStatusConnectionTimeout, nil
errMsg := "connection timeout"
return NetworkStatusConnectionTimeout, errMsg, errors.New(errMsg)
}

conn, err := net.DialTimeout("tcp", dialAddress, 50*time.Millisecond)
Expand All @@ -124,13 +127,13 @@ func checkTCPConnection(progressChan chan<- interface{}, listenAddress string, d
continue
}
if strings.Contains(err.Error(), "connection refused") {
return NetworkStatusConnectionRefused, nil
return NetworkStatusConnectionRefused, err.Error(), errors.Wrap(err, "failed to dial")
}
return NetworkStatusErrorOther, errors.Wrap(err, "failed to dial")
return NetworkStatusErrorOther, err.Error(), errors.Wrap(err, "failed to dial")
}

if verifyConnectionToServer(conn, requestToken, responseToken) {
return NetworkStatusConnected, nil
return NetworkStatusConnected, "", nil
}

progressChan <- errors.New("failed to verify connection to server")
Expand Down
Loading
Loading