Skip to content

Commit

Permalink
Do not remove default TLS server modified by users in gateway (#5629)
Browse files Browse the repository at this point in the history
* Do not remove default TLS server modified by users in gateway

This patch changes to stop removing default TLS servers modified by
users. In other words, if the TLS server is matches to both:

- `port.name` is `https`
- `hosts` is `'*'`

it will be removed as it conflicts with other hosts.

* Fix code style to more simple
  • Loading branch information
nak3 authored and knative-prow-robot committed Oct 29, 2019
1 parent fe00815 commit a1a35b1
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 26 deletions.
5 changes: 4 additions & 1 deletion pkg/reconciler/ingress/resources/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ func UpdateGateway(gateway *v1alpha3.Gateway, want []v1alpha3.Server, existing [
}

func isDefaultServer(server *v1alpha3.Server) bool {
return server.Port.Name == "http" || server.Port.Name == "https"
if server.Port.Name == "https" {
return len(server.Hosts) > 0 && server.Hosts[0] == "*"
}
return server.Port.Name == "http"
}

func isPlaceHolderServer(server *v1alpha3.Server) bool {
Expand Down
134 changes: 109 additions & 25 deletions pkg/reconciler/ingress/resources/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,35 @@ var selector = map[string]string{

var gateway = v1alpha3.Gateway{
Spec: v1alpha3.GatewaySpec{
Servers: []v1alpha3.Server{{
Hosts: []string{"host1.example.com"},
Port: v1alpha3.Port{
Name: "test-ns/ingress:0",
Number: 443,
Protocol: v1alpha3.ProtocolHTTPS,
},
TLS: &v1alpha3.TLSOptions{
Mode: v1alpha3.TLSModeSimple,
ServerCertificate: "tls.crt",
PrivateKey: "tls.key",
},
}, {
Hosts: []string{"host2.example.com"},
Port: v1alpha3.Port{
Name: "test-ns/non-ingress:0",
Number: 443,
Protocol: v1alpha3.ProtocolHTTPS,
},
TLS: &v1alpha3.TLSOptions{
Mode: v1alpha3.TLSModeSimple,
ServerCertificate: "tls.crt",
PrivateKey: "tls.key",
},
}},
Servers: servers,
},
}

var servers = []v1alpha3.Server{
{
Hosts: []string{"host1.example.com"},
Port: v1alpha3.Port{
Name: "test-ns/ingress:0",
Number: 443,
Protocol: v1alpha3.ProtocolHTTPS,
},
TLS: &v1alpha3.TLSOptions{
Mode: v1alpha3.TLSModeSimple,
ServerCertificate: "tls.crt",
PrivateKey: "tls.key",
},
}, {
Hosts: []string{"host2.example.com"},
Port: v1alpha3.Port{
Name: "test-ns/non-ingress:0",
Number: 443,
Protocol: v1alpha3.ProtocolHTTPS,
},
TLS: &v1alpha3.TLSOptions{
Mode: v1alpha3.TLSModeSimple,
ServerCertificate: "tls.crt",
PrivateKey: "tls.key",
},
},
}

Expand All @@ -103,6 +107,42 @@ var gatewayWithPlaceholderServer = v1alpha3.Gateway{
},
}

var gatewayWithDefaultWildcardTLSServer = v1alpha3.Gateway{
Spec: v1alpha3.GatewaySpec{
Servers: []v1alpha3.Server{{
Hosts: []string{"*"},
Port: v1alpha3.Port{
Name: "https",
Number: 443,
Protocol: v1alpha3.ProtocolHTTPS,
},
TLS: &v1alpha3.TLSOptions{
Mode: v1alpha3.TLSModePassThrough,
}},
},
},
}

var gatewayWithModifiedWildcardTLSServer = v1alpha3.Gateway{
Spec: v1alpha3.GatewaySpec{
Servers: []v1alpha3.Server{modifiedDefaultTLSServer},
},
}

var modifiedDefaultTLSServer = v1alpha3.Server{
Hosts: []string{"added.by.user.example.com"},
Port: v1alpha3.Port{
Name: "https",
Number: 443,
Protocol: v1alpha3.ProtocolHTTPS,
},
TLS: &v1alpha3.TLSOptions{
Mode: v1alpha3.TLSModeSimple,
ServerCertificate: "tls.crt",
PrivateKey: "tls.key",
},
}

var ingressSpec = v1alpha1.IngressSpec{
Rules: []v1alpha1.IngressRule{{
Hosts: []string{"host1.example.com"},
Expand Down Expand Up @@ -463,6 +503,50 @@ func TestUpdateGateway(t *testing.T) {
}},
},
},
}, {
name: "Delete wildcard servers from gateway",
existingServers: []v1alpha3.Server{},
newServers: servers,
original: gatewayWithDefaultWildcardTLSServer,
// The wildcard server should be deleted.
expected: gateway,
}, {
name: "Do not delete modified wildcard servers from gateway",
existingServers: []v1alpha3.Server{},
newServers: []v1alpha3.Server{{
Hosts: []string{"host1.example.com"},
Port: v1alpha3.Port{
Name: "clusteringress:0",
Number: 443,
Protocol: v1alpha3.ProtocolHTTPS,
},
TLS: &v1alpha3.TLSOptions{
Mode: v1alpha3.TLSModeSimple,
ServerCertificate: "tls.crt",
PrivateKey: "tls.key",
},
}},
original: gatewayWithModifiedWildcardTLSServer,
expected: v1alpha3.Gateway{
Spec: v1alpha3.GatewaySpec{
Servers: []v1alpha3.Server{
{
Hosts: []string{"host1.example.com"},
Port: v1alpha3.Port{
Name: "clusteringress:0",
Number: 443,
Protocol: v1alpha3.ProtocolHTTPS,
},
TLS: &v1alpha3.TLSOptions{
Mode: v1alpha3.TLSModeSimple,
ServerCertificate: "tls.crt",
PrivateKey: "tls.key",
},
},
modifiedDefaultTLSServer,
},
},
},
}}

for _, c := range cases {
Expand Down

0 comments on commit a1a35b1

Please sign in to comment.