diff --git a/cmd/minikube/cmd/tunnel.go b/cmd/minikube/cmd/tunnel.go index 8fdcae40a6e1..a41f1e6359d8 100644 --- a/cmd/minikube/cmd/tunnel.go +++ b/cmd/minikube/cmd/tunnel.go @@ -45,6 +45,7 @@ var tunnelCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { manager := tunnel.NewManager() + if cleanup { glog.Info("Checking for tunnels to cleanup...") if err := manager.CleanupNotRunningTunnels(); err != nil { @@ -60,6 +61,7 @@ var tunnelCmd = &cobra.Command{ } glog.Infof("Creating k8s client...") + // Tunnel uses the k8s clientset to query the API server for services in the LoadBalancerEmulator. // We define the tunnel and minikube error free if the API server responds within a second. // This also contributes to better UX, the tunnel status check can happen every second and @@ -69,6 +71,11 @@ var tunnelCmd = &cobra.Command{ exit.WithError("error creating clientset", err) } + if true { + kicTunnel := tunnel.NewKicTunnel(clientset.CoreV1()) + kicTunnel.Start() + } + ctrlC := make(chan os.Signal, 1) signal.Notify(ctrlC, os.Interrupt) ctx, cancel := context.WithCancel(context.Background()) diff --git a/pkg/minikube/tunnel/kic_darwing.go b/pkg/minikube/tunnel/kic_darwing.go new file mode 100644 index 000000000000..bf5547ab38c3 --- /dev/null +++ b/pkg/minikube/tunnel/kic_darwing.go @@ -0,0 +1,68 @@ +package tunnel + +import ( + "time" + "os" + "os/exec" + "fmt" + + typed_core "k8s.io/client-go/kubernetes/typed/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/api/core/v1" +) + +// ssh tunnel for kic when running on darwing + +type KicTunnel struct { + sshPort string + sshKey string + v1Core typed_core.CoreV1Interface +} + +// essa porta precisa vir de uma pergunta para o cluster +func NewKicTunnel(v1Core typed_core.CoreV1Interface) *KicTunnel { + return &KicTunnel{ + v1Core: v1Core, + } +} + +func (kt *KicTunnel) Start() { + for { + services, err := kt.v1Core.Services("").List(metav1.ListOptions{}) + if err != nil { + os.Exit(1) + } + + for _, s := range services.Items { + if s.Spec.Type == v1.ServiceTypeLoadBalancer { + createTunnel(s.Name, s.Spec.ClusterIP, s.Spec.Ports) + } + } + + time.Sleep(10 * time.Second) + } +} + +func createTunnel(name, clusterIP string, ports []v1.ServicePort) { + sshArgs := []string{ + "-N", + "docker@127.0.0.1", + "-p", "32782", + "-i", "~/.minikube/machines/minikube/id_rsa", + } + + for _, port := range ports { + arg := fmt.Sprintf( + "-L %d:%s:%d", + port.Port, + clusterIP, + port.Port, + ) + + sshArgs = append(sshArgs, arg) + } + + cmd := exec.Command("ssh", sshArgs + err := cmd.Run() + fmt.Println(err) +}