-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement collector and analyser for network namespace connecti…
…vity checks if two network namespaces can talk to each other on udp and tcp. its usage is as follows: ```yaml apiVersion: troubleshoot.sh/v1beta2 kind: SupportBundle metadata: name: test spec: hostCollectors: - networkNamespaceConnectivity: collectorName: check-network-connectivity fromCIDR: 10.0.0.0/24 toCIDR: 10.0.1.0/24 hostAnalyzers: - networkNamespaceConnectivity: collectorName: check-network-connectivity outcomes: - pass: message: "Communication between 10.0.0.0/24 and 10.0.1.0/24 is working" - fail: message: "Communication between 10.0.0.0/24 and 10.0.1.0/24 isn't working" ``` if this fails then you may need to enable `forwarding` with: ```bash sysctl -w net.ipv4.ip_forward=1 ``` if it still fails then you may need to configure firewalld to allow the traffic or simply disable it for sake of testing.
- Loading branch information
1 parent
544a700
commit 7c92bf8
Showing
20 changed files
with
1,575 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package analyzer | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"path/filepath" | ||
|
||
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" | ||
"github.com/replicatedhq/troubleshoot/pkg/collect" | ||
) | ||
|
||
type AnalyzeHostNetworkNamespaceConnectivity struct { | ||
hostAnalyzer *troubleshootv1beta2.NetworkNamespaceConnectivityAnalyze | ||
} | ||
|
||
func (a *AnalyzeHostNetworkNamespaceConnectivity) Title() string { | ||
return hostAnalyzerTitleOrDefault(a.hostAnalyzer.AnalyzeMeta, "Network Namespace Connectivity") | ||
} | ||
|
||
func (a *AnalyzeHostNetworkNamespaceConnectivity) IsExcluded() (bool, error) { | ||
return isExcluded(a.hostAnalyzer.Exclude) | ||
} | ||
|
||
func (a *AnalyzeHostNetworkNamespaceConnectivity) Analyze( | ||
getCollectedFileContents func(string) ([]byte, error), findFiles getChildCollectedFileContents, | ||
) ([]*AnalyzeResult, error) { | ||
hostAnalyzer := a.hostAnalyzer | ||
|
||
name := filepath.Join("host-collectors/system", "networkNamespaceConnectivity.json") | ||
if hostAnalyzer.CollectorName != "" { | ||
name = filepath.Join("host-collectors/system", hostAnalyzer.CollectorName+".json") | ||
} | ||
|
||
contents, err := getCollectedFileContents(name) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get collected file %s: %w", name, err) | ||
} | ||
|
||
var info collect.NetworkNamespaceConnectivityInfo | ||
if err := json.Unmarshal(contents, &info); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal disk usage info from %s: %w", name, err) | ||
} | ||
|
||
var results []*AnalyzeResult | ||
for _, outcome := range hostAnalyzer.Outcomes { | ||
result := &AnalyzeResult{Title: a.Title()} | ||
|
||
if outcome.Pass != nil && info.Success { | ||
result.IsPass = true | ||
result.Message = outcome.Pass.Message | ||
results = append(results, result) | ||
break | ||
} | ||
|
||
if outcome.Fail != nil && !info.Success { | ||
result.IsFail = true | ||
result.Message = outcome.Fail.Message | ||
results = append(results, result) | ||
break | ||
} | ||
} | ||
|
||
return results, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.