mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-10 04:48:43 +00:00
Update portForward.go, watch.go, and mizu.go
This commit is contained in:
parent
78f5a569c6
commit
3aeb8128c7
@ -2,6 +2,7 @@ package kubernetes
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"k8s.io/apimachinery/pkg/util/httpstream"
|
"k8s.io/apimachinery/pkg/util/httpstream"
|
||||||
"k8s.io/client-go/tools/portforward"
|
"k8s.io/client-go/tools/portforward"
|
||||||
@ -15,7 +16,7 @@ type PortForward struct {
|
|||||||
stopChan chan struct{}
|
stopChan chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPortForward(kubernetesProvider *Provider, namespace string, podName string, localPort uint16, podPort uint16) (*PortForward, error) {
|
func NewPortForward(kubernetesProvider *Provider, namespace string, podName string, localPort uint16, podPort uint16, cancel context.CancelFunc) (*PortForward, error) {
|
||||||
dialer := getHttpDialer(kubernetesProvider, namespace, podName)
|
dialer := getHttpDialer(kubernetesProvider, namespace, podName)
|
||||||
stopChan, readyChan := make(chan struct{}, 1), make(chan struct{}, 1)
|
stopChan, readyChan := make(chan struct{}, 1), make(chan struct{}, 1)
|
||||||
out, errOut := new(bytes.Buffer), new(bytes.Buffer)
|
out, errOut := new(bytes.Buffer), new(bytes.Buffer)
|
||||||
@ -24,10 +25,13 @@ func NewPortForward(kubernetesProvider *Provider, namespace string, podName stri
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
go forwarder.ForwardPorts()
|
go func () {
|
||||||
//if err != nil {
|
err = forwarder.ForwardPorts() // this is blocking
|
||||||
// return nil, err
|
if err != nil {
|
||||||
//}
|
fmt.Printf("kubernetes port-forwarding error: %s", err)
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
}()
|
||||||
return &PortForward{stopChan: stopChan}, nil
|
return &PortForward{stopChan: stopChan}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ func FilteredWatch(ctx context.Context, watcher watch.Interface, podFilter *rege
|
|||||||
|
|
||||||
if e.Object == nil {
|
if e.Object == nil {
|
||||||
errorChan <- errors.New("kubernetes pod watch failed")
|
errorChan <- errors.New("kubernetes pod watch failed")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pod := e.Object.(*corev1.Pod)
|
pod := e.Object.(*corev1.Pod)
|
||||||
|
@ -78,7 +78,7 @@ func createPodAndPortForward(ctx context.Context, kubernetesProvider *kubernetes
|
|||||||
if modifiedPod.Status.Phase == "Running" && !isPodReady {
|
if modifiedPod.Status.Phase == "Running" && !isPodReady {
|
||||||
isPodReady = true
|
isPodReady = true
|
||||||
var err error
|
var err error
|
||||||
portForward, err = kubernetes.NewPortForward(kubernetesProvider, kubernetesProvider.Namespace, podName, config.Configuration.DashboardPort, 80)
|
portForward, err = kubernetes.NewPortForward(kubernetesProvider, kubernetesProvider.Namespace, podName, config.Configuration.DashboardPort, 80, cancel)
|
||||||
if !config.Configuration.NoDashboard {
|
if !config.Configuration.NoDashboard {
|
||||||
fmt.Printf("Dashboard is now available at http://localhost:%d\n", config.Configuration.DashboardPort)
|
fmt.Printf("Dashboard is now available at http://localhost:%d\n", config.Configuration.DashboardPort)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user