Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Manually register the port mapping for k8s API
Browse files Browse the repository at this point in the history
This will send a port mapping event to Rancher-Desktop wsl-proxy for the
port 6443. This manual registration of k8s API port only applies to when
kubernetes along with wsl-integration are enabled.

Signed-off-by: Nino Kodabande <[email protected]>
  • Loading branch information
Nino-K committed May 7, 2024
1 parent afce3ee commit e28d980
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cmd/rancher-desktop-guestagent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"time"

"github.com/Masterminds/log-go"
"github.com/docker/go-connections/nat"
"github.com/rancher-sandbox/rancher-desktop-agent/pkg/containerd"
"github.com/rancher-sandbox/rancher-desktop-agent/pkg/docker"
"github.com/rancher-sandbox/rancher-desktop-agent/pkg/forwarder"
Expand All @@ -56,6 +57,8 @@ var (
k8sServiceListenerAddr = flag.String("k8sServiceListenerAddr", net.IPv4zero.String(),
"address to bind Kubernetes services to on the host, valid options are 0.0.0.0 or 127.0.0.1")
adminInstall = flag.Bool("adminInstall", false, "indicates if Rancher Desktop is installed as admin or not")
k8sAPIPort = flag.String("k8sAPIPort", "6443",
"K8sAPI port number to forward to rancher-desktop wsl-proxy as a static portMapping event")
)

// Flags can only be enabled in the following combination:
Expand Down Expand Up @@ -143,6 +146,32 @@ func main() {
} else {
forwarder := forwarder.NewWSLProxyForwarder("/run/wsl-proxy.sock")
portTracker = tracker.NewAPITracker(forwarder, tracker.GatewayBaseURL, *adminInstall)
// Manually register the port for K8s API, we would
// only want to send this manual portmapping if only
// the following conditions are met:
// 1) if kubernetes is enabled
// 2) when wsl-proxy for wsl-integration is enabled
if *enableKubernetes {
port, err := nat.NewPort("tcp", *k8sAPIPort)
if err != nil {
log.Fatalf("failed to parse port for k8s API: %v", err)
}
k8sAPIportMapping := types.PortMapping{
Remove: false,
Ports: nat.PortMap{
port: []nat.PortBinding{
{
HostIP: "127.0.0.1",
HostPort: *k8sAPIPort,
},
},
},
}
if err := forwarder.Send(k8sAPIportMapping); err != nil {
log.Fatalf("failed to send a static portMapping envent to wsl-proxy: %v", err)
}
log.Debugf("successfully forwarded k8s API port [%s] to wsl-proxy", *k8sAPIPort)
}
}

if *enableContainerd {
Expand Down

0 comments on commit e28d980

Please sign in to comment.