@@ -1295,3 +1295,117 @@ func Test_defaultModelBuildTask_buildLoadBalancerSubnets(t *testing.T) {
12951295 })
12961296 }
12971297}
1298+
1299+ func Test_defaultModelBuildTask_buildLoadBalancerIPAddressType (t * testing.T ) {
1300+ type fields struct {
1301+ ingGroup Group
1302+ }
1303+
1304+ tests := []struct {
1305+ name string
1306+ fields fields
1307+ want elbv2.IPAddressType
1308+ wantErr error
1309+ }{
1310+ {
1311+ name : "No ip-address-type annotation set" ,
1312+ fields : fields {
1313+ ingGroup : Group {
1314+ ID : GroupID {Name : "explicit-group" },
1315+ Members : []ClassifiedIngress {
1316+ {
1317+ Ing : & networking.Ingress {
1318+ ObjectMeta : metav1.ObjectMeta {
1319+ Namespace : "awesome-ns" ,
1320+ Name : "ing-1" ,
1321+ },
1322+ },
1323+ },
1324+ },
1325+ },
1326+ },
1327+ want : "" ,
1328+ },
1329+ {
1330+ name : "The ip-address-type annotation is set to ipv4" ,
1331+ fields : fields {
1332+ ingGroup : Group {
1333+ ID : GroupID {Name : "explicit-group" },
1334+ Members : []ClassifiedIngress {
1335+ {
1336+ Ing : & networking.Ingress {
1337+ ObjectMeta : metav1.ObjectMeta {
1338+ Namespace : "awesome-ns" ,
1339+ Name : "ing-1" ,
1340+ Annotations : map [string ]string {
1341+ "alb.ingress.kubernetes.io/ip-address-type" : "ipv4" ,
1342+ },
1343+ },
1344+ },
1345+ },
1346+ },
1347+ },
1348+ },
1349+ want : elbv2 .IPAddressTypeIPV4 ,
1350+ },
1351+ {
1352+ name : "The ip-address-type annotation is set to dualstack" ,
1353+ fields : fields {
1354+ ingGroup : Group {
1355+ ID : GroupID {Name : "explicit-group" },
1356+ Members : []ClassifiedIngress {
1357+ {
1358+ Ing : & networking.Ingress {
1359+ ObjectMeta : metav1.ObjectMeta {
1360+ Namespace : "awesome-ns" ,
1361+ Name : "ing-1" ,
1362+ Annotations : map [string ]string {
1363+ "alb.ingress.kubernetes.io/ip-address-type" : "dualstack" ,
1364+ },
1365+ },
1366+ },
1367+ },
1368+ },
1369+ },
1370+ },
1371+ want : elbv2 .IPAddressTypeDualStack ,
1372+ },
1373+ {
1374+ name : "The ip-address-type annotation is set to dualstack-without-public-ipv4" ,
1375+ fields : fields {
1376+ ingGroup : Group {
1377+ ID : GroupID {Name : "explicit-group" },
1378+ Members : []ClassifiedIngress {
1379+ {
1380+ Ing : & networking.Ingress {
1381+ ObjectMeta : metav1.ObjectMeta {
1382+ Namespace : "awesome-ns" ,
1383+ Name : "ing-1" ,
1384+ Annotations : map [string ]string {
1385+ "alb.ingress.kubernetes.io/ip-address-type" : "dualstack-without-public-ipv4" ,
1386+ "alb.ingress.kubernetes.io/scheme" : "internet-facing" ,
1387+ },
1388+ },
1389+ },
1390+ },
1391+ },
1392+ },
1393+ },
1394+ want : elbv2 .IPAddressTypeDualStackWithoutPublicIPV4 ,
1395+ },
1396+ }
1397+ for _ , tt := range tests {
1398+ t .Run (tt .name , func (t * testing.T ) {
1399+ task := & defaultModelBuildTask {
1400+ ingGroup : tt .fields .ingGroup ,
1401+ annotationParser : annotations .NewSuffixAnnotationParser ("alb.ingress.kubernetes.io" ),
1402+ }
1403+ got , err := task .buildLoadBalancerIPAddressType (context .Background ())
1404+ if err != nil {
1405+ assert .EqualError (t , err , tt .wantErr .Error ())
1406+ } else {
1407+ assert .Equal (t , tt .want , got )
1408+ }
1409+ })
1410+ }
1411+ }
0 commit comments