@@ -393,6 +393,38 @@ func TestCreateRoute(t *testing.T) {
393393 assert .NoError (t , err )
394394 })
395395
396+ interfaceWithVPCAndRoute := linodego.LinodeInterface {
397+ ID : services .VpcIDs ["dummy" ],
398+ VPC : & linodego.VPCInterface {
399+ IPv4 : linodego.VPCInterfaceIPv4 {
400+ Ranges : []linodego.VPCInterfaceIPv4Range {{Range : "10.10.10.0/24" }},
401+ },
402+ },
403+ }
404+ validInstance .InterfaceGeneration = linodego .GenerationLinode
405+ t .Run ("should return no error if instance exists, connected to VPC we add a route with linode interfaces" , func (t * testing.T ) {
406+ ctrl := gomock .NewController (t )
407+ defer ctrl .Finish ()
408+ client := mocks .NewMockClient (ctrl )
409+ instanceCache := services .NewInstances (client )
410+ existingK8sCache := registeredK8sNodeCache
411+ defer func () {
412+ registeredK8sNodeCache = existingK8sCache
413+ }()
414+ registeredK8sNodeCache = newK8sNodeCache ()
415+ registeredK8sNodeCache .addNodeToCache (node )
416+ routeController , err := newRoutes (client , instanceCache )
417+ require .NoError (t , err )
418+
419+ client .EXPECT ().ListInstances (gomock .Any (), nil ).Times (1 ).Return ([]linodego.Instance {validInstance }, nil )
420+ client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (2 ).Return (noRoutesInVPC , nil )
421+ client .EXPECT ().ListVPCIPv6Addresses (gomock .Any (), gomock .Any (), gomock .Any ()).AnyTimes ().Return ([]linodego.VPCIP {}, nil )
422+ client .EXPECT ().UpdateInterface (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Times (1 ).Return (& interfaceWithVPCAndRoute , nil )
423+ err = routeController .CreateRoute (ctx , "dummy" , "dummy" , route )
424+ assert .NoError (t , err )
425+ })
426+ validInstance .InterfaceGeneration = ""
427+
396428 v6Route := & cloudprovider.Route {
397429 Name : "route2" ,
398430 TargetNode : types .NodeName (name ),
@@ -552,6 +584,29 @@ func TestDeleteRoute(t *testing.T) {
552584 assert .NoError (t , err )
553585 })
554586
587+ interfaceWitVPCAndNoRoute := linodego.LinodeInterface {
588+ ID : services .VpcIDs ["dummy" ],
589+ VPC : & linodego.VPCInterface {IPv4 : linodego.VPCInterfaceIPv4 {Ranges : nil }},
590+ }
591+
592+ validInstance .InterfaceGeneration = linodego .GenerationLinode
593+ t .Run ("should return no error if instance exists, connected to VPC, route doesn't exist and we try to delete route with linode interfaces" , func (t * testing.T ) {
594+ ctrl := gomock .NewController (t )
595+ defer ctrl .Finish ()
596+ client := mocks .NewMockClient (ctrl )
597+ instanceCache := services .NewInstances (client )
598+ routeController , err := newRoutes (client , instanceCache )
599+ require .NoError (t , err )
600+
601+ client .EXPECT ().ListInstances (gomock .Any (), nil ).Times (1 ).Return ([]linodego.Instance {validInstance }, nil )
602+ client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (2 ).Return (noRoutesInVPC , nil )
603+ client .EXPECT ().ListVPCIPv6Addresses (gomock .Any (), gomock .Any (), gomock .Any ()).AnyTimes ().Return ([]linodego.VPCIP {}, nil )
604+ client .EXPECT ().UpdateInterface (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Times (1 ).Return (& interfaceWitVPCAndNoRoute , nil )
605+ err = routeController .DeleteRoute (ctx , "dummy" , route )
606+ assert .NoError (t , err )
607+ })
608+ validInstance .InterfaceGeneration = ""
609+
555610 routesInVPC := []linodego.VPCIP {
556611 {
557612 Address : & vpcIP ,
@@ -584,4 +639,21 @@ func TestDeleteRoute(t *testing.T) {
584639 err = routeController .DeleteRoute (ctx , "dummy" , route )
585640 assert .NoError (t , err )
586641 })
642+
643+ validInstance .InterfaceGeneration = linodego .GenerationLinode
644+ t .Run ("should return no error if instance exists, connected to VPC and route is deleted with linode interfaces" , func (t * testing.T ) {
645+ ctrl := gomock .NewController (t )
646+ defer ctrl .Finish ()
647+ client := mocks .NewMockClient (ctrl )
648+ instanceCache := services .NewInstances (client )
649+ routeController , err := newRoutes (client , instanceCache )
650+ require .NoError (t , err )
651+
652+ client .EXPECT ().ListInstances (gomock .Any (), nil ).Times (1 ).Return ([]linodego.Instance {validInstance }, nil )
653+ client .EXPECT ().ListVPCIPAddresses (gomock .Any (), gomock .Any (), gomock .Any ()).Times (2 ).Return (routesInVPC , nil )
654+ client .EXPECT ().ListVPCIPv6Addresses (gomock .Any (), gomock .Any (), gomock .Any ()).AnyTimes ().Return ([]linodego.VPCIP {}, nil )
655+ client .EXPECT ().UpdateInterface (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Times (1 ).Return (& interfaceWitVPCAndNoRoute , nil )
656+ err = routeController .DeleteRoute (ctx , "dummy" , route )
657+ assert .NoError (t , err )
658+ })
587659}
0 commit comments