Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set AppProtocol on Services #14757

Merged
merged 5 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions pkg/reconciler/route/resources/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ func MakeK8sPlaceholderService(ctx context.Context, route *v1.Route, tagName str
ExternalName: domainName,
SessionAffinity: corev1.ServiceAffinityNone,
Ports: []corev1.ServicePort{{
Name: netapi.ServicePortNameH2C,
Port: int32(80),
TargetPort: intstr.FromInt(80),
Name: netapi.ServicePortNameH2C,
AppProtocol: &netapi.AppProtocolH2C,
Port: int32(80),
TargetPort: intstr.FromInt(80),
}},
},
}, nil
Expand Down Expand Up @@ -101,9 +102,10 @@ func MakeK8sService(ctx context.Context, route *v1.Route, tagName string, ingres
ObjectMeta: makeServiceObjectMeta(hostname, route),
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{{
Name: netapi.ServicePortNameH2C,
Port: int32(80),
TargetPort: intstr.FromInt(80),
Name: netapi.ServicePortNameH2C,
AppProtocol: &netapi.AppProtocolH2C,
Port: int32(80),
TargetPort: intstr.FromInt(80),
}},
},
},
Expand All @@ -128,8 +130,9 @@ func MakeK8sService(ctx context.Context, route *v1.Route, tagName string, ingres
IP: balancer.IP,
}},
Ports: []corev1.EndpointPort{{
Name: netapi.ServicePortNameH2C,
Port: int32(80),
Name: netapi.ServicePortNameH2C,
AppProtocol: &netapi.AppProtocolH2C,
Port: int32(80),
}},
}},
}
Expand Down
24 changes: 14 additions & 10 deletions pkg/reconciler/route/resources/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ var (
}

expectedPorts = []corev1.ServicePort{{
Name: netapi.ServicePortNameH2C,
Port: int32(80),
TargetPort: intstr.FromInt(80),
Name: netapi.ServicePortNameH2C,
AppProtocol: &netapi.AppProtocolH2C,
Port: int32(80),
TargetPort: intstr.FromInt(80),
}}
)

Expand Down Expand Up @@ -123,8 +124,9 @@ func TestMakeK8SService(t *testing.T) {
IP: "some-ip",
}},
Ports: []corev1.EndpointPort{{
Name: netapi.ServicePortNameH2C,
Port: int32(80),
Name: netapi.ServicePortNameH2C,
AppProtocol: &netapi.AppProtocolH2C,
Port: int32(80),
}},
}},
}, {
Expand Down Expand Up @@ -200,8 +202,9 @@ func TestMakeK8SService(t *testing.T) {
IP: "some-ip",
}},
Ports: []corev1.EndpointPort{{
Name: netapi.ServicePortNameH2C,
Port: int32(80),
Name: netapi.ServicePortNameH2C,
AppProtocol: &netapi.AppProtocolH2C,
Port: int32(80),
}},
}},
}, {
Expand Down Expand Up @@ -392,9 +395,10 @@ func TestMakePlaceholderService(t *testing.T) {
ExternalName: tt.expectedExternalName,
SessionAffinity: corev1.ServiceAffinityNone,
Ports: []corev1.ServicePort{{
Name: netapi.ServicePortNameH2C,
Port: int32(80),
TargetPort: intstr.FromInt(80),
Name: netapi.ServicePortNameH2C,
AppProtocol: &netapi.AppProtocolH2C,
Port: int32(80),
TargetPort: intstr.FromInt(80),
}},
}

Expand Down
16 changes: 9 additions & 7 deletions pkg/reconciler/serverlessservice/resources/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ func MakePublicService(sks *v1alpha1.ServerlessService) *corev1.Service {

func makePublicServicePorts(sks *v1alpha1.ServerlessService) []corev1.ServicePort {
ports := []corev1.ServicePort{{
Name: pkgnet.ServicePortName(sks.Spec.ProtocolType),
Protocol: corev1.ProtocolTCP,
Port: int32(pkgnet.ServicePort(sks.Spec.ProtocolType)),
TargetPort: targetPort(sks),
Name: pkgnet.ServicePortName(sks.Spec.ProtocolType),
Protocol: corev1.ProtocolTCP,
AppProtocol: pkgnet.AppProtocol(sks.Spec.ProtocolType),
Port: int32(pkgnet.ServicePort(sks.Spec.ProtocolType)),
TargetPort: targetPort(sks),
}, {
// The HTTPS port is used when activator-ca is enabled.
// Although it is not used by default, we put it here as it should be harmless
Expand Down Expand Up @@ -144,9 +145,10 @@ func MakePrivateService(sks *v1alpha1.ServerlessService, selector map[string]str
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{{
Name: pkgnet.ServicePortName(sks.Spec.ProtocolType),
Protocol: corev1.ProtocolTCP,
Port: pkgnet.ServiceHTTPPort,
Name: pkgnet.ServicePortName(sks.Spec.ProtocolType),
Protocol: corev1.ProtocolTCP,
AppProtocol: pkgnet.AppProtocol(sks.Spec.ProtocolType),
Port: pkgnet.ServiceHTTPPort,
// This one is matching the public one, since this is the
// port queue-proxy listens on.
TargetPort: targetPort(sks),
Expand Down
36 changes: 20 additions & 16 deletions pkg/reconciler/serverlessservice/resources/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ func TestMakePublicService(t *testing.T) {
}),
want: svc(networking.ServiceTypePublic, func(s *corev1.Service) {
s.Spec.Ports = []corev1.ServicePort{{
Name: pkgnet.ServicePortNameH2C,
Protocol: corev1.ProtocolTCP,
Port: pkgnet.ServiceHTTP2Port,
TargetPort: intstr.FromInt(networking.BackendHTTP2Port),
Name: pkgnet.ServicePortNameH2C,
Protocol: corev1.ProtocolTCP,
AppProtocol: &pkgnet.AppProtocolH2C,
Port: pkgnet.ServiceHTTP2Port,
TargetPort: intstr.FromInt(networking.BackendHTTP2Port),
}, {
Name: pkgnet.ServicePortNameHTTPS,
Protocol: corev1.ProtocolTCP,
Expand All @@ -202,10 +203,11 @@ func TestMakePublicService(t *testing.T) {
}),
want: svc(networking.ServiceTypePublic, func(s *corev1.Service) {
s.Spec.Ports = []corev1.ServicePort{{
Name: pkgnet.ServicePortNameH2C,
Protocol: corev1.ProtocolTCP,
Port: pkgnet.ServiceHTTP2Port,
TargetPort: intstr.FromInt(networking.BackendHTTP2Port),
Name: pkgnet.ServicePortNameH2C,
Protocol: corev1.ProtocolTCP,
AppProtocol: &pkgnet.AppProtocolH2C,
Port: pkgnet.ServiceHTTP2Port,
TargetPort: intstr.FromInt(networking.BackendHTTP2Port),
}, {
Name: pkgnet.ServicePortNameHTTPS,
Protocol: corev1.ProtocolTCP,
Expand All @@ -222,10 +224,11 @@ func TestMakePublicService(t *testing.T) {
}),
want: svc(networking.ServiceTypePublic, func(s *corev1.Service) {
s.Spec.Ports = []corev1.ServicePort{{
Name: pkgnet.ServicePortNameH2C,
Protocol: corev1.ProtocolTCP,
Port: pkgnet.ServiceHTTP2Port,
TargetPort: intstr.FromInt(networking.BackendHTTP2Port),
Name: pkgnet.ServicePortNameH2C,
Protocol: corev1.ProtocolTCP,
AppProtocol: &pkgnet.AppProtocolH2C,
Port: pkgnet.ServiceHTTP2Port,
TargetPort: intstr.FromInt(networking.BackendHTTP2Port),
}, {
Name: pkgnet.ServicePortNameHTTPS,
Protocol: corev1.ProtocolTCP,
Expand Down Expand Up @@ -470,10 +473,11 @@ func TestMakePrivateService(t *testing.T) {
}, privateSvcMod, func(s *corev1.Service) {
// And now patch port to be http2.
s.Spec.Ports[0] = corev1.ServicePort{
Name: pkgnet.ServicePortNameH2C,
Protocol: corev1.ProtocolTCP,
Port: pkgnet.ServiceHTTPPort,
TargetPort: intstr.FromInt(networking.BackendHTTP2Port),
Name: pkgnet.ServicePortNameH2C,
Protocol: corev1.ProtocolTCP,
AppProtocol: &pkgnet.AppProtocolH2C,
Port: pkgnet.ServiceHTTPPort,
TargetPort: intstr.FromInt(networking.BackendHTTP2Port),
}
s.Spec.Ports[5] = corev1.ServicePort{
Name: pkgnet.ServicePortNameH2C + "-istio",
Expand Down
2 changes: 2 additions & 0 deletions pkg/reconciler/serverlessservice/serverlessservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ func deploy(namespace, name string, opts ...deploymentOption) *appsv1.Deployment
func withHTTP2Priv(svc *corev1.Service) {
svc.Spec.Ports[0].Name = "http2"
svc.Spec.Ports[0].TargetPort = intstr.FromInt(networking.BackendHTTP2Port)
svc.Spec.Ports[0].AppProtocol = &pkgnet.AppProtocolH2C

svc.Spec.Ports[5].Name = "http2-istio"
svc.Spec.Ports[5].Port = networking.BackendHTTP2Port
Expand All @@ -812,6 +813,7 @@ func withHTTP2Priv(svc *corev1.Service) {
func withHTTP2(svc *corev1.Service) {
svc.Spec.Ports[0].Port = pkgnet.ServiceHTTP2Port
svc.Spec.Ports[0].Name = "http2"
svc.Spec.Ports[0].AppProtocol = &pkgnet.AppProtocolH2C
svc.Spec.Ports[0].TargetPort = intstr.FromInt(networking.BackendHTTP2Port)
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/testing/functional.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,10 @@ func WithExternalName(name string) K8sServiceOption {
return func(svc *corev1.Service) {
svc.Spec.ExternalName = name
svc.Spec.Ports = []corev1.ServicePort{{
Name: networking.ServicePortNameH2C,
Port: int32(80),
TargetPort: intstr.FromInt(80),
Name: networking.ServicePortNameH2C,
AppProtocol: &networking.AppProtocolH2C,
Port: int32(80),
TargetPort: intstr.FromInt(80),
}}
}
}
Expand Down
Loading