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