From a912d81edca2fc1a24923e5ebf9e3109f1406a6f Mon Sep 17 00:00:00 2001 From: tunahanertekin Date: Tue, 4 Jun 2024 11:33:37 +0300 Subject: [PATCH 1/3] refactor(protocol): select protocol by port name prefix --- internal/configure/v1alpha1/custom_ports.go | 9 +++++++++ internal/resources/v1alpha1/robot_ide.go | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/configure/v1alpha1/custom_ports.go b/internal/configure/v1alpha1/custom_ports.go index fb7d4079..69805bb9 100644 --- a/internal/configure/v1alpha1/custom_ports.go +++ b/internal/configure/v1alpha1/custom_ports.go @@ -18,9 +18,18 @@ func (cfg *ContainerConfigInjector) InjectCustomPortConfiguration(container *cor fwdStr := strings.Split(portInfo[1], ":") // nodePortVal, _ := strconv.ParseInt(fwdStr[0], 10, 64) containerPortVal, _ := strconv.ParseInt(fwdStr[1], 10, 64) + + var protocol corev1.Protocol + if strings.HasPrefix(portName, "t") { + protocol = corev1.ProtocolTCP + } else if strings.HasPrefix(portName, "u") { + protocol = corev1.ProtocolUDP + } + container.Ports = append(container.Ports, corev1.ContainerPort{ Name: portName, ContainerPort: int32(containerPortVal), + Protocol: protocol, }) } diff --git a/internal/resources/v1alpha1/robot_ide.go b/internal/resources/v1alpha1/robot_ide.go index e28c1eb9..1d25d555 100644 --- a/internal/resources/v1alpha1/robot_ide.go +++ b/internal/resources/v1alpha1/robot_ide.go @@ -272,13 +272,21 @@ func GetRobotIDECustomService(robotIDE *robotv1alpha1.RobotIDE, svcNamespacedNam fwdStr := strings.Split(portInfo[1], ":") nodePortVal, _ := strconv.ParseInt(fwdStr[0], 10, 64) containerPortVal, _ := strconv.ParseInt(fwdStr[1], 10, 64) + + var protocol corev1.Protocol + if strings.HasPrefix(portName, "t") { + protocol = corev1.ProtocolTCP + } else if strings.HasPrefix(portName, "u") { + protocol = corev1.ProtocolUDP + } + ports = append(ports, corev1.ServicePort{ Port: int32(containerPortVal), TargetPort: intstr.IntOrString{ IntVal: int32(containerPortVal), }, NodePort: int32(nodePortVal), - Protocol: corev1.ProtocolTCP, + Protocol: protocol, Name: portName, }) } From be70cc2e9aa2c0d530102e6fe8f3613ce12dbfb6 Mon Sep 17 00:00:00 2001 From: tunahanertekin Date: Tue, 4 Jun 2024 11:38:40 +0300 Subject: [PATCH 2/3] refactor(protocol): select protocol by port name prefix for vdi --- internal/resources/v1alpha1/robot_vdi.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/resources/v1alpha1/robot_vdi.go b/internal/resources/v1alpha1/robot_vdi.go index 2d4c36c2..4b4fecae 100644 --- a/internal/resources/v1alpha1/robot_vdi.go +++ b/internal/resources/v1alpha1/robot_vdi.go @@ -357,13 +357,21 @@ func GetRobotVDICustomService(robotVDI *robotv1alpha1.RobotVDI, svcNamespacedNam fwdStr := strings.Split(portInfo[1], ":") nodePortVal, _ := strconv.ParseInt(fwdStr[0], 10, 64) containerPortVal, _ := strconv.ParseInt(fwdStr[1], 10, 64) + + var protocol corev1.Protocol + if strings.HasPrefix(portName, "t") { + protocol = corev1.ProtocolTCP + } else if strings.HasPrefix(portName, "u") { + protocol = corev1.ProtocolUDP + } + ports = append(ports, corev1.ServicePort{ Port: int32(containerPortVal), TargetPort: intstr.IntOrString{ IntVal: int32(containerPortVal), }, NodePort: int32(nodePortVal), - Protocol: corev1.ProtocolTCP, + Protocol: protocol, Name: portName, }) } From c9a6954674858a46a81e552c79c3e22a7c05b616 Mon Sep 17 00:00:00 2001 From: tunahanertekin Date: Tue, 4 Jun 2024 11:44:50 +0300 Subject: [PATCH 3/3] refactor(host-network): put option for host network to ide and vdi --- internal/resources/v1alpha1/robot_ide.go | 5 +++++ internal/resources/v1alpha1/robot_vdi.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/internal/resources/v1alpha1/robot_ide.go b/internal/resources/v1alpha1/robot_ide.go index 1d25d555..93018a07 100644 --- a/internal/resources/v1alpha1/robot_ide.go +++ b/internal/resources/v1alpha1/robot_ide.go @@ -97,6 +97,11 @@ func GetRobotIDEPod(robotIDE *robotv1alpha1.RobotIDE, podNamespacedName *types.N }, } + // host network patch + if _, hostNetworkEnabled := robotIDE.Labels["host-network"]; hostNetworkEnabled { + idePod.Spec.HostNetwork = true + } + podCfg.InjectImagePullPolicy(&idePod) podCfg.SchedulePod(&idePod, robotIDE) podCfg.InjectVolumeConfiguration(&idePod, robot) diff --git a/internal/resources/v1alpha1/robot_vdi.go b/internal/resources/v1alpha1/robot_vdi.go index 4b4fecae..2394b663 100644 --- a/internal/resources/v1alpha1/robot_vdi.go +++ b/internal/resources/v1alpha1/robot_vdi.go @@ -162,6 +162,11 @@ func GetRobotVDIPod(robotVDI *robotv1alpha1.RobotVDI, podNamespacedName *types.N }, } + // host network patch + if _, hostNetworkEnabled := robotVDI.Labels["host-network"]; hostNetworkEnabled { + vdiPod.Spec.HostNetwork = true + } + podCfg.InjectImagePullPolicy(vdiPod) podCfg.SchedulePod(vdiPod, robotVDI) podCfg.InjectGenericEnvironmentVariables(vdiPod, robot)