@@ -43,6 +43,17 @@ import (
4343	"sigs.k8s.io/cluster-api/util/conditions" 
4444)
4545
46+ var  stubInfraV1TargetGroupSpecAPI  =  infrav1.TargetGroupSpec {
47+ 	Name :     "name" ,
48+ 	Port :     infrav1 .DefaultAPIServerPort ,
49+ 	Protocol : "TCP" ,
50+ 	HealthCheck : & infrav1.TargetGroupHealthCheck {
51+ 		IntervalSeconds : aws .Int64 (10 ),
52+ 		TimeoutSeconds :  aws .Int64 (5 ),
53+ 		ThresholdCount :  aws .Int64 (5 ),
54+ 	},
55+ }
56+ 
4657func  TestELBName (t  * testing.T ) {
4758	tests  :=  []struct  {
4859		name        string 
@@ -842,7 +853,7 @@ func TestRegisterInstanceWithAPIServerNLB(t *testing.T) {
842853					TargetGroups : []* elbv2.TargetGroup {
843854						{
844855							HealthCheckEnabled :  aws .Bool (true ),
845- 							HealthCheckPort :     aws .String (" infrav1.DefaultAPIServerPort" 
856+ 							HealthCheckPort :     aws .String (infrav1 .DefaultAPIServerPortString ),
846857							HealthCheckProtocol : aws .String ("TCP" ),
847858							LoadBalancerArns :    aws .StringSlice ([]string {elbArn }),
848859							Port :                aws .Int64 (infrav1 .DefaultAPIServerPort ),
@@ -945,7 +956,7 @@ func TestRegisterInstanceWithAPIServerNLB(t *testing.T) {
945956					TargetGroups : []* elbv2.TargetGroup {
946957						{
947958							HealthCheckEnabled :  aws .Bool (true ),
948- 							HealthCheckPort :     aws .String (" infrav1.DefaultAPIServerPort" 
959+ 							HealthCheckPort :     aws .String (infrav1 .DefaultAPIServerPortString ),
949960							HealthCheckProtocol : aws .String ("TCP" ),
950961							LoadBalancerArns :    aws .StringSlice ([]string {elbArn }),
951962							Port :                aws .Int64 (infrav1 .DefaultAPIServerPort ),
@@ -1189,13 +1200,14 @@ func TestCreateNLB(t *testing.T) {
11891200					},
11901201				}, nil )
11911202				m .CreateTargetGroup (gomock .Eq (& elbv2.CreateTargetGroupInput {
1192- 					HealthCheckEnabled :  aws .Bool (true ),
1193- 					HealthCheckPort :     aws .String ("infrav1.DefaultAPIServerPort" ),
1194- 					HealthCheckProtocol : aws .String ("tcp" ),
1195- 					Name :                aws .String ("name" ),
1196- 					Port :                aws .Int64 (infrav1 .DefaultAPIServerPort ),
1197- 					Protocol :            aws .String ("TCP" ),
1198- 					VpcId :               aws .String (vpcID ),
1203+ 					HealthCheckEnabled :      aws .Bool (true ),
1204+ 					HealthCheckPort :         aws .String (infrav1 .DefaultAPIServerPortString ),
1205+ 					HealthCheckProtocol :     aws .String ("tcp" ),
1206+ 					UnhealthyThresholdCount : aws .Int64 (infrav1 .DefaultAPIServerUnhealthThresholdCount ),
1207+ 					Name :                    aws .String ("name" ),
1208+ 					Port :                    aws .Int64 (infrav1 .DefaultAPIServerPort ),
1209+ 					Protocol :                aws .String ("TCP" ),
1210+ 					VpcId :                   aws .String (vpcID ),
11991211					Tags : []* elbv2.Tag {
12001212						{
12011213							Key :   aws .String ("test" ),
@@ -1291,14 +1303,15 @@ func TestCreateNLB(t *testing.T) {
12911303					},
12921304				}, nil )
12931305				m .CreateTargetGroup (gomock .Eq (& elbv2.CreateTargetGroupInput {
1294- 					HealthCheckEnabled :  aws .Bool (true ),
1295- 					HealthCheckPort :     aws .String ("infrav1.DefaultAPIServerPort" ),
1296- 					HealthCheckProtocol : aws .String ("tcp" ),
1297- 					Name :                aws .String ("name" ),
1298- 					Port :                aws .Int64 (infrav1 .DefaultAPIServerPort ),
1299- 					Protocol :            aws .String ("TCP" ),
1300- 					VpcId :               aws .String (vpcID ),
1301- 					IpAddressType :       aws .String ("ipv6" ),
1306+ 					HealthCheckEnabled :      aws .Bool (true ),
1307+ 					HealthCheckPort :         aws .String (infrav1 .DefaultAPIServerPortString ),
1308+ 					HealthCheckProtocol :     aws .String ("tcp" ),
1309+ 					UnhealthyThresholdCount : aws .Int64 (infrav1 .DefaultAPIServerUnhealthThresholdCount ),
1310+ 					Name :                    aws .String ("name" ),
1311+ 					Port :                    aws .Int64 (infrav1 .DefaultAPIServerPort ),
1312+ 					Protocol :                aws .String ("TCP" ),
1313+ 					VpcId :                   aws .String (vpcID ),
1314+ 					IpAddressType :           aws .String ("ipv6" ),
13021315					Tags : []* elbv2.Tag {
13031316						{
13041317							Key :   aws .String ("test" ),
@@ -1529,13 +1542,14 @@ func TestCreateNLB(t *testing.T) {
15291542					},
15301543				}, nil )
15311544				m .CreateTargetGroup (gomock .Eq (& elbv2.CreateTargetGroupInput {
1532- 					HealthCheckEnabled :  aws .Bool (true ),
1533- 					HealthCheckPort :     aws .String ("infrav1.DefaultAPIServerPort" ),
1534- 					HealthCheckProtocol : aws .String ("tcp" ),
1535- 					Name :                aws .String ("name" ),
1536- 					Port :                aws .Int64 (infrav1 .DefaultAPIServerPort ),
1537- 					Protocol :            aws .String ("TCP" ),
1538- 					VpcId :               aws .String (vpcID ),
1545+ 					HealthCheckEnabled :      aws .Bool (true ),
1546+ 					HealthCheckPort :         aws .String (infrav1 .DefaultAPIServerPortString ),
1547+ 					HealthCheckProtocol :     aws .String ("tcp" ),
1548+ 					UnhealthyThresholdCount : aws .Int64 (infrav1 .DefaultAPIServerUnhealthThresholdCount ),
1549+ 					Name :                    aws .String ("name" ),
1550+ 					Port :                    aws .Int64 (infrav1 .DefaultAPIServerPort ),
1551+ 					Protocol :                aws .String ("TCP" ),
1552+ 					VpcId :                   aws .String (vpcID ),
15391553					Tags : []* elbv2.Tag {
15401554						{
15411555							Key :   aws .String ("test" ),
@@ -1619,13 +1633,14 @@ func TestCreateNLB(t *testing.T) {
16191633					},
16201634				}, nil )
16211635				m .CreateTargetGroup (gomock .Eq (& elbv2.CreateTargetGroupInput {
1622- 					HealthCheckEnabled :  aws .Bool (true ),
1623- 					HealthCheckPort :     aws .String ("infrav1.DefaultAPIServerPort" ),
1624- 					HealthCheckProtocol : aws .String ("tcp" ),
1625- 					Name :                aws .String ("name" ),
1626- 					Port :                aws .Int64 (infrav1 .DefaultAPIServerPort ),
1627- 					Protocol :            aws .String ("TCP" ),
1628- 					VpcId :               aws .String (vpcID ),
1636+ 					HealthCheckEnabled :      aws .Bool (true ),
1637+ 					HealthCheckPort :         aws .String (infrav1 .DefaultAPIServerPortString ),
1638+ 					HealthCheckProtocol :     aws .String ("tcp" ),
1639+ 					UnhealthyThresholdCount : aws .Int64 (infrav1 .DefaultAPIServerUnhealthThresholdCount ),
1640+ 					Name :                    aws .String ("name" ),
1641+ 					Port :                    aws .Int64 (infrav1 .DefaultAPIServerPort ),
1642+ 					Protocol :                aws .String ("TCP" ),
1643+ 					VpcId :                   aws .String (vpcID ),
16291644					Tags : []* elbv2.Tag {
16301645						{
16311646							Key :   aws .String ("test" ),
@@ -1684,6 +1699,260 @@ func TestCreateNLB(t *testing.T) {
16841699				}
16851700			},
16861701		},
1702+ 		{
1703+ 			name : "NLB with HTTP health check" ,
1704+ 			awsCluster : func (acl  infrav1.AWSCluster ) infrav1.AWSCluster  {
1705+ 				acl .Spec .ControlPlaneLoadBalancer .Scheme  =  & infrav1 .ELBSchemeInternetFacing 
1706+ 				acl .Spec .ControlPlaneLoadBalancer .LoadBalancerType  =  infrav1 .LoadBalancerTypeNLB 
1707+ 				acl .Spec .ControlPlaneLoadBalancer .HealthCheckProtocol  =  & infrav1 .ELBProtocolHTTP 
1708+ 				return  acl 
1709+ 			},
1710+ 			spec : func (spec  infrav1.LoadBalancer ) infrav1.LoadBalancer  {
1711+ 				tg  :=  stubInfraV1TargetGroupSpecAPI 
1712+ 				tg .VpcID  =  vpcID 
1713+ 				tg .HealthCheck .Protocol  =  aws .String ("HTTP" )
1714+ 				tg .HealthCheck .Port  =  aws .String (infrav1 .DefaultAPIServerPortString )
1715+ 				tg .HealthCheck .Path  =  aws .String ("/readyz" )
1716+ 				spec .ELBListeners  =  []infrav1.Listener {
1717+ 					{
1718+ 						Protocol :    "TCP" ,
1719+ 						Port :        infrav1 .DefaultAPIServerPort ,
1720+ 						TargetGroup : tg ,
1721+ 					},
1722+ 				}
1723+ 				return  spec 
1724+ 			},
1725+ 			elbV2APIMocks : func (m  * mocks.MockELBV2APIMockRecorder ) {
1726+ 				m .CreateLoadBalancer (gomock .Eq (& elbv2.CreateLoadBalancerInput {
1727+ 					Name :           aws .String (elbName ),
1728+ 					Scheme :         aws .String ("internet-facing" ),
1729+ 					SecurityGroups : aws .StringSlice ([]string {}),
1730+ 					Type :           aws .String ("network" ),
1731+ 					Subnets :        aws .StringSlice ([]string {clusterSubnetID }),
1732+ 					Tags : []* elbv2.Tag {
1733+ 						{
1734+ 							Key :   aws .String ("test" ),
1735+ 							Value : aws .String ("tag" ),
1736+ 						},
1737+ 					},
1738+ 				})).Return (& elbv2.CreateLoadBalancerOutput {
1739+ 					LoadBalancers : []* elbv2.LoadBalancer {
1740+ 						{
1741+ 							LoadBalancerArn :  aws .String (elbArn ),
1742+ 							LoadBalancerName : aws .String (elbName ),
1743+ 							Scheme :           aws .String (string (infrav1 .ELBSchemeInternetFacing )),
1744+ 							DNSName :          aws .String (dns ),
1745+ 						},
1746+ 					},
1747+ 				}, nil )
1748+ 				m .CreateTargetGroup (gomock .Eq (& elbv2.CreateTargetGroupInput {
1749+ 					Name :                       aws .String ("name" ),
1750+ 					Port :                       aws .Int64 (infrav1 .DefaultAPIServerPort ),
1751+ 					Protocol :                   aws .String ("TCP" ),
1752+ 					VpcId :                      aws .String (vpcID ),
1753+ 					HealthCheckEnabled :         aws .Bool (true ),
1754+ 					HealthCheckPort :            aws .String (infrav1 .DefaultAPIServerPortString ),
1755+ 					HealthCheckProtocol :        aws .String ("HTTP" ),
1756+ 					HealthCheckPath :            aws .String ("/readyz" ),
1757+ 					HealthCheckIntervalSeconds : aws .Int64 (10 ),
1758+ 					HealthCheckTimeoutSeconds :  aws .Int64 (5 ),
1759+ 					HealthyThresholdCount :      aws .Int64 (5 ),
1760+ 					UnhealthyThresholdCount :    aws .Int64 (3 ),
1761+ 					Tags : []* elbv2.Tag {
1762+ 						{
1763+ 							Key :   aws .String ("test" ),
1764+ 							Value : aws .String ("tag" ),
1765+ 						},
1766+ 					},
1767+ 				})).Return (& elbv2.CreateTargetGroupOutput {
1768+ 					TargetGroups : []* elbv2.TargetGroup {
1769+ 						{
1770+ 							TargetGroupArn :             aws .String ("target-group::arn" ),
1771+ 							TargetGroupName :            aws .String ("name" ),
1772+ 							VpcId :                      aws .String (vpcID ),
1773+ 							HealthCheckEnabled :         aws .Bool (true ),
1774+ 							HealthCheckPort :            aws .String (infrav1 .DefaultAPIServerPortString ),
1775+ 							HealthCheckProtocol :        aws .String ("http" ),
1776+ 							HealthCheckPath :            aws .String ("/readyz" ),
1777+ 							HealthCheckIntervalSeconds : aws .Int64 (10 ),
1778+ 							HealthCheckTimeoutSeconds :  aws .Int64 (5 ),
1779+ 							HealthyThresholdCount :      aws .Int64 (5 ),
1780+ 							UnhealthyThresholdCount :    aws .Int64 (3 ),
1781+ 						},
1782+ 					},
1783+ 				}, nil )
1784+ 				m .CreateListener (gomock .Eq (& elbv2.CreateListenerInput {
1785+ 					DefaultActions : []* elbv2.Action {
1786+ 						{
1787+ 							TargetGroupArn : aws .String ("target-group::arn" ),
1788+ 							Type :           aws .String (elbv2 .ActionTypeEnumForward ),
1789+ 						},
1790+ 					},
1791+ 					LoadBalancerArn : aws .String (elbArn ),
1792+ 					Port :            aws .Int64 (infrav1 .DefaultAPIServerPort ),
1793+ 					Protocol :        aws .String ("TCP" ),
1794+ 					Tags : []* elbv2.Tag {
1795+ 						{
1796+ 							Key :   aws .String ("test" ),
1797+ 							Value : aws .String ("tag" ),
1798+ 						},
1799+ 					},
1800+ 				})).Return (& elbv2.CreateListenerOutput {
1801+ 					Listeners : []* elbv2.Listener {
1802+ 						{
1803+ 							ListenerArn : aws .String ("listener::arn" ),
1804+ 						},
1805+ 					},
1806+ 				}, nil )
1807+ 				m .ModifyTargetGroupAttributes (gomock .Eq (& elbv2.ModifyTargetGroupAttributesInput {
1808+ 					TargetGroupArn : aws .String ("target-group::arn" ),
1809+ 					Attributes : []* elbv2.TargetGroupAttribute {
1810+ 						{
1811+ 							Key :   aws .String (infrav1 .TargetGroupAttributeEnablePreserveClientIP ),
1812+ 							Value : aws .String ("false" ),
1813+ 						},
1814+ 					},
1815+ 				})).Return (nil , nil )
1816+ 			},
1817+ 			check : func (t  * testing.T , lb  * infrav1.LoadBalancer , err  error ) {
1818+ 				t .Helper ()
1819+ 				if  err  !=  nil  {
1820+ 					t .Fatalf ("did not expect error: %v" , err )
1821+ 				}
1822+ 				got  :=  * lb .ELBListeners [0 ].TargetGroup .HealthCheck .Protocol 
1823+ 				want  :=  "HTTP" 
1824+ 				if  got  !=  want  {
1825+ 					t .Fatalf ("Health Check protocol for the API Target group did not equal expected value: %s; was: '%s'" , want , got )
1826+ 				}
1827+ 			},
1828+ 		},
1829+ 		{
1830+ 			name : "NLB with HTTPS health check" ,
1831+ 			awsCluster : func (acl  infrav1.AWSCluster ) infrav1.AWSCluster  {
1832+ 				acl .Spec .ControlPlaneLoadBalancer .Scheme  =  & infrav1 .ELBSchemeInternetFacing 
1833+ 				acl .Spec .ControlPlaneLoadBalancer .LoadBalancerType  =  infrav1 .LoadBalancerTypeNLB 
1834+ 				acl .Spec .ControlPlaneLoadBalancer .HealthCheckProtocol  =  & infrav1 .ELBProtocolHTTPS 
1835+ 				return  acl 
1836+ 			},
1837+ 			spec : func (spec  infrav1.LoadBalancer ) infrav1.LoadBalancer  {
1838+ 				tg  :=  stubInfraV1TargetGroupSpecAPI 
1839+ 				tg .VpcID  =  vpcID 
1840+ 				tg .HealthCheck .Protocol  =  aws .String ("HTTPS" )
1841+ 				tg .HealthCheck .Port  =  aws .String (infrav1 .DefaultAPIServerPortString )
1842+ 				tg .HealthCheck .Path  =  aws .String ("/readyz" )
1843+ 				spec .ELBListeners  =  []infrav1.Listener {
1844+ 					{
1845+ 						Protocol :    "TCP" ,
1846+ 						Port :        infrav1 .DefaultAPIServerPort ,
1847+ 						TargetGroup : tg ,
1848+ 					},
1849+ 				}
1850+ 				return  spec 
1851+ 			},
1852+ 			elbV2APIMocks : func (m  * mocks.MockELBV2APIMockRecorder ) {
1853+ 				m .CreateLoadBalancer (gomock .Eq (& elbv2.CreateLoadBalancerInput {
1854+ 					Name :           aws .String (elbName ),
1855+ 					Scheme :         aws .String ("internet-facing" ),
1856+ 					SecurityGroups : aws .StringSlice ([]string {}),
1857+ 					Type :           aws .String ("network" ),
1858+ 					Subnets :        aws .StringSlice ([]string {clusterSubnetID }),
1859+ 					Tags : []* elbv2.Tag {
1860+ 						{
1861+ 							Key :   aws .String ("test" ),
1862+ 							Value : aws .String ("tag" ),
1863+ 						},
1864+ 					},
1865+ 				})).Return (& elbv2.CreateLoadBalancerOutput {
1866+ 					LoadBalancers : []* elbv2.LoadBalancer {
1867+ 						{
1868+ 							LoadBalancerArn :  aws .String (elbArn ),
1869+ 							LoadBalancerName : aws .String (elbName ),
1870+ 							Scheme :           aws .String (string (infrav1 .ELBSchemeInternetFacing )),
1871+ 							DNSName :          aws .String (dns ),
1872+ 						},
1873+ 					},
1874+ 				}, nil )
1875+ 				m .CreateTargetGroup (gomock .Eq (& elbv2.CreateTargetGroupInput {
1876+ 					Name :                       aws .String ("name" ),
1877+ 					Port :                       aws .Int64 (infrav1 .DefaultAPIServerPort ),
1878+ 					Protocol :                   aws .String ("TCP" ),
1879+ 					VpcId :                      aws .String (vpcID ),
1880+ 					HealthCheckEnabled :         aws .Bool (true ),
1881+ 					HealthCheckPort :            aws .String (infrav1 .DefaultAPIServerPortString ),
1882+ 					HealthCheckProtocol :        aws .String ("HTTPS" ),
1883+ 					HealthCheckPath :            aws .String ("/readyz" ),
1884+ 					HealthCheckIntervalSeconds : aws .Int64 (10 ),
1885+ 					HealthCheckTimeoutSeconds :  aws .Int64 (5 ),
1886+ 					HealthyThresholdCount :      aws .Int64 (5 ),
1887+ 					UnhealthyThresholdCount :    aws .Int64 (3 ),
1888+ 					Tags : []* elbv2.Tag {
1889+ 						{
1890+ 							Key :   aws .String ("test" ),
1891+ 							Value : aws .String ("tag" ),
1892+ 						},
1893+ 					},
1894+ 				})).Return (& elbv2.CreateTargetGroupOutput {
1895+ 					TargetGroups : []* elbv2.TargetGroup {
1896+ 						{
1897+ 							TargetGroupArn :             aws .String ("target-group::arn" ),
1898+ 							TargetGroupName :            aws .String ("name" ),
1899+ 							VpcId :                      aws .String (vpcID ),
1900+ 							HealthCheckEnabled :         aws .Bool (true ),
1901+ 							HealthCheckPort :            aws .String (infrav1 .DefaultAPIServerPortString ),
1902+ 							HealthCheckProtocol :        aws .String ("HTTPS" ),
1903+ 							HealthCheckPath :            aws .String ("/readyz" ),
1904+ 							HealthCheckIntervalSeconds : aws .Int64 (10 ),
1905+ 							HealthCheckTimeoutSeconds :  aws .Int64 (5 ),
1906+ 							HealthyThresholdCount :      aws .Int64 (5 ),
1907+ 							UnhealthyThresholdCount :    aws .Int64 (3 ),
1908+ 						},
1909+ 					},
1910+ 				}, nil )
1911+ 				m .CreateListener (gomock .Eq (& elbv2.CreateListenerInput {
1912+ 					DefaultActions : []* elbv2.Action {
1913+ 						{
1914+ 							TargetGroupArn : aws .String ("target-group::arn" ),
1915+ 							Type :           aws .String (elbv2 .ActionTypeEnumForward ),
1916+ 						},
1917+ 					},
1918+ 					LoadBalancerArn : aws .String (elbArn ),
1919+ 					Port :            aws .Int64 (infrav1 .DefaultAPIServerPort ),
1920+ 					Protocol :        aws .String ("TCP" ),
1921+ 					Tags : []* elbv2.Tag {
1922+ 						{
1923+ 							Key :   aws .String ("test" ),
1924+ 							Value : aws .String ("tag" ),
1925+ 						},
1926+ 					},
1927+ 				})).Return (& elbv2.CreateListenerOutput {
1928+ 					Listeners : []* elbv2.Listener {
1929+ 						{
1930+ 							ListenerArn : aws .String ("listener::arn" ),
1931+ 						},
1932+ 					},
1933+ 				}, nil )
1934+ 				m .ModifyTargetGroupAttributes (gomock .Eq (& elbv2.ModifyTargetGroupAttributesInput {
1935+ 					TargetGroupArn : aws .String ("target-group::arn" ),
1936+ 					Attributes : []* elbv2.TargetGroupAttribute {
1937+ 						{
1938+ 							Key :   aws .String (infrav1 .TargetGroupAttributeEnablePreserveClientIP ),
1939+ 							Value : aws .String ("false" ),
1940+ 						},
1941+ 					},
1942+ 				})).Return (nil , nil )
1943+ 			},
1944+ 			check : func (t  * testing.T , lb  * infrav1.LoadBalancer , err  error ) {
1945+ 				t .Helper ()
1946+ 				if  err  !=  nil  {
1947+ 					t .Fatalf ("did not expect error: %v" , err )
1948+ 				}
1949+ 				got  :=  * lb .ELBListeners [0 ].TargetGroup .HealthCheck .Protocol 
1950+ 				want  :=  "HTTPS" 
1951+ 				if  got  !=  want  {
1952+ 					t .Fatalf ("Health Check protocol for the API Target group did not equal expected value: %s; was: '%s'" , want , got )
1953+ 				}
1954+ 			},
1955+ 		},
16871956	}
16881957
16891958	for  _ , tc  :=  range  tests  {
@@ -1751,7 +2020,7 @@ func TestCreateNLB(t *testing.T) {
17512020							VpcID :    vpcID ,
17522021							HealthCheck : & infrav1.TargetGroupHealthCheck {
17532022								Protocol : aws .String ("tcp" ),
1754- 								Port :     aws .String (" infrav1.DefaultAPIServerPort" 
2023+ 								Port :     aws .String (infrav1 .DefaultAPIServerPortString ),
17552024							},
17562025						},
17572026					},
0 commit comments