@@ -3,11 +3,12 @@ package ingress
33import (
44 "context"
55 "encoding/json"
6- ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
7- elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
86 "testing"
97 "time"
108
9+ ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
10+ elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
11+
1112 awssdk "github.com/aws/aws-sdk-go-v2/aws"
1213 jsonpatch "github.com/evanphx/json-patch"
1314 "github.com/go-logr/logr"
@@ -2140,6 +2141,313 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
21402141 "80:3": null
21412142 }
21422143 }
2144+ }` ,
2145+ },
2146+ {
2147+ name : "Ingress - target-type in IngressClassParams" ,
2148+ env : env {
2149+ svcs : []* corev1.Service {ns_1_svc_1 , ns_1_svc_2 , ns_1_svc_3 },
2150+ },
2151+ fields : fields {
2152+ resolveViaDiscoveryCalls : []resolveViaDiscoveryCall {resolveViaDiscoveryCallForInternalLB },
2153+ listLoadBalancersCalls : []listLoadBalancersCall {listLoadBalancerCallForEmptyLB },
2154+ enableBackendSG : true ,
2155+ },
2156+ args : args {
2157+ ingGroup : Group {
2158+ ID : GroupID {Namespace : "ns-1" , Name : "ing-1" },
2159+ Members : []ClassifiedIngress {
2160+ {
2161+ IngClassConfig : ClassConfiguration {
2162+ IngClassParams : & v1beta1.IngressClassParams {
2163+ Spec : v1beta1.IngressClassParamsSpec {
2164+ TargetType : v1beta1 .TargetTypeIP ,
2165+ },
2166+ },
2167+ },
2168+ Ing : & networking.Ingress {ObjectMeta : metav1.ObjectMeta {
2169+ Namespace : "ns-1" ,
2170+ Name : "ing-1" ,
2171+ Annotations : map [string ]string {
2172+ "alb.ingress.kubernetes.io/target-type" : string (v1beta1 .TargetTypeInstance ),
2173+ },
2174+ },
2175+ Spec : networking.IngressSpec {
2176+ Rules : []networking.IngressRule {
2177+ {
2178+ Host : "app-1.example.com" ,
2179+ IngressRuleValue : networking.IngressRuleValue {
2180+ HTTP : & networking.HTTPIngressRuleValue {
2181+ Paths : []networking.HTTPIngressPath {
2182+ {
2183+ Path : "/svc-1" ,
2184+ Backend : networking.IngressBackend {
2185+ Service : & networking.IngressServiceBackend {
2186+ Name : ns_1_svc_1 .Name ,
2187+ Port : networking.ServiceBackendPort {
2188+ Name : "http" ,
2189+ },
2190+ },
2191+ },
2192+ },
2193+ {
2194+ Path : "/svc-2" ,
2195+ Backend : networking.IngressBackend {
2196+ Service : & networking.IngressServiceBackend {
2197+ Name : ns_1_svc_2 .Name ,
2198+ Port : networking.ServiceBackendPort {
2199+ Name : "http" ,
2200+ },
2201+ },
2202+ },
2203+ },
2204+ },
2205+ },
2206+ },
2207+ },
2208+ {
2209+ Host : "app-2.example.com" ,
2210+ IngressRuleValue : networking.IngressRuleValue {
2211+ HTTP : & networking.HTTPIngressRuleValue {
2212+ Paths : []networking.HTTPIngressPath {
2213+ {
2214+ Path : "/svc-3" ,
2215+ Backend : networking.IngressBackend {
2216+ Service : & networking.IngressServiceBackend {
2217+ Name : ns_1_svc_3 .Name ,
2218+ Port : networking.ServiceBackendPort {
2219+ Name : "https" ,
2220+ },
2221+ },
2222+ },
2223+ },
2224+ },
2225+ },
2226+ },
2227+ },
2228+ },
2229+ },
2230+ },
2231+ },
2232+ },
2233+ },
2234+ },
2235+ defaultTargetType : "instance" ,
2236+ wantStackPatch : `
2237+ {
2238+ "resources": {
2239+ "AWS::ElasticLoadBalancingV2::TargetGroup":{
2240+ "ns-1/ing-1-svc-1:http":{
2241+ "spec":{
2242+ "name":"k8s-ns1-svc1-6350990f3a",
2243+ "targetType":"ip",
2244+ "ipAddressType":"ipv4",
2245+ "port":8080,
2246+ "protocol":"HTTP",
2247+ "protocolVersion":"HTTP1",
2248+ "healthCheckConfig":{
2249+ "port":"traffic-port",
2250+ "protocol":"HTTP",
2251+ "path":"/",
2252+ "matcher":{
2253+ "httpCode":"200"
2254+ },
2255+ "intervalSeconds":15,
2256+ "timeoutSeconds":5,
2257+ "healthyThresholdCount":2,
2258+ "unhealthyThresholdCount":2
2259+ }
2260+ }
2261+ },
2262+ "ns-1/ing-1-svc-2:http":{
2263+ "spec":{
2264+ "name":"k8s-ns1-svc2-6350990f3a",
2265+ "targetType":"ip",
2266+ "ipAddressType":"ipv4",
2267+ "port":8080,
2268+ "protocol":"HTTP",
2269+ "protocolVersion":"HTTP1",
2270+ "healthCheckConfig":{
2271+ "port":"traffic-port",
2272+ "protocol":"HTTP",
2273+ "path":"/",
2274+ "matcher":{
2275+ "httpCode":"200"
2276+ },
2277+ "intervalSeconds":15,
2278+ "timeoutSeconds":5,
2279+ "healthyThresholdCount":2,
2280+ "unhealthyThresholdCount":2
2281+ }
2282+ }
2283+ },
2284+ "ns-1/ing-1-svc-3:https":{
2285+ "spec":{
2286+ "name":"k8s-ns1-svc3-bf42870fba",
2287+ "targetType":"ip",
2288+ "ipAddressType":"ipv4",
2289+ "port":8443,
2290+ "protocol":"HTTPS",
2291+ "protocolVersion":"HTTP1",
2292+ "healthCheckConfig":{
2293+ "port":9090,
2294+ "protocol":"HTTPS",
2295+ "path":"/health-check",
2296+ "matcher":{
2297+ "httpCode":"200-300"
2298+ },
2299+ "intervalSeconds":20,
2300+ "timeoutSeconds":10,
2301+ "healthyThresholdCount":7,
2302+ "unhealthyThresholdCount":5
2303+ }
2304+ }
2305+ }
2306+ },
2307+ "K8S::ElasticLoadBalancingV2::TargetGroupBinding":{
2308+ "ns-1/ing-1-svc-1:http":{
2309+ "spec":{
2310+ "template":{
2311+ "metadata":{
2312+ "name":"k8s-ns1-svc1-6350990f3a",
2313+ "namespace":"ns-1",
2314+ "creationTimestamp":null
2315+ },
2316+ "spec":{
2317+ "targetGroupARN":{
2318+ "$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/ns-1/ing-1-svc-1:http/status/targetGroupARN"
2319+ },
2320+ "targetType":"ip",
2321+ "vpcID": "vpc-dummy",
2322+ "ipAddressType":"ipv4",
2323+ "serviceRef":{
2324+ "name":"svc-1",
2325+ "port":"http"
2326+ },
2327+ "networking":{
2328+ "ingress":[
2329+ {
2330+ "from":[
2331+ {
2332+ "securityGroup":{
2333+ "groupID": "sg-auto"
2334+ }
2335+ }
2336+ ],
2337+ "ports":[
2338+ {
2339+ "port":8080,
2340+ "protocol":"TCP"
2341+ }
2342+ ]
2343+ }
2344+ ]
2345+ }
2346+ }
2347+ }
2348+ }
2349+ },
2350+ "ns-1/ing-1-svc-2:http":{
2351+ "spec":{
2352+ "template":{
2353+ "metadata":{
2354+ "name":"k8s-ns1-svc2-6350990f3a",
2355+ "namespace":"ns-1",
2356+ "creationTimestamp":null
2357+ },
2358+ "spec":{
2359+ "targetGroupARN":{
2360+ "$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/ns-1/ing-1-svc-2:http/status/targetGroupARN"
2361+ },
2362+ "targetType":"ip",
2363+ "ipAddressType":"ipv4",
2364+ "vpcID": "vpc-dummy",
2365+ "serviceRef":{
2366+ "name":"svc-2",
2367+ "port":"http"
2368+ },
2369+ "networking":{
2370+ "ingress":[
2371+ {
2372+ "from":[
2373+ {
2374+ "securityGroup":{
2375+ "groupID": "sg-auto"
2376+ }
2377+ }
2378+ ],
2379+ "ports":[
2380+ {
2381+ "port":8080,
2382+ "protocol":"TCP"
2383+ }
2384+ ]
2385+ }
2386+ ]
2387+ }
2388+ }
2389+ }
2390+ }
2391+ },
2392+ "ns-1/ing-1-svc-3:https":{
2393+ "spec":{
2394+ "template":{
2395+ "metadata":{
2396+ "name":"k8s-ns1-svc3-bf42870fba",
2397+ "namespace":"ns-1",
2398+ "creationTimestamp":null
2399+ },
2400+ "spec":{
2401+ "targetGroupARN":{
2402+ "$ref":"#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/ns-1/ing-1-svc-3:https/status/targetGroupARN"
2403+ },
2404+ "targetType":"ip",
2405+ "vpcID": "vpc-dummy",
2406+ "ipAddressType":"ipv4",
2407+ "serviceRef":{
2408+ "name":"svc-3",
2409+ "port":"https"
2410+ },
2411+ "networking":{
2412+ "ingress":[
2413+ {
2414+ "from":[
2415+ {
2416+ "securityGroup":{
2417+ "groupID": "sg-auto"
2418+ }
2419+ }
2420+ ],
2421+ "ports":[
2422+ {
2423+ "port": 8443,
2424+ "protocol":"TCP"
2425+ }
2426+ ]
2427+ },
2428+ {
2429+ "from":[
2430+ {
2431+ "securityGroup":{
2432+ "groupID": "sg-auto"
2433+ }
2434+ }
2435+ ],
2436+ "ports":[
2437+ {
2438+ "port": 9090,
2439+ "protocol":"TCP"
2440+ }
2441+ ]
2442+ }
2443+ ]
2444+ }
2445+ }
2446+ }
2447+ }
2448+ }
2449+ }
2450+ }
21432451}` ,
21442452 },
21452453 {
0 commit comments