mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-02-14 18:29:53 +00:00
* feat: implement collector and analyser for network namespace connectivity
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.
* chore: rebuild schemas
* chore: remove unused property
* chore: disable namespaces for other platforms
* chore: make sure we timeout temporary servers
* feat: analyzer now supports multi-node collection
* feat: check both udp and tcp even on failure
check both protocols even if one fails. this pr commit also introduces a
timeout that can be set by the user.
* feat: add templating to the failure outcome
allow users to dump the errors found during the analysis.
* chore: addressing pr comments
* feat: delete interface pair before namespace
even though the interface pair is deleted everyttime we delete the
namespace on my tests we better delete it before we delete the
namespace.
this comes out of a review comment where some people seem to still be
able to see the interface pair even after the namespace is deleted.
i.e. better safe than sorry.
* chore: fix typo on comment
92 lines
2.4 KiB
Go
92 lines
2.4 KiB
Go
//go:build linux
|
|
|
|
package namespaces
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"syscall"
|
|
|
|
"github.com/vishvananda/netlink"
|
|
)
|
|
|
|
// InterfacePair represents a pair of virtual ethernets that are connected to
|
|
// each other. these are used to connect a network namespace to the outside
|
|
// world.
|
|
type InterfacePair struct {
|
|
nethandler NetlinkHandler
|
|
prefix string
|
|
in netlink.Link
|
|
out netlink.Link
|
|
cfg Configuration
|
|
}
|
|
|
|
// SetExternalIP assigns an ip address to the interface living in the default
|
|
// namespace (outside interface).
|
|
func (p *InterfacePair) SetExternalIP(outaddr string) error {
|
|
addr, err := p.nethandler.ParseAddr(outaddr)
|
|
if err != nil {
|
|
return fmt.Errorf("error parsing ip: %w", err)
|
|
}
|
|
|
|
if err := p.nethandler.AddrAdd(p.out, addr); err != nil {
|
|
return fmt.Errorf("error assigning ip: %w", err)
|
|
}
|
|
|
|
if err := p.nethandler.LinkSetUp(p.out); err != nil {
|
|
return fmt.Errorf("error bringing up: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Close deletes the interface pair. by deleting one of the interfaces, the
|
|
// other is deleted as well.
|
|
func (p *InterfacePair) Close() error {
|
|
for _, ifc := range []netlink.Link{p.in, p.out} {
|
|
if err := p.nethandler.LinkDel(ifc); err != nil {
|
|
var scerr syscall.Errno
|
|
if errors.As(err, &scerr) && scerr == syscall.ENODEV {
|
|
continue
|
|
}
|
|
return fmt.Errorf("error deleting %s: %w", ifc.Attrs().Name, scerr)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Setup sets up the interface pair. this function will create the veth pair
|
|
// and bring the interfaces up.
|
|
func (p *InterfacePair) Setup() (err error) {
|
|
in := fmt.Sprintf("%s-in", p.prefix)
|
|
out := fmt.Sprintf("%s-out", p.prefix)
|
|
veth := &netlink.Veth{
|
|
LinkAttrs: netlink.LinkAttrs{Name: in},
|
|
PeerName: out,
|
|
}
|
|
|
|
p.cfg.Logf("creating interface pair %q and %q", in, out)
|
|
if err := p.nethandler.LinkAdd(veth); err != nil {
|
|
return fmt.Errorf("error creating veth pair: %w", err)
|
|
}
|
|
|
|
if p.in, err = p.nethandler.LinkByName(in); err != nil {
|
|
return fmt.Errorf("error finding %s: %w", in, err)
|
|
}
|
|
|
|
if p.out, err = p.nethandler.LinkByName(out); err != nil {
|
|
return fmt.Errorf("error finding %s: %w", out, err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// NewInterfacePair creates a pair of connected virtual ethernets. interfaces
|
|
// are named `prefix-in` and `prefix-out`.
|
|
func NewInterfacePair(prefix string, options ...Option) *InterfacePair {
|
|
config := NewConfiguration(options...)
|
|
return &InterfacePair{
|
|
nethandler: NetlinkHandle{},
|
|
prefix: prefix,
|
|
cfg: config,
|
|
}
|
|
}
|