mirror of
https://github.com/lukaszraczylo/kportal.git
synced 2026-07-05 06:05:39 +00:00
Port forward to the named service ports.
When adding a service via the wizard, resolve the service's targetPort to the actual pod container port instead of using the service port directly. Problem: Service port 80 → Pod port 8000, but kportal was trying to forward to port 80 on the pod. Solution: Look up the pod's actual containerPort when the service uses a named targetPort (like http), and use that for port-forwarding.
This commit is contained in:
@@ -468,7 +468,14 @@ func (m model) handleAddWizardEnter() (tea.Model, tea.Cmd) {
|
||||
wizard.clearTextInput()
|
||||
} else if wizard.cursor >= 0 && wizard.cursor < len(wizard.detectedPorts) {
|
||||
// Selected a detected port
|
||||
wizard.remotePort = int(wizard.detectedPorts[wizard.cursor].Port)
|
||||
// For services, use TargetPort (actual pod port) if available
|
||||
// For pods, TargetPort is 0, so use Port (container port)
|
||||
selectedPort := wizard.detectedPorts[wizard.cursor]
|
||||
if selectedPort.TargetPort > 0 {
|
||||
wizard.remotePort = int(selectedPort.TargetPort)
|
||||
} else {
|
||||
wizard.remotePort = int(selectedPort.Port)
|
||||
}
|
||||
wizard.step = StepEnterLocalPort
|
||||
wizard.clearTextInput()
|
||||
wizard.inputMode = InputModeText
|
||||
|
||||
@@ -349,9 +349,20 @@ func (m model) renderEnterRemotePort() string {
|
||||
// Render detected ports within viewport
|
||||
for i := start; i < end && i < len(wizard.detectedPorts); i++ {
|
||||
port := wizard.detectedPorts[i]
|
||||
portDesc := fmt.Sprintf("%d", port.Port)
|
||||
if port.Name != "" {
|
||||
portDesc += fmt.Sprintf(" (%s)", port.Name)
|
||||
// For services, show both service port and target port if they differ
|
||||
var portDesc string
|
||||
if port.TargetPort > 0 && port.TargetPort != port.Port {
|
||||
// Service with different target port: "80 → 8000 (http)"
|
||||
portDesc = fmt.Sprintf("%d → %d", port.Port, port.TargetPort)
|
||||
if port.Name != "" {
|
||||
portDesc += fmt.Sprintf(" (%s)", port.Name)
|
||||
}
|
||||
} else {
|
||||
// Pod port or service with same port
|
||||
portDesc = fmt.Sprintf("%d", port.Port)
|
||||
if port.Name != "" {
|
||||
portDesc += fmt.Sprintf(" (%s)", port.Name)
|
||||
}
|
||||
}
|
||||
|
||||
prefix := " "
|
||||
@@ -390,9 +401,17 @@ func (m model) renderEnterRemotePort() string {
|
||||
if len(wizard.detectedPorts) > 0 {
|
||||
b.WriteString(mutedStyle.Render("Detected ports:\n"))
|
||||
for _, port := range wizard.detectedPorts {
|
||||
portDesc := fmt.Sprintf("%d", port.Port)
|
||||
if port.Name != "" {
|
||||
portDesc += fmt.Sprintf(" (%s)", port.Name)
|
||||
var portDesc string
|
||||
if port.TargetPort > 0 && port.TargetPort != port.Port {
|
||||
portDesc = fmt.Sprintf("%d → %d", port.Port, port.TargetPort)
|
||||
if port.Name != "" {
|
||||
portDesc += fmt.Sprintf(" (%s)", port.Name)
|
||||
}
|
||||
} else {
|
||||
portDesc = fmt.Sprintf("%d", port.Port)
|
||||
if port.Name != "" {
|
||||
portDesc += fmt.Sprintf(" (%s)", port.Name)
|
||||
}
|
||||
}
|
||||
b.WriteString(mutedStyle.Render(fmt.Sprintf(" • %s\n", portDesc)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user