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

Collector/Analyzer - Subnet Available #1004

Merged
merged 31 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b5ad2bb
boilerplate code for the subnet available collector and analyzer, still
Feb 2, 2023
077846b
remove netlink dependency
Feb 2, 2023
8530b20
working parsing of /proc/net/route to obtain ipv4 routes (without the
Feb 4, 2023
2f1d980
WIP on subnet available collector/analyzer including an example YAML
Feb 5, 2023
04106d2
fix api defs for subnet available collector
Feb 5, 2023
82f07ff
WIP on subnet available collector logic, tests don't pass yet
Feb 14, 2023
a1d4b19
more WIP on subnet available collector, tests don't pass yet still
Feb 14, 2023
be1591c
WIP on subnet available analyzer, not quite there yet (will likely wait
Feb 14, 2023
aeaac58
validate the cidr size for the subnet available collector
Feb 14, 2023
5e23811
WIP on subnet available collector, more logic added but it's not 100%
Feb 15, 2023
4c8fcac
more WIP on subnet available collector, dealing with IP address parsing
Feb 15, 2023
3b43f59
fixed the isASubnetAvailableInCIDR function, pretty sure it was buggy
Feb 17, 2023
4976784
subnet available collector and analyzer all working as expected
Feb 17, 2023
be64f55
remove debug output
Feb 17, 2023
d09fa32
Merge branch 'main' into cpuid-984
Feb 17, 2023
bb2026a
remove the unnecessary return, apparently its unreachable code... I
Feb 17, 2023
a3286cc
fix spacing in example
Feb 17, 2023
cde6172
subnet available collector: fix status JSON field name
Feb 17, 2023
9f06b4d
subnet available collector: include output of `make generate`
Feb 22, 2023
4529eea
move the example subnet available collector/analyzer spec, ref https:…
Feb 22, 2023
cee70d6
rename the subnet available collector/analyzer example spec, fix indents
Feb 22, 2023
d461aa9
allow picking a subnet from a /0 (all ipv4 space), ref https://github…
Feb 22, 2023
12a334d
subnet available collector/analyzer: make schemas
Feb 22, 2023
8d1c668
Merge branch 'main' into cpuid-984
Feb 22, 2023
0981e72
subnetavailable collector: have to remove this test, it can't be run …
Mar 7, 2023
4808507
Merge branch 'main' into cpuid-984
Mar 7, 2023
82394a2
Merge branch 'main' into cpuid-984
Mar 9, 2023
dc4ea46
subnetAvailable collector: change to klog
Mar 9, 2023
fcfab32
subnetAvailable collector: push the routes list even further down the
Mar 9, 2023
61e489f
subnetAvailable collector: oops remove debug param
Mar 9, 2023
3fc02f9
oops... :)
Mar 9, 2023
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
19 changes: 19 additions & 0 deletions config/samples/troubleshoot_v1beta2_subnetavailable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: troubleshoot.sh/v1beta2
CpuID marked this conversation as resolved.
Show resolved Hide resolved
kind: HostPreflight
metadata:
name: subnet-available
spec:
collectors:
# would output yes/no depending if there is a /22 available in 10.0.0.0/8
- subnetAvailable:
CIDRRangeAlloc: "10.0.0.0/8"
CpuID marked this conversation as resolved.
Show resolved Hide resolved
desiredCIDR: 22
analyzers:
- subnetAvailable:
outcomes:
CpuID marked this conversation as resolved.
Show resolved Hide resolved
- fail:
when: "no-subnet-available"
CpuID marked this conversation as resolved.
Show resolved Hide resolved
message: failed to find available subnet
- pass:
when: "a-subnet-is-available"
CpuID marked this conversation as resolved.
Show resolved Hide resolved
message: available /22 subnet found
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ require (

require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ github.com/alexflint/go-filemutex v0.0.0-20171022225611-72bdc8eae2ae/go.mod h1:C
github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc=
github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apparentlymart/go-cidr v1.1.0 h1:2mAhrMoF+nhXqxTzSZMUzDHkLjmIHC+Zzn4tdgBZjnU=
github.com/apparentlymart/go-cidr v1.1.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
Expand Down
2 changes: 2 additions & 0 deletions pkg/analyze/host_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func GetHostAnalyzer(analyzer *troubleshootv1beta2.HostAnalyze) (HostAnalyzer, b
return &AnalyzeHostTCPConnect{analyzer.TCPConnect}, true
case analyzer.IPV4Interfaces != nil:
return &AnalyzeHostIPV4Interfaces{analyzer.IPV4Interfaces}, true
case analyzer.SubnetAvailable != nil:
return &AnalyzeHostSubnetAvailable{analyzer.SubnetAvailable}, true
case analyzer.FilesystemPerformance != nil:
return &AnalyzeHostFilesystemPerformance{analyzer.FilesystemPerformance}, true
case analyzer.Certificate != nil:
Expand Down
82 changes: 82 additions & 0 deletions pkg/analyze/host_subnetavailable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package analyzer

import (
"encoding/json"
"path/filepath"

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

type AnalyzeHostSubnetAvailable struct {
hostAnalyzer *troubleshootv1beta2.SubnetAvailableAnalyze
}

func (a *AnalyzeHostSubnetAvailable) Title() string {
return hostAnalyzerTitleOrDefault(a.hostAnalyzer.AnalyzeMeta, "Subnet Available")
}

func (a *AnalyzeHostSubnetAvailable) IsExcluded() (bool, error) {
return isExcluded(a.hostAnalyzer.Exclude)
}

func (a *AnalyzeHostSubnetAvailable) Analyze(getCollectedFileContents func(string) ([]byte, error)) ([]*AnalyzeResult, error) {
hostAnalyzer := a.hostAnalyzer

name := filepath.Join("host-collectors/subnetAvailable", "result.json")
CpuID marked this conversation as resolved.
Show resolved Hide resolved
if hostAnalyzer.CollectorName != "" {
name = filepath.Join("host-collectors/subnetAvailable", hostAnalyzer.CollectorName+".json")
CpuID marked this conversation as resolved.
Show resolved Hide resolved
}
contents, err := getCollectedFileContents(name)
if err != nil {
return nil, errors.Wrap(err, "failed to get collected file")
}

isSubnetAvailable := &collect.SubnetAvailableResult{}
if err := json.Unmarshal(contents, isSubnetAvailable); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal subnetAvailable result")
}

result := &AnalyzeResult{
Title: a.Title(),
}

for _, outcome := range hostAnalyzer.Outcomes {
if outcome.Fail != nil {
if outcome.Fail.When == "" {
result.IsFail = true
result.Message = outcome.Fail.Message
result.URI = outcome.Fail.URI

return []*AnalyzeResult{result}, nil
}

if string(isSubnetAvailable.Status) == outcome.Fail.When {
result.IsFail = true
result.Message = outcome.Fail.Message
result.URI = outcome.Fail.URI

return []*AnalyzeResult{result}, nil
}
} else if outcome.Pass != nil {
if outcome.Pass.When == "" {
result.IsPass = true
result.Message = outcome.Pass.Message
result.URI = outcome.Pass.URI

return []*AnalyzeResult{result}, nil
}

if string(isSubnetAvailable.Status) == outcome.Pass.When {
result.IsPass = true
result.Message = outcome.Pass.Message
result.URI = outcome.Pass.URI

return []*AnalyzeResult{result}, nil
}
}
}

return []*AnalyzeResult{result}, nil
}
8 changes: 8 additions & 0 deletions pkg/apis/troubleshoot/v1beta2/hostanalyzer_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ type IPV4InterfacesAnalyze struct {
Outcomes []*Outcome `json:"outcomes" yaml:"outcomes"`
}

type SubnetAvailableAnalyze struct {
AnalyzeMeta `json:",inline" yaml:",inline"`
CollectorName string `json:"collectorName,omitempty" yaml:"collectorName,omitempty"`
Outcomes []*Outcome `json:"outcomes" yaml:"outcomes"`
}

type FilesystemPerformanceAnalyze struct {
AnalyzeMeta `json:",inline" yaml:",inline"`
CollectorName string `json:"collectorName,omitempty" yaml:"collectorName,omitempty"`
Expand Down Expand Up @@ -137,6 +143,8 @@ type HostAnalyze struct {

IPV4Interfaces *IPV4InterfacesAnalyze `json:"ipv4Interfaces,omitempty" yaml:"ipv4Interfaces,omitempty"`

SubnetAvailable *SubnetAvailableAnalyze `json:"subnetAvailable,omitempty" yaml:"subnetAvailable,omitempty"`

FilesystemPerformance *FilesystemPerformanceAnalyze `json:"filesystemPerformance,omitempty" yaml:"filesystemPerformance,omitempty"`

Certificate *CertificateAnalyze `json:"certificate,omitempty" yaml:"certificate,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ type IPV4Interfaces struct {
HostCollectorMeta `json:",inline" yaml:",inline"`
}

type SubnetAvailable struct {
HostCollectorMeta `json:",inline" yaml:",inline"`
CIDRRangeAlloc string `json:"CIDRRangeAlloc" yaml:"CIDRRangeAlloc"`
DesiredCIDR int `json:"desiredCIDR" yaml:"desiredCIDR"`
}

type DiskUsage struct {
HostCollectorMeta `json:",inline" yaml:",inline"`
Path string `json:"path"`
Expand Down Expand Up @@ -171,6 +177,7 @@ type HostCollect struct {
UDPPortStatus *UDPPortStatus `json:"udpPortStatus,omitempty" yaml:"udpPortStatus,omitempty"`
Kubernetes *Kubernetes `json:"kubernetes,omitempty" yaml:"kubernetes,omitempty"`
IPV4Interfaces *IPV4Interfaces `json:"ipv4Interfaces,omitempty" yaml:"ipv4Interfaces,omitempty"`
SubnetAvailable *SubnetAvailable `json:"subnetAvailable,omitempty" yaml:"subnetAvailable,omitempty"`
DiskUsage *DiskUsage `json:"diskUsage,omitempty" yaml:"diskUsage,omitempty"`
HTTP *HostHTTP `json:"http,omitempty" yaml:"http,omitempty"`
Time *HostTime `json:"time,omitempty" yaml:"time,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/troubleshoot/v1beta2/remote_collector_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ type RemoteIPV4Interfaces struct {
RemoteCollectorMeta `json:",inline" yaml:",inline"`
}

type RemoteSubnetAvailable struct {
RemoteCollectorMeta `json:",inline" yaml:",inline"`
CIDRRangeAlloc string `json:"CIDRRangeAlloc" yaml:"CIDRRangeAlloc"`
DesiredCIDR int `json:"desiredCIDR" yaml:"desiredCIDR"`
}

type RemoteDiskUsage struct {
RemoteCollectorMeta `json:",inline" yaml:",inline"`
Path string `json:"path"`
Expand Down Expand Up @@ -149,6 +155,7 @@ type RemoteCollect struct {
TCPPortStatus *RemoteTCPPortStatus `json:"tcpPortStatus,omitempty" yaml:"tcpPortStatus,omitempty"`
UDPPortStatus *RemoteUDPPortStatus `json:"udpPortStatus,omitempty" yaml:"udpPortStatus,omitempty"`
IPV4Interfaces *RemoteIPV4Interfaces `json:"ipv4Interfaces,omitempty" yaml:"ipv4Interfaces,omitempty"`
SubnetAvailable *RemoteSubnetAvailable `json:"subnetAvailable,omitempty" yaml:"subnetAvailable,omitempty"`
DiskUsage *RemoteDiskUsage `json:"diskUsage,omitempty" yaml:"diskUsage,omitempty"`
HTTP *RemoteHTTP `json:"http,omitempty" yaml:"http,omitempty"`
Time *RemoteTime `json:"time,omitempty" yaml:"time,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/collect/host_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func GetHostCollector(collector *troubleshootv1beta2.HostCollect, bundlePath str
return &CollectHostTCPConnect{collector.TCPConnect, bundlePath}, true
case collector.IPV4Interfaces != nil:
return &CollectHostIPV4Interfaces{collector.IPV4Interfaces, bundlePath}, true
case collector.SubnetAvailable != nil:
return &CollectHostSubnetAvailable{collector.SubnetAvailable, bundlePath}, true
case collector.FilesystemPerformance != nil:
return &CollectHostFilesystemPerformance{collector.FilesystemPerformance, bundlePath}, true
case collector.Certificate != nil:
Expand Down
Loading