wmedvede commented on code in PR #283:
URL:
https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/283#discussion_r1378579127
##########
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:
yes, this why this method has **customPort string** as input parameter.
In the ResourceUri we have
https://github.com/apache/incubator-kie-kogito-serverless-operator/blob/df49ec869c47b2da6773cdfbf2feb1bf89057d9a/controllers/discovery/discovery.go#L16
Ths CustomPortLabel that can be set as part of ResourceUri to query. When
set, it is properly propagated and passed to this method, and has priority, so
we try to get the port with that label.
The other criteria to consider ssl port, or http, or web, or the first
available if no custom, ssl, http or web are present is borrowed from the kogio
runtimes kubernetes catalog implementation to keep semantic compatibility.
--
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]