@@ -11,13 +11,13 @@ import (
1111 "time"
1212
1313 n "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
14+ "github.com/Azure/go-autorest/autorest/to"
1415 "github.com/onsi/ginkgo"
1516 . "github.com/onsi/gomega"
1617 v1 "k8s.io/api/core/v1"
1718 "k8s.io/api/extensions/v1beta1"
1819 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1920 "k8s.io/apimachinery/pkg/util/intstr"
20- "github.com/Azure/go-autorest/autorest/to"
2121 testclient "k8s.io/client-go/kubernetes/fake"
2222 "k8s.io/client-go/tools/record"
2323
@@ -30,6 +30,7 @@ import (
3030 "github.com/Azure/application-gateway-kubernetes-ingress/pkg/version"
3131
3232 . "github.com/Azure/application-gateway-kubernetes-ingress/pkg/appgw"
33+ "github.com/Azure/application-gateway-kubernetes-ingress/pkg/utils"
3334)
3435
3536func TestFunctional (t * testing.T ) {
@@ -46,8 +47,6 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
4647 version .GitCommit = "b"
4748 version .BuildDate = "c"
4849
49- ingressNS := "test-ingress-controller"
50-
5150 serviceName := "hello-world"
5251 serviceNameA := "hello-world-a"
5352 serviceNameB := "hello-world-b"
@@ -61,7 +60,7 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
6160 // We will create all our resources under this namespace.
6261 ns := & v1.Namespace {
6362 ObjectMeta : metav1.ObjectMeta {
64- Name : ingressNS ,
63+ Name : tests . Namespace ,
6564 },
6665 }
6766
@@ -102,6 +101,7 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
102101 TLS : []v1beta1.IngressTLS {
103102 {
104103 Hosts : []string {
104+ "foo.baz" ,
105105 "www.contoso.com" ,
106106 "ftp.contoso.com" ,
107107 tests .Host ,
@@ -120,7 +120,43 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
120120 annotations .IngressClassKey : annotations .ApplicationGatewayIngressClass ,
121121 annotations .SslRedirectKey : "true" ,
122122 },
123- Namespace : ingressNS ,
123+ Namespace : tests .Namespace ,
124+ Name : tests .Name ,
125+ },
126+ }
127+
128+ ingressSecret := tests .NewSecretTestFixture ()
129+
130+ // Create an Ingress resource for the same domain but no TLS
131+ ingressFooBazNoTLS := & v1beta1.Ingress {
132+ Spec : v1beta1.IngressSpec {
133+ Rules : []v1beta1.IngressRule {
134+ {
135+ Host : "foo.baz" ,
136+ IngressRuleValue : v1beta1.IngressRuleValue {
137+ HTTP : & v1beta1.HTTPIngressRuleValue {
138+ Paths : []v1beta1.HTTPIngressPath {
139+ {
140+ Path : "/.well-known/acme-challenge/blahBlahBBLLAAHH" ,
141+ Backend : v1beta1.IngressBackend {
142+ ServiceName : serviceNameB ,
143+ ServicePort : intstr.IntOrString {
144+ Type : intstr .Int ,
145+ IntVal : 80 ,
146+ },
147+ },
148+ },
149+ },
150+ },
151+ },
152+ },
153+ },
154+ },
155+ ObjectMeta : metav1.ObjectMeta {
156+ Annotations : map [string ]string {
157+ annotations .IngressClassKey : annotations .ApplicationGatewayIngressClass ,
158+ },
159+ Namespace : tests .Namespace ,
124160 Name : tests .Name ,
125161 },
126162 }
@@ -129,7 +165,7 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
129165 service := & v1.Service {
130166 ObjectMeta : metav1.ObjectMeta {
131167 Name : serviceName ,
132- Namespace : ingressNS ,
168+ Namespace : tests . Namespace ,
133169 },
134170 Spec : v1.ServiceSpec {
135171 Ports : []v1.ServicePort {
@@ -150,7 +186,7 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
150186 serviceA := & v1.Service {
151187 ObjectMeta : metav1.ObjectMeta {
152188 Name : serviceNameA ,
153- Namespace : ingressNS ,
189+ Namespace : tests . Namespace ,
154190 },
155191 Spec : v1.ServiceSpec {
156192 Ports : []v1.ServicePort {
@@ -171,7 +207,7 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
171207 serviceB := & v1.Service {
172208 ObjectMeta : metav1.ObjectMeta {
173209 Name : serviceNameB ,
174- Namespace : ingressNS ,
210+ Namespace : tests . Namespace ,
175211 },
176212 Spec : v1.ServiceSpec {
177213 Ports : []v1.ServicePort {
@@ -202,7 +238,7 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
202238 endpoints := & v1.Endpoints {
203239 ObjectMeta : metav1.ObjectMeta {
204240 Name : serviceName ,
205- Namespace : ingressNS ,
241+ Namespace : tests . Namespace ,
206242 },
207243 Subsets : []v1.EndpointSubset {
208244 {
@@ -225,7 +261,7 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
225261 endpointsA := & v1.Endpoints {
226262 ObjectMeta : metav1.ObjectMeta {
227263 Name : serviceNameA ,
228- Namespace : ingressNS ,
264+ Namespace : tests . Namespace ,
229265 },
230266 Subsets : []v1.EndpointSubset {
231267 {
@@ -248,7 +284,7 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
248284 endpointsB := & v1.Endpoints {
249285 ObjectMeta : metav1.ObjectMeta {
250286 Name : serviceNameB ,
251- Namespace : ingressNS ,
287+ Namespace : tests . Namespace ,
252288 },
253289 Subsets : []v1.EndpointSubset {
254290 {
@@ -268,7 +304,7 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
268304 },
269305 }
270306
271- pod := tests .NewPodFixture (serviceName , ingressNS , backendName , int32 (backendPort ))
307+ pod := tests .NewPodFixture (serviceName , tests . Namespace , backendName , int32 (backendPort ))
272308
273309 _ = flag .Lookup ("logtostderr" ).Value .Set ("true" )
274310 _ = flag .Set ("v" , "3" )
@@ -286,16 +322,23 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
286322 k8sClient := testclient .NewSimpleClientset ()
287323 _ , _ = k8sClient .CoreV1 ().Namespaces ().Create (ns )
288324 _ , _ = k8sClient .CoreV1 ().Nodes ().Create (node )
289- _ , _ = k8sClient .ExtensionsV1beta1 ().Ingresses (ingressNS ).Create (ingress )
290- _ , _ = k8sClient .CoreV1 ().Services (ingressNS ).Create (service )
291- _ , _ = k8sClient .CoreV1 ().Endpoints (ingressNS ).Create (endpoints )
292- _ , _ = k8sClient .CoreV1 ().Endpoints (ingressNS ).Create (endpointsA )
293- _ , _ = k8sClient .CoreV1 ().Endpoints (ingressNS ).Create (endpointsB )
294- _ , _ = k8sClient .CoreV1 ().Pods (ingressNS ).Create (pod )
325+ _ , _ = k8sClient .ExtensionsV1beta1 ().Ingresses (tests .Namespace ).Create (ingress )
326+ _ , _ = k8sClient .CoreV1 ().Services (tests .Namespace ).Create (service )
327+ _ , _ = k8sClient .CoreV1 ().Services (tests .Namespace ).Create (serviceA )
328+ _ , _ = k8sClient .CoreV1 ().Services (tests .Namespace ).Create (serviceB )
329+ _ , _ = k8sClient .CoreV1 ().Endpoints (tests .Namespace ).Create (endpoints )
330+ _ , _ = k8sClient .CoreV1 ().Endpoints (tests .Namespace ).Create (endpointsA )
331+ _ , _ = k8sClient .CoreV1 ().Endpoints (tests .Namespace ).Create (endpointsB )
332+ _ , _ = k8sClient .CoreV1 ().Pods (tests .Namespace ).Create (pod )
333+ _ , _ = k8sClient .CoreV1 ().Secrets (tests .Namespace ).Create (ingressSecret )
295334
296335 crdClient := fake .NewSimpleClientset ()
297336 istioCrdClient := istio_fake .NewSimpleClientset ()
298- ctxt = k8scontext .NewContext (k8sClient , crdClient , istioCrdClient , []string {ingressNS }, 1000 * time .Second )
337+ ctxt = k8scontext .NewContext (k8sClient , crdClient , istioCrdClient , []string {tests .Namespace }, 1000 * time .Second )
338+
339+ secKey := utils .GetResourceKey (ingressSecret .Namespace , ingressSecret .Name )
340+ _ = ctxt .CertificateSecretStore .ConvertSecret (secKey , ingressSecret )
341+ _ = ctxt .CertificateSecretStore .GetPfxCertificate (secKey )
299342
300343 appGwy := & n.ApplicationGateway {
301344 ApplicationGatewayPropertiesFormat : NewAppGwyConfigFixture (),
@@ -337,7 +380,7 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
337380 Annotations : map [string ]string {
338381 annotations .IngressClassKey : annotations .ApplicationGatewayIngressClass ,
339382 },
340- Namespace : ingressNS ,
383+ Namespace : tests . Namespace ,
341384 Name : tests .Name ,
342385 },
343386 }
@@ -370,7 +413,7 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
370413 Annotations : map [string ]string {
371414 annotations .IngressClassKey : annotations .ApplicationGatewayIngressClass ,
372415 },
373- Namespace : ingressNS ,
416+ Namespace : tests . Namespace ,
374417 Name : tests .Name ,
375418 },
376419 }
@@ -403,7 +446,7 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
403446 Annotations : map [string ]string {
404447 annotations .IngressClassKey : annotations .ApplicationGatewayIngressClass ,
405448 },
406- Namespace : ingressNS ,
449+ Namespace : tests . Namespace ,
407450 Name : tests .Name ,
408451 },
409452 }
@@ -464,5 +507,19 @@ var _ = ginkgo.Describe("Tests `appgw.ConfigBuilder`", func() {
464507 check (cbCtx , "two_ingresses_slash_slashsomething.json" , stopChannel , ctxt , configBuilder )
465508 })
466509
510+ ginkgo .It ("TWO Ingress Resources for the same domain: one with TLS, another without" , func () {
511+ cbCtx := & ConfigBuilderContext {
512+ IngressList : []* v1beta1.Ingress {
513+ ingress ,
514+ ingressFooBazNoTLS ,
515+ },
516+ ServiceList : serviceList ,
517+ EnvVariables : environment .GetFakeEnv (),
518+ DefaultAddressPoolID : to .StringPtr ("xx" ),
519+ DefaultHTTPSettingsID : to .StringPtr ("yy" ),
520+ }
521+ check (cbCtx , "two_ingresses_same_domain_tls_notls.json" , stopChannel , ctxt , configBuilder )
522+ })
523+
467524 })
468525})
0 commit comments