@@ -37,16 +37,9 @@ func cmdCheck(args *skel.CmdArgs) error {
3737
3838 var errs []error
3939
40- // Check VRF interface exists.
41- if err := vrf .Exists (pluginConf .VPC , pluginConf .VPCAttachment ); err != nil {
42- errs = append (errs , fmt .Errorf ("vrf %s-%s: %w" , pluginConf .VPC , pluginConf .VPCAttachment , err ))
43- }
44-
45- // Check the host-side interface exists.
46- hostName := intf .GenerateInterfaceNameHost (pluginConf .VPC , pluginConf .VPCAttachment )
47- if _ , err := netlink .LinkByName (hostName ); err != nil {
48- errs = append (errs , fmt .Errorf ("host interface %q: %w" , hostName , err ))
49- }
40+ // Check node-level state (VRF + host interface).
41+ hostName , nodeErrs := checkNodeLevelState (pluginConf .VPC , pluginConf .VPCAttachment )
42+ errs = append (errs , nodeErrs ... )
5043
5144 // For veth mode, verify the guest interface is in the container netns.
5245 if pluginConf .InterfaceType == interfaceTypeVeth {
@@ -88,16 +81,9 @@ func cmdStatus(args *skel.CmdArgs) error {
8881
8982 var errs []error
9083
91- // Check VRF interface exists.
92- if err := vrf .Exists (pluginConf .VPC , pluginConf .VPCAttachment ); err != nil {
93- errs = append (errs , fmt .Errorf ("vrf %s-%s: %w" , pluginConf .VPC , pluginConf .VPCAttachment , err ))
94- }
95-
96- // Check the host-side interface exists.
97- hostName := intf .GenerateInterfaceNameHost (pluginConf .VPC , pluginConf .VPCAttachment )
98- if _ , err := netlink .LinkByName (hostName ); err != nil {
99- errs = append (errs , fmt .Errorf ("host interface %q: %w" , hostName , err ))
100- }
84+ // Check node-level state (VRF + host interface).
85+ _ , statusErrs := checkNodeLevelState (pluginConf .VPC , pluginConf .VPCAttachment )
86+ errs = append (errs , statusErrs ... )
10187
10288 // Check API server reachability with a lightweight GET.
10389 if err := probeAPIServer (); err != nil {
@@ -144,6 +130,26 @@ func probeAPIServer() error {
144130 return nil
145131}
146132
133+ // checkNodeLevelState verifies that node-level networking resources exist:
134+ // the VRF interface and the host-side endpoint interface. Returns the host
135+ // interface name (for callers that need it, e.g. cmdCheck's prevResult
136+ // validation) and a slice of errors (nil when all checks pass) so callers
137+ // can accumulate and report all failures at once.
138+ func checkNodeLevelState (vpc , vpcAttachment string ) (string , []error ) {
139+ var errs []error
140+
141+ if err := vrf .Exists (vpc , vpcAttachment ); err != nil {
142+ errs = append (errs , fmt .Errorf ("vrf %s-%s: %w" , vpc , vpcAttachment , err ))
143+ }
144+
145+ hostName := intf .GenerateInterfaceNameHost (vpc , vpcAttachment )
146+ if _ , err := netlink .LinkByName (hostName ); err != nil {
147+ errs = append (errs , fmt .Errorf ("host interface %q: %w" , hostName , err ))
148+ }
149+
150+ return hostName , errs
151+ }
152+
147153// checkGuestInterface verifies that the named interface exists inside the
148154// given network namespace. Returns nil when the interface is present.
149155func checkGuestInterface (netnsPath , ifName string ) error {
0 commit comments