ricardozanini commented on code in PR #283:
URL:
https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/283#discussion_r1378823557
##########
controllers/discovery/port_utils.go:
##########
@@ -0,0 +1,108 @@
+package discovery
+
+import (
+ corev1 "k8s.io/api/core/v1"
+)
+
+const (
+ httpProtocol = "http"
+ httpsProtocol = "https"
+ webProtocol = "web"
+ securePort = 443
+ appSecurePort = 8443
+)
+
+func isSecurePort(port int) bool {
+ return port == securePort || port == appSecurePort
+}
+
+// findServicePort returns the best suited ServicePort to connect to a service.
+// The optional customPort can be used to determine which port should be used
for the communication, when not set,
+// the best suited port is returned. For this last, a secure port has
precedence over a no-secure port.
+func findServicePort(servicePorts []corev1.ServicePort, customPort string)
*corev1.ServicePort {
+ // customPort is provided and is configured?
+ if len(customPort) > 0 {
+ if result := findServicePortByName(servicePorts, customPort);
result != nil {
+ return result
+ }
+ }
+ // has ssl port?
+ if result := findServicePortByName(servicePorts, httpsProtocol); result
!= nil {
+ return result
+ }
+ // has http port?
+ if result := findServicePortByName(servicePorts, httpProtocol); result
!= nil {
+ return result
+ }
+ // has web port?
+ if result := findServicePortByName(servicePorts, webProtocol); result
!= nil {
+ return result
+ }
+ // by definition a service must always have at least one port, get the
first port.
+ return &servicePorts[0]
+}
+
+func findServicePortByName(ports []corev1.ServicePort, name string)
*corev1.ServicePort {
+ for _, servicePort := range ports {
+ if name == servicePort.Name {
+ return &servicePort
+ }
+ }
+ return nil
+}
+
+func isServicePortSecure(servicePort corev1.ServicePort) bool {
+ return servicePort.Name == httpsProtocol ||
isSecurePort(int(servicePort.Port))
+}
+
+// findContainerPort returns the best suited PortPort to connect to a pod, or
nil if the pod has no ports at all.
+// The optional customPort can be used to determine which port should be used
for the communication, when not set,
+// the best suited port is returned. For this last, a secure port has
precedence over a non-secure port.
+func findContainerPort(containerPorts []corev1.ContainerPort, customPort
string) *corev1.ContainerPort {
Review Comment:
Great, instead of `custom-port`, can we call it just `port`? It's easier to
remember.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]