Skip to content

Commit

Permalink
WIP: kic darwin tunnel
Browse files Browse the repository at this point in the history
  • Loading branch information
josedonizetti committed Feb 1, 2020
1 parent 8679063 commit 8c35493
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/minikube/cmd/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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())
Expand Down
68 changes: 68 additions & 0 deletions pkg/minikube/tunnel/kic_darwing.go
Original file line number Diff line number Diff line change
@@ -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",
"[email protected]",
"-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)
}

0 comments on commit 8c35493

Please sign in to comment.