@@ -282,6 +282,10 @@ func TestCCMLoadBalancers(t *testing.T) {
282282 name : "Create Load Balancer - Very long Service name" ,
283283 f : testVeryLongServiceName ,
284284 },
285+ {
286+ name : "getNodeBalancerByStatus with IPv4 and IPv6 addresses" ,
287+ f : testGetNodeBalancerByStatus ,
288+ },
285289 }
286290
287291 for _ , tc := range testCases {
@@ -3660,6 +3664,70 @@ func testUpdateLoadBalancerNoNodes(t *testing.T, client *linodego.Client, _ *fak
36603664 }
36613665}
36623666
3667+ func testGetNodeBalancerByStatus (t * testing.T , client * linodego.Client , _ * fakeAPI ) {
3668+ t .Helper ()
3669+
3670+ lb , assertion := newLoadbalancers (client , "us-west" ).(* loadbalancers )
3671+ if ! assertion {
3672+ t .Error ("type assertion failed" )
3673+ }
3674+ fakeClientset := fake .NewSimpleClientset ()
3675+ lb .kubeClient = fakeClientset
3676+
3677+ for _ , test := range []struct {
3678+ name string
3679+ service * v1.Service
3680+ }{
3681+ {
3682+ name : "hostname only" ,
3683+ service : & v1.Service {
3684+ ObjectMeta : metav1.ObjectMeta {
3685+ Name : "hostname-ingress-" + randString (),
3686+ Annotations : map [string ]string {annotations .AnnLinodeHostnameOnlyIngress : "true" },
3687+ },
3688+ },
3689+ },
3690+ {
3691+ name : "ipv4" ,
3692+ service : & v1.Service {
3693+ ObjectMeta : metav1.ObjectMeta {
3694+ Name : "ipv4-ingress-" + randString (),
3695+ },
3696+ },
3697+ },
3698+ {
3699+ name : "ipv4 and ipv6" ,
3700+ service : & v1.Service {
3701+ ObjectMeta : metav1.ObjectMeta {
3702+ Name : "ipv6-ingress-" + randString (),
3703+ Annotations : map [string ]string {annotations .AnnLinodeEnableIPv6Ingress : "true" },
3704+ },
3705+ },
3706+ },
3707+ } {
3708+ t .Run (test .name , func (t * testing.T ) {
3709+ expectedNB , err := lb .createNodeBalancer (t .Context (), "linodelb" , test .service , []* linodego.NodeBalancerConfigCreateOptions {})
3710+ if err != nil {
3711+ t .Fatal (err )
3712+ }
3713+ test .service .Status .LoadBalancer = * makeLoadBalancerStatus (test .service , expectedNB )
3714+
3715+ actualNB , err := lb .getNodeBalancerByStatus (t .Context (), test .service )
3716+ if err != nil {
3717+ t .Fatal (err )
3718+ }
3719+
3720+ if expectedNB .ID != actualNB .ID {
3721+ t .Error ("unexpected nodebalancer ID" )
3722+ t .Logf ("expected: %v" , expectedNB .ID )
3723+ t .Logf ("actual: %v" , actualNB .ID )
3724+ }
3725+
3726+ _ = lb .EnsureLoadBalancerDeleted (t .Context (), "linodelb" , test .service )
3727+ })
3728+ }
3729+ }
3730+
36633731func testGetNodeBalancerForServiceIDDoesNotExist (t * testing.T , client * linodego.Client , _ * fakeAPI ) {
36643732 t .Helper ()
36653733
0 commit comments