Skip to content

Commit 4a99157

Browse files
committed
add a test
1 parent a4f6ffc commit 4a99157

File tree

1 file changed

+307
-0
lines changed

1 file changed

+307
-0
lines changed

pkg/ingress/model_builder_test.go

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

0 commit comments

Comments
 (0)