Files
troubleshoot/pkg/namespaces/netlink-handler.go
Ricardo Maraschini e272683bce feat: implement collector and analyser for network namespace connectivity (#1670)
* 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
2024-11-06 11:30:13 +01:00

63 lines
1.7 KiB
Go

//go:build linux
package namespaces
import "github.com/vishvananda/netlink"
// NetlinkHandler is an interface that represents the netlink functions that
// we need to mock. This only exists for test purposes.
type NetlinkHandler interface {
ParseAddr(string) (*netlink.Addr, error)
AddrAdd(netlink.Link, *netlink.Addr) error
LinkSetUp(netlink.Link) error
LinkDel(netlink.Link) error
LinkAdd(netlink.Link) error
LinkByName(string) (netlink.Link, error)
LinkSetNsFd(netlink.Link, int) error
RouteAdd(*netlink.Route) error
}
// NetlinkHandle is a struct that exists solely for the purpose of mocking
// netlink functions on tests.
type NetlinkHandle struct{}
// ParseAddr calls netlink.ParseAddr.
func (n NetlinkHandle) ParseAddr(s string) (*netlink.Addr, error) {
return netlink.ParseAddr(s)
}
// AddrAdd calls netlink.AddrAdd.
func (n NetlinkHandle) AddrAdd(l netlink.Link, a *netlink.Addr) error {
return netlink.AddrAdd(l, a)
}
// LinkSetUp calls netlink.LinkSetUp.
func (n NetlinkHandle) LinkSetUp(link netlink.Link) error {
return netlink.LinkSetUp(link)
}
// LinkDel calls netlink.LinkDel.
func (n NetlinkHandle) LinkDel(link netlink.Link) error {
return netlink.LinkDel(link)
}
// LinkAdd calls netlink.LinkAdd.
func (n NetlinkHandle) LinkAdd(link netlink.Link) error {
return netlink.LinkAdd(link)
}
// LinkByName calls netlink.LinkByName.
func (n NetlinkHandle) LinkByName(name string) (netlink.Link, error) {
return netlink.LinkByName(name)
}
// LinkSetNsFd calls netlink.LinkSetNsFd.
func (n NetlinkHandle) LinkSetNsFd(link netlink.Link, fd int) error {
return netlink.LinkSetNsFd(link, fd)
}
// RouteAdd calls netlink.RouteAdd.
func (n NetlinkHandle) RouteAdd(route *netlink.Route) error {
return netlink.RouteAdd(route)
}