@@ -3,11 +3,13 @@ package service
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ awssdk "github.com/aws/aws-sdk-go/aws"
6
7
. "github.com/onsi/ginkgo"
7
8
. "github.com/onsi/gomega"
8
9
corev1 "k8s.io/api/core/v1"
9
10
"sigs.k8s.io/aws-load-balancer-controller/test/framework/http"
10
11
"sigs.k8s.io/aws-load-balancer-controller/test/framework/utils"
12
+ "strings"
11
13
)
12
14
13
15
var _ = Describe ("test k8s service reconciled by the aws load balancer controller" , func () {
@@ -84,7 +86,7 @@ var _ = Describe("test k8s service reconciled by the aws load balancer controlle
84
86
})
85
87
86
88
By ("enabling cross zone load balancing" , func () {
87
- err := stack .UpdateServiceAnnotation (ctx , tf , map [string ]string {
89
+ err := stack .UpdateServiceAnnotations (ctx , tf , map [string ]string {
88
90
"service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled" : "true" ,
89
91
})
90
92
Expect (err ).NotTo (HaveOccurred ())
@@ -97,7 +99,7 @@ var _ = Describe("test k8s service reconciled by the aws load balancer controlle
97
99
})
98
100
99
101
By ("specifying load balancer tags" , func () {
100
- err := stack .UpdateServiceAnnotation (ctx , tf , map [string ]string {
102
+ err := stack .UpdateServiceAnnotations (ctx , tf , map [string ]string {
101
103
"service.beta.kubernetes.io/aws-load-balancer-additional-resource-tags" : "instance-mode=true, key1=value1" ,
102
104
})
103
105
Expect (err ).NotTo (HaveOccurred ())
@@ -174,7 +176,7 @@ var _ = Describe("test k8s service reconciled by the aws load balancer controlle
174
176
Expect (err ).NotTo (HaveOccurred ())
175
177
})
176
178
By ("specifying target group attributes annotation" , func () {
177
- err := stack .UpdateServiceAnnotation (ctx , tf , map [string ]string {
179
+ err := stack .UpdateServiceAnnotations (ctx , tf , map [string ]string {
178
180
"service.beta.kubernetes.io/aws-load-balancer-target-group-attributes" : "preserve_client_ip.enabled=false, proxy_protocol_v2.enabled=true, deregistration_delay.timeout_seconds=120" ,
179
181
})
180
182
Expect (err ).NotTo (HaveOccurred ())
@@ -188,5 +190,144 @@ var _ = Describe("test k8s service reconciled by the aws load balancer controlle
188
190
}, utils .PollTimeoutShort , utils .PollIntervalMedium ).Should (BeTrue ())
189
191
})
190
192
})
193
+ It ("should create TLS listeners" , func () {
194
+ if len (tf .Options .CertificateARNs ) == 0 {
195
+ Skip ("Skipping tests, certificates not specified" )
196
+ }
197
+ By ("deploying stack" , func () {
198
+ err := stack .Deploy (ctx , tf , map [string ]string {
199
+ "service.beta.kubernetes.io/aws-load-balancer-ssl-cert" : tf .Options .CertificateARNs ,
200
+ })
201
+ Expect (err ).NotTo (HaveOccurred ())
202
+ })
203
+ By ("checking service status for lb dns name" , func () {
204
+ dnsName = stack .GetLoadBalancerIngressHostName ()
205
+ Expect (dnsName ).ToNot (BeEmpty ())
206
+ })
207
+
208
+ By ("querying AWS loadbalancer from the dns name" , func () {
209
+ var err error
210
+ lbARN , err = tf .LBManager .FindLoadBalancerByDNSName (ctx , dnsName )
211
+ Expect (err ).NotTo (HaveOccurred ())
212
+ Expect (lbARN ).ToNot (BeEmpty ())
213
+ })
214
+ By ("verifying AWS loadbalancer resources" , func () {
215
+ err := verifyAWSLoadBalancerResources (ctx , tf , lbARN , LoadBalancerExpectation {
216
+ Type : "network" ,
217
+ Scheme : "internet-facing" ,
218
+ TargetType : "instance" ,
219
+ Listeners : map [string ]string {
220
+ "80" : "TLS" ,
221
+ },
222
+ TargetGroups : stack .resourceStack .getTargetGroupNodePortMap (),
223
+ NumTargets : 0 ,
224
+ TargetGroupHC : & TargetGroupHC {
225
+ Protocol : "TCP" ,
226
+ Port : "traffic-port" ,
227
+ Interval : 10 ,
228
+ Timeout : 10 ,
229
+ HealthyThreshold : 3 ,
230
+ UnhealthyThreshold : 3 ,
231
+ },
232
+ })
233
+ Expect (err ).NotTo (HaveOccurred ())
234
+ })
235
+ By ("verifying listener certificates" , func () {
236
+ expectedARNs := strings .Split (tf .Options .CertificateARNs , "," )
237
+ Eventually (func () bool {
238
+ return verifyLoadBalancerListenerCertificates (ctx , tf , lbARN , expectedARNs ) == nil
239
+ }, utils .PollTimeoutShort , utils .PollIntervalMedium ).Should (BeTrue ())
240
+ })
241
+ By ("removing first certificate from annotation and updating the service" , func () {
242
+ certs := strings .Split (tf .Options .CertificateARNs , "," )[1 :]
243
+ if len (certs ) == 0 {
244
+ return
245
+ }
246
+ err := stack .UpdateServiceAnnotations (ctx , tf , map [string ]string {
247
+ "service.beta.kubernetes.io/aws-load-balancer-ssl-cert" : strings .Join (certs , "," ),
248
+ })
249
+ Expect (err ).NotTo (HaveOccurred ())
250
+ Eventually (func () bool {
251
+ return verifyLoadBalancerListenerCertificates (ctx , tf , lbARN , certs ) == nil
252
+ }, utils .PollTimeoutShort , utils .PollIntervalMedium ).Should (BeTrue ())
253
+ })
254
+ })
255
+ It ("should enable proxy protocol v2" , func () {
256
+ By ("deploying stack" , func () {
257
+ err := stack .Deploy (ctx , tf , map [string ]string {
258
+ "service.beta.kubernetes.io/aws-load-balancer-proxy-protocol" : "*" ,
259
+ })
260
+ Expect (err ).ToNot (HaveOccurred ())
261
+ dnsName = stack .GetLoadBalancerIngressHostName ()
262
+ Expect (dnsName ).ToNot (BeEmpty ())
263
+ lbARN , err = tf .LBManager .FindLoadBalancerByDNSName (ctx , dnsName )
264
+ Expect (err ).NotTo (HaveOccurred ())
265
+ Expect (lbARN ).ToNot (BeEmpty ())
266
+ })
267
+ By ("verifying target group attributes" , func () {
268
+ verified := verifyTargetGroupAttributes (ctx , tf , lbARN , map [string ]string {
269
+ "proxy_protocol_v2.enabled" : "true" ,
270
+ })
271
+ Expect (verified ).To (BeTrue ())
272
+ })
273
+ By ("verifying precedence with target group attributes configuration" , func () {
274
+ err := stack .UpdateServiceAnnotations (ctx , tf , map [string ]string {
275
+ "service.beta.kubernetes.io/aws-load-balancer-target-group-attributes" : "proxy_protocol_v2.enabled=false, deregistration_delay.timeout_seconds=120" ,
276
+ })
277
+ Expect (err ).NotTo (HaveOccurred ())
278
+ Eventually (func () bool {
279
+ return verifyTargetGroupAttributes (ctx , tf , lbARN , map [string ]string {
280
+ "proxy_protocol_v2.enabled" : "true" ,
281
+ "deregistration_delay.timeout_seconds" : "120" ,
282
+ })
283
+ }, utils .PollTimeoutShort , utils .PollIntervalMedium ).Should (BeTrue ())
284
+ })
285
+ })
286
+ })
287
+
288
+ Context ("with NLB instance target configuration with target node labels" , func () {
289
+ It ("should add only the labelled nodes to the target group" , func () {
290
+ By ("deploying stack" , func () {
291
+ err := stack .Deploy (ctx , tf , map [string ]string {
292
+ "service.beta.kubernetes.io/aws-load-balancer-target-node-labels" : "service.node.label/key1=value1" ,
293
+ })
294
+ Expect (err ).ToNot (HaveOccurred ())
295
+ dnsName = stack .GetLoadBalancerIngressHostName ()
296
+ Expect (dnsName ).ToNot (BeEmpty ())
297
+ lbARN , err = tf .LBManager .FindLoadBalancerByDNSName (ctx , dnsName )
298
+ Expect (err ).NotTo (HaveOccurred ())
299
+ Expect (lbARN ).ToNot (BeEmpty ())
300
+ })
301
+ By ("applying label to 1 worker node" , func () {
302
+ nodes , err := stack .GetWorkerNodes (ctx , tf )
303
+ Expect (err ).ToNot (HaveOccurred ())
304
+ Expect (len (nodes )).To (BeNumerically (">" , 0 ))
305
+ err = stack .ApplyNodeLabels (ctx , tf , & nodes [0 ], map [string ]string {"service.node.label/key1" : "value1" })
306
+ Expect (err ).ToNot (HaveOccurred ())
307
+
308
+ targetGroups , err := tf .TGManager .GetTargetGroupsForLoadBalancer (ctx , lbARN )
309
+ Expect (err ).ToNot (HaveOccurred ())
310
+ Expect (len (targetGroups )).To (Equal (1 ))
311
+ tgARN := awssdk .StringValue (targetGroups [0 ].TargetGroupArn )
312
+
313
+ err = verifyTargetGroupNumRegistered (ctx , tf , tgARN , 1 )
314
+ Expect (err ).ToNot (HaveOccurred ())
315
+ })
316
+ By ("removing target-node-labels annotation from the service" , func () {
317
+ err := stack .DeleteServiceAnnotations (ctx , tf , []string {"service.beta.kubernetes.io/aws-load-balancer-target-node-labels" })
318
+ Expect (err ).ToNot (HaveOccurred ())
319
+
320
+ targetGroups , err := tf .TGManager .GetTargetGroupsForLoadBalancer (ctx , lbARN )
321
+ Expect (err ).ToNot (HaveOccurred ())
322
+ Expect (len (targetGroups )).To (Equal (1 ))
323
+ tgARN := awssdk .StringValue (targetGroups [0 ].TargetGroupArn )
324
+
325
+ nodes , err := stack .GetWorkerNodes (ctx , tf )
326
+ Expect (err ).ToNot (HaveOccurred ())
327
+
328
+ err = verifyTargetGroupNumRegistered (ctx , tf , tgARN , len (nodes ))
329
+ Expect (err ).ToNot (HaveOccurred ())
330
+ })
331
+ })
191
332
})
192
333
})
0 commit comments