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

Support hostNetwork and custom port protocols for dev #244

Merged
merged 3 commits into from
Jun 4, 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
9 changes: 9 additions & 0 deletions internal/configure/v1alpha1/custom_ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
15 changes: 14 additions & 1 deletion internal/resources/v1alpha1/robot_ide.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -272,13 +277,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,
})
}
Expand Down
15 changes: 14 additions & 1 deletion internal/resources/v1alpha1/robot_vdi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -357,13 +362,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,
})
}
Expand Down
Loading