Skip to content
Merged
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
46 changes: 26 additions & 20 deletions internal/cni/ops_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,9 @@ func cmdCheck(args *skel.CmdArgs) error {

var errs []error

// Check VRF interface exists.
if err := vrf.Exists(pluginConf.VPC, pluginConf.VPCAttachment); err != nil {
errs = append(errs, fmt.Errorf("vrf %s-%s: %w", pluginConf.VPC, pluginConf.VPCAttachment, err))
}

// Check the host-side interface exists.
hostName := intf.GenerateInterfaceNameHost(pluginConf.VPC, pluginConf.VPCAttachment)
if _, err := netlink.LinkByName(hostName); err != nil {
errs = append(errs, fmt.Errorf("host interface %q: %w", hostName, err))
}
// Check node-level state (VRF + host interface).
hostName, nodeErrs := checkNodeLevelState(pluginConf.VPC, pluginConf.VPCAttachment)
errs = append(errs, nodeErrs...)

// For veth mode, verify the guest interface is in the container netns.
if pluginConf.InterfaceType == interfaceTypeVeth {
Expand Down Expand Up @@ -88,16 +81,9 @@ func cmdStatus(args *skel.CmdArgs) error {

var errs []error

// Check VRF interface exists.
if err := vrf.Exists(pluginConf.VPC, pluginConf.VPCAttachment); err != nil {
errs = append(errs, fmt.Errorf("vrf %s-%s: %w", pluginConf.VPC, pluginConf.VPCAttachment, err))
}

// Check the host-side interface exists.
hostName := intf.GenerateInterfaceNameHost(pluginConf.VPC, pluginConf.VPCAttachment)
if _, err := netlink.LinkByName(hostName); err != nil {
errs = append(errs, fmt.Errorf("host interface %q: %w", hostName, err))
}
// Check node-level state (VRF + host interface).
_, statusErrs := checkNodeLevelState(pluginConf.VPC, pluginConf.VPCAttachment)
errs = append(errs, statusErrs...)

// Check API server reachability with a lightweight GET.
if err := probeAPIServer(); err != nil {
Expand Down Expand Up @@ -144,6 +130,26 @@ func probeAPIServer() error {
return nil
}

// checkNodeLevelState verifies that node-level networking resources exist:
// the VRF interface and the host-side endpoint interface. Returns the host
// interface name (for callers that need it, e.g. cmdCheck's prevResult
// validation) and a slice of errors (nil when all checks pass) so callers
// can accumulate and report all failures at once.
func checkNodeLevelState(vpc, vpcAttachment string) (string, []error) {
var errs []error

if err := vrf.Exists(vpc, vpcAttachment); err != nil {
errs = append(errs, fmt.Errorf("vrf %s-%s: %w", vpc, vpcAttachment, err))
}

hostName := intf.GenerateInterfaceNameHost(vpc, vpcAttachment)
if _, err := netlink.LinkByName(hostName); err != nil {
errs = append(errs, fmt.Errorf("host interface %q: %w", hostName, err))
}

return hostName, errs
}

// checkGuestInterface verifies that the named interface exists inside the
// given network namespace. Returns nil when the interface is present.
func checkGuestInterface(netnsPath, ifName string) error {
Expand Down
Loading