-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8679063
commit 8c35493
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |