Skip to content

Commit

Permalink
use h2c when ports named http2 use port 80
Browse files Browse the repository at this point in the history
  • Loading branch information
KauzClay committed May 25, 2023
1 parent fad133d commit 340ab10
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/reconciler/contour/contour.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ing *v1alpha1.Ingress) r
for _, port := range svc.Spec.Ports {

if port.Name == networking.ServicePortNameH2C {
if cfg.Network != nil && cfg.Network.InternalEncryption {
if cfg.Network != nil && cfg.Network.InternalEncryption && port.Port != networking.ServiceHTTPPort {
serviceToProtocol[name] = resources.InternalEncryptionH2Protocol
logger.Debugf("marked an http2 svc %s as h2 for internal encryption", name)
} else {
Expand Down
50 changes: 40 additions & 10 deletions pkg/reconciler/contour/contour_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ func TestReconcileInternalEncryption(t *testing.T) {
Objects: append([]runtime.Object{
ing("dm-name", "ns", withDomainMappingSpec, withContour),
mustMakeProbe(t, ing("dm-name", "ns", withDomainMappingSpec, withContour), makeItReady),
}, servicesAndEndpoints...),
}, tlsServiceAndEndpoint...),
WantCreates: mustMakeProxiesWithConfig(t, ing("dm-name", "ns", withDomainMappingSpec, withContour), internalEncryptionConfig),
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: ing("dm-name", "ns", withDomainMappingSpec, withContour, func(i *v1alpha1.Ingress) {
Expand Down Expand Up @@ -800,7 +800,7 @@ var (
&corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: "ns",
Name: tlsServiceName,
Name: tlsRevisionServiceName,
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{{
Expand All @@ -811,6 +811,18 @@ var (
}},
},
},
&corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: "ns",
Name: tlsServiceName,
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{{
Name: "http2",
Port: 80,
}},
},
},
// Contour Control Plane Services
&corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -835,7 +847,7 @@ var (
&corev1.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Namespace: "ns",
Name: tlsServiceName,
Name: tlsRevisionServiceName,
},
Subsets: []corev1.EndpointSubset{{
Addresses: []corev1.EndpointAddress{{
Expand All @@ -847,14 +859,32 @@ var (
}},
}},
},
&corev1.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Namespace: "ns",
Name: tlsServiceName,
},
Subsets: []corev1.EndpointSubset{{
Addresses: []corev1.EndpointAddress{{
IP: "192.168.1.1",
}},
Ports: []corev1.EndpointPort{{
Name: "http2",
Port: 80,
Protocol: corev1.ProtocolTCP,
}},
}},
},
}
tlsServiceAndEndpoint = append(append([]runtime.Object{}, tlsService...), tlsEndpoint...)

h2cServiceName = "doo"
tlsServiceName = "tlsService"
serviceToProtocol = map[string]string{
h2cServiceName: "h2c",
tlsServiceName: resources.InternalEncryptionProtocol,
h2cServiceName = "doo"
tlsServiceName = "tlsService"
tlsRevisionServiceName = tlsServiceName + "-00001"
serviceToProtocol = map[string]string{
h2cServiceName: "h2c",
tlsServiceName: "h2c",
tlsRevisionServiceName: resources.InternalEncryptionProtocol,
}
)

Expand Down Expand Up @@ -1007,7 +1037,7 @@ func withTLSServiceSpec(i *v1alpha1.Ingress) {
Paths: []v1alpha1.HTTPIngressPath{{
Splits: []v1alpha1.IngressBackendSplit{{
IngressBackend: v1alpha1.IngressBackend{
ServiceName: tlsServiceName,
ServiceName: tlsRevisionServiceName,
ServiceNamespace: i.Namespace,
ServicePort: intstr.FromInt(443),
},
Expand All @@ -1033,7 +1063,7 @@ func withDomainMappingSpec(i *v1alpha1.Ingress) {
"K-Original-Host": "dm.example.com",
},
IngressBackend: v1alpha1.IngressBackend{
ServiceName: "doo",
ServiceName: tlsServiceName,
ServiceNamespace: i.Namespace,
ServicePort: intstr.FromInt(80),
},
Expand Down
12 changes: 1 addition & 11 deletions pkg/reconciler/contour/resources/httpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,7 @@ func MakeHTTPProxies(ctx context.Context, ing *v1alpha1.Ingress, serviceToProtoc
svc.RequestHeadersPolicy = postSplitHeaders

if proto, ok := serviceToProtocol[split.ServiceName]; ok {
//In order for domain mappings to work with internal
//encryption, need to unencrypt traffic back to the envoy.
//See
//https://github.com/knative-sandbox/net-contour/issues/862
//Can identify domain mappings by the presence of the
//RewriteHost field on the Path
if path.RewriteHost != "" {
svc.Protocol = ptr.String("h2c")
} else {
svc.Protocol = ptr.String(proto)
}
svc.Protocol = ptr.String(proto)
}

if cfg.Network != nil && cfg.Network.InternalEncryption {
Expand Down

0 comments on commit 340ab10

Please sign in to comment.