-
Notifications
You must be signed in to change notification settings - Fork 100
Conversation
Signed-off-by: Oscar Ward <oscar@acorn.io>
pkg/controller/service/service.go
Outdated
http2Ports := ports.ByProtocol(svcInstance.Spec.Ports, true, v1.ProtocolHTTP2) | ||
httpPorts := ports.ByProtocol(svcInstance.Spec.Ports, true, v1.ProtocolHTTP) | ||
// If we have both types of ports we need to create a separate service with the annotation | ||
if len(http2Ports) > 0 && len(httpPorts) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll put some explanation on this, since we paired up to work on this yesterday and I still feel like this is a good and simple solution that can be a little confusing.
The background is that we have to put a traefik annotation on the K8s Service for http2 support (h2c). With that service we'd break the traffic for "normal" http traefik to other ports listed in that service though.
E.g. if someone uses http2 for the app server, but metrics are served via http.
That means, if we have both http/http2 mixed in a single ServiceInstance, we have to split it up to generate two K8s services.
However, all the code further down the stream is specific to a single service and even re-uses the ServiceInstance name in a lot of places.
So we need a "virtual" ServiceInstance with a different name, holding only the http2 ports to be able to leave lots of code untouched.
The DeepCopies are necessary to leave the original serviceInstance object untouched during that process and we only have to populated actively modified status fields on it.
Signed-off-by: Oscar Ward <oscar@acorn.io>
Signed-off-by: Oscar Ward <oscar@acorn.io>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, would you be able to add some intergation tests around it
@@ -19,6 +19,8 @@ func validProto(p string) (Protocol, bool) { | |||
case ProtocolUDP: | |||
fallthrough | |||
case ProtocolHTTP: | |||
fallthrough |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: all of these cases can be put on the same line:
switch ret {
case ProtocolTCP, ProtocolUDP, ProtocolHTTP, ProtocolHTTP2, "":
return ret, true
}
pkg/controller/service/service.go
Outdated
if len(http2Ports) > 0 { | ||
svcCopy := svcInstance.DeepCopy() | ||
svcCopy.Spec.Ports = http2Ports | ||
svcCopy.Name = fmt.Sprintf("%s-%s", svcInstance.Name, v1.ProtocolHTTP2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am agreeing with @StrongMonkey here. Creating an additional ServiceInstance
with a different name may cause issues with other parts of the system. For example, if something depends on the service, but the service has a different name. Or, the user may create a service that results in a ServiceInstance
being created with the same name you are creating here.
Would it be possible to render the corev1.Service
with the special annotations instead of creating an additional ServiceInstance
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ServiceInstance
is only created as a temporary copy for our purposes so that we can pass the same value into the function logic. We don't actually return the temporarily created ServiceInstance
object, we just use it to create a new corev1.Service
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spoke offline about a slightly different approach that would alleviate the concerns above.
Signed-off-by: Oscar Ward <oscar@acorn.io>
Signed-off-by: Oscar Ward <oscar@acorn.io>
acorn-io/manager#1523
Checklist
This is a title (#1216)
. Here's an example