Skip to content

Commit 7ee4cd4

Browse files
authored
Filter IngressTLS for visibility (knative-extensions#1216)
IngressVisibilityExternalIP
1 parent 0a04929 commit 7ee4cd4

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

pkg/reconciler/ingress/ingress.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (r *Reconciler) reconcileIngress(ctx context.Context, ing *v1alpha1.Ingress
143143
return err
144144
}
145145

146-
nonWildcardIngressTLS := resources.GetNonWildcardIngressTLS(ing.Spec.TLS, nonWildcardSecrets)
146+
nonWildcardIngressTLS := resources.GetNonWildcardIngressTLS(ing.GetIngressTLSForVisibility(v1alpha1.IngressVisibilityExternalIP), nonWildcardSecrets)
147147
ingressGateways, err = resources.MakeIngressTLSGateways(ctx, ing, nonWildcardIngressTLS, nonWildcardSecrets, r.svcLister)
148148
if err != nil {
149149
return err
@@ -419,7 +419,7 @@ func (r *Reconciler) reconcileDeletion(ctx context.Context, ing *v1alpha1.Ingres
419419
}
420420

421421
errs := []error{}
422-
for _, tls := range ing.Spec.TLS {
422+
for _, tls := range ing.GetIngressTLSForVisibility(v1alpha1.IngressVisibilityExternalIP) {
423423
nameNamespaces, err := resources.GetIngressGatewaySvcNameNamespaces(ctx)
424424
if err != nil {
425425
errs = append(errs, err)
@@ -542,14 +542,14 @@ func getLBStatus(gatewayServiceURL string) []v1alpha1.LoadBalancerIngressStatus
542542
}
543543

544544
func shouldReconcileTLS(ing *v1alpha1.Ingress) bool {
545-
return isIngressPublic(ing) && len(ing.Spec.TLS) > 0
545+
return isIngressPublic(ing) && len(ing.GetIngressTLSForVisibility(v1alpha1.IngressVisibilityExternalIP)) > 0
546546
}
547547

548548
func shouldReconcileHTTPServer(ing *v1alpha1.Ingress) bool {
549549
// We will create a Ingress specific HTTPServer when
550550
// 1. auto TLS is enabled as in this case users want us to fully handle the TLS/HTTP behavior,
551551
// 2. HTTPOption is set to Redirected as we don't have default HTTP server supporting HTTP redirection.
552-
return isIngressPublic(ing) && (ing.Spec.HTTPOption == v1alpha1.HTTPOptionRedirected || len(ing.Spec.TLS) > 0)
552+
return isIngressPublic(ing) && (ing.Spec.HTTPOption == v1alpha1.HTTPOptionRedirected || len(ing.GetIngressTLSForVisibility(v1alpha1.IngressVisibilityExternalIP)) > 0)
553553
}
554554

555555
func isIngressPublic(ing *v1alpha1.Ingress) bool {

pkg/reconciler/ingress/resources/gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func MakeIngressTLSGateways(ctx context.Context, ing *v1alpha1.Ingress, ingressT
116116
}
117117
gateways := make([]*v1beta1.Gateway, len(gatewayServices))
118118
for i, gatewayService := range gatewayServices {
119-
servers, err := MakeTLSServers(ing, ing.Spec.TLS, gatewayService.Namespace, originSecrets)
119+
servers, err := MakeTLSServers(ing, ing.GetIngressTLSForVisibility(v1alpha1.IngressVisibilityExternalIP), gatewayService.Namespace, originSecrets)
120120
if err != nil {
121121
return nil, err
122122
}

pkg/reconciler/ingress/resources/gateway_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ var modifiedDefaultTLSServer = istiov1beta1.Server{
139139

140140
var ingressSpec = v1alpha1.IngressSpec{
141141
Rules: []v1alpha1.IngressRule{{
142-
Hosts: []string{"host1.example.com"},
142+
Hosts: []string{"host1.example.com"},
143+
Visibility: v1alpha1.IngressVisibilityExternalIP,
143144
}},
144145
TLS: []v1alpha1.IngressTLS{{
145146
Hosts: []string{"host1.example.com"},
@@ -294,7 +295,7 @@ func TestMakeTLSServers(t *testing.T) {
294295
}}
295296
for _, c := range cases {
296297
t.Run(c.name, func(t *testing.T) {
297-
servers, err := MakeTLSServers(c.ci, c.ci.Spec.TLS, c.gatewayServiceNamespace, c.originSecrets)
298+
servers, err := MakeTLSServers(c.ci, c.ci.GetIngressTLSForVisibility(v1alpha1.IngressVisibilityExternalIP), c.gatewayServiceNamespace, c.originSecrets)
298299
if (err != nil) != c.wantErr {
299300
t.Fatalf("Test: %s; MakeServers error = %v, WantErr %v", c.name, err, c.wantErr)
300301
}
@@ -960,7 +961,7 @@ func TestMakeIngressTLSGateways(t *testing.T) {
960961
},
961962
})
962963
t.Run(c.name, func(t *testing.T) {
963-
got, err := MakeIngressTLSGateways(ctx, c.ia, c.ia.Spec.TLS, c.originSecrets, svcLister)
964+
got, err := MakeIngressTLSGateways(ctx, c.ia, c.ia.GetIngressTLSForVisibility(v1alpha1.IngressVisibilityExternalIP), c.originSecrets, svcLister)
964965
if (err != nil) != c.wantErr {
965966
t.Fatalf("Test: %s; MakeIngressTLSGateways error = %v, WantErr %v", c.name, err, c.wantErr)
966967
}

pkg/reconciler/ingress/resources/secret.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
// returns a map whose key is the a secret namespace/name key and value is pointer of the secret.
3838
func GetSecrets(ing *v1alpha1.Ingress, secretLister corev1listers.SecretLister) (map[string]*corev1.Secret, error) {
3939
secrets := map[string]*corev1.Secret{}
40-
for _, tls := range ing.Spec.TLS {
40+
for _, tls := range ing.GetIngressTLSForVisibility(v1alpha1.IngressVisibilityExternalIP) {
4141
ref := secretKey(tls)
4242
if _, ok := secrets[ref]; ok {
4343
continue

pkg/reconciler/ingress/resources/secret_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ var (
5151
Namespace: system.Namespace(),
5252
},
5353
Spec: v1alpha1.IngressSpec{
54+
Rules: []v1alpha1.IngressRule{
55+
{
56+
Hosts: []string{"example.com"},
57+
Visibility: v1alpha1.IngressVisibilityExternalIP,
58+
},
59+
},
5460
TLS: []v1alpha1.IngressTLS{{
5561
Hosts: []string{"example.com"},
5662
SecretName: "secret0",
@@ -90,6 +96,12 @@ func TestGetSecrets(t *testing.T) {
9096
secret: &corev1.Secret{},
9197
ci: &v1alpha1.Ingress{
9298
Spec: v1alpha1.IngressSpec{
99+
Rules: []v1alpha1.IngressRule{
100+
{
101+
Hosts: []string{"example.com"},
102+
Visibility: v1alpha1.IngressVisibilityExternalIP,
103+
},
104+
},
93105
TLS: []v1alpha1.IngressTLS{{
94106
Hosts: []string{"example.com"},
95107
SecretName: "no-exist-secret",

0 commit comments

Comments
 (0)