Add cleanup to kic tunnel
parent
3f0fceb769
commit
073558e21e
|
@ -1,6 +1,7 @@
|
||||||
package kic
|
package kic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -14,6 +15,7 @@ import (
|
||||||
|
|
||||||
// Tunnel ...
|
// Tunnel ...
|
||||||
type Tunnel struct {
|
type Tunnel struct {
|
||||||
|
ctx context.Context
|
||||||
sshPort string
|
sshPort string
|
||||||
sshKey string
|
sshKey string
|
||||||
v1Core typed_core.CoreV1Interface
|
v1Core typed_core.CoreV1Interface
|
||||||
|
@ -21,8 +23,9 @@ type Tunnel struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTunnel ...
|
// NewTunnel ...
|
||||||
func NewTunnel(sshPort, sshKey string, v1Core typed_core.CoreV1Interface) *Tunnel {
|
func NewTunnel(ctx context.Context, sshPort, sshKey string, v1Core typed_core.CoreV1Interface) *Tunnel {
|
||||||
return &Tunnel{
|
return &Tunnel{
|
||||||
|
ctx: ctx,
|
||||||
sshPort: sshPort,
|
sshPort: sshPort,
|
||||||
sshKey: sshKey,
|
sshKey: sshKey,
|
||||||
v1Core: v1Core,
|
v1Core: v1Core,
|
||||||
|
@ -35,6 +38,16 @@ func (t *Tunnel) Start() error {
|
||||||
sshTunnels := make(map[string]*sshTunnel)
|
sshTunnels := make(map[string]*sshTunnel)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
select {
|
||||||
|
case <-t.ctx.Done():
|
||||||
|
_, err := t.LoadBalancerEmulator.Cleanup()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
services, err := t.v1Core.Services("").List(metav1.ListOptions{})
|
services, err := t.v1Core.Services("").List(metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -56,6 +69,8 @@ func (t *Tunnel) Start() error {
|
||||||
|
|
||||||
newSSHTunnel := createSSHTunnel(name, t.sshPort, t.sshKey, s)
|
newSSHTunnel := createSSHTunnel(name, t.sshPort, t.sshKey, s)
|
||||||
sshTunnels[newSSHTunnel.name] = newSSHTunnel
|
sshTunnels[newSSHTunnel.name] = newSSHTunnel
|
||||||
|
|
||||||
|
// PatchServicesIP maybe can receive the svc here, instead of listing inside again
|
||||||
_, err := t.LoadBalancerEmulator.PatchServicesIP("127.0.0.1")
|
_, err := t.LoadBalancerEmulator.PatchServicesIP("127.0.0.1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|
Loading…
Reference in New Issue