mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-04-06 10:47:49 +00:00
* WIP
* WIP
* WIP
* WIP
* WIP
* Update tapRunner.go and k8sTapManager.go
* Update cleanRunner.go, common.go, and 8 more files...
* Update common.go, tapConfig.go, and 2 more files...
* Update config.go, config.go, and 5 more files...
* Update tapRunner.go, config.go, and 7 more files...
* Update cleanRunner.go, logs.go, and 2 more files...
* Update k8sTapManager.go, provider.go, and watch.go
* Update go.sum, go.mod, and go.sum
* Update go.mod and go.sum
* Update go.mod, go.sum, and 2 more files...
* Revert "Update go.mod, go.sum, and 2 more files..."
This reverts commit 8140311349.
* Update funcWrappers.go, tapRunner.go, and 4 more files...
* Update main.go, tapRunner.go, and mizuTapperSyncer.go
67 lines
2.2 KiB
Go
67 lines
2.2 KiB
Go
package cmd
|
||
|
||
import (
|
||
"context"
|
||
"errors"
|
||
"fmt"
|
||
"os"
|
||
"os/signal"
|
||
"syscall"
|
||
|
||
"github.com/up9inc/mizu/cli/config"
|
||
"github.com/up9inc/mizu/cli/config/configStructs"
|
||
"github.com/up9inc/mizu/cli/errormessage"
|
||
"github.com/up9inc/mizu/cli/uiUtils"
|
||
"github.com/up9inc/mizu/shared/kubernetes"
|
||
"github.com/up9inc/mizu/shared/logger"
|
||
)
|
||
|
||
func GetApiServerUrl() string {
|
||
return fmt.Sprintf("http://%s", kubernetes.GetMizuApiServerProxiedHostAndPath(config.Config.Tap.GuiPort))
|
||
}
|
||
|
||
func startProxyReportErrorIfAny(kubernetesProvider *kubernetes.Provider, cancel context.CancelFunc) {
|
||
err := kubernetes.StartProxy(kubernetesProvider, config.Config.Tap.ProxyHost, config.Config.Tap.GuiPort, config.Config.MizuResourcesNamespace, kubernetes.ApiServerPodName)
|
||
if err != nil {
|
||
logger.Log.Errorf(uiUtils.Error, fmt.Sprintf("Error occured while running k8s proxy %v\n"+
|
||
"Try setting different port by using --%s", errormessage.FormatError(err), configStructs.GuiPortTapName))
|
||
cancel()
|
||
}
|
||
|
||
logger.Log.Debugf("proxy ended")
|
||
}
|
||
|
||
func waitForFinish(ctx context.Context, cancel context.CancelFunc) {
|
||
logger.Log.Debugf("waiting for finish...")
|
||
sigChan := make(chan os.Signal, 1)
|
||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
||
|
||
// block until ctx cancel is called or termination signal is received
|
||
select {
|
||
case <-ctx.Done():
|
||
logger.Log.Debugf("ctx done")
|
||
break
|
||
case <-sigChan:
|
||
logger.Log.Debugf("Got termination signal, canceling execution...")
|
||
cancel()
|
||
}
|
||
}
|
||
|
||
func getKubernetesProviderForCli() (*kubernetes.Provider, error) {
|
||
kubernetesProvider, err := kubernetes.NewProvider(config.Config.KubeConfigPath())
|
||
if err != nil {
|
||
handleKubernetesProviderError(err)
|
||
return nil, err
|
||
}
|
||
return kubernetesProvider, nil
|
||
}
|
||
|
||
func handleKubernetesProviderError(err error) {
|
||
var clusterBehindProxyErr *kubernetes.ClusterBehindProxyError
|
||
if ok := errors.As(err, &clusterBehindProxyErr); ok {
|
||
logger.Log.Errorf("cannot establish http-proxy connection to the Kubernetes cluster. If you’re using Lens or similar tool, please run mizu with regular kubectl config using --%v %v=$HOME/.kube/config flag", config.SetCommandName, config.KubeConfigPathConfigName)
|
||
} else {
|
||
logger.Log.Error(err)
|
||
}
|
||
}
|