mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-05-10 11:16:44 +00:00
* Rename `mizu` to `kubeshark` * Rename `up9inc` to `kubeshark` * Change the logo, title, motto and the main color * Replace the favicon * Update the docs link * Change the copyright text in C files * Remove a comment * Rewrite the `README.md` and update the logo and screenshots used in it * Add a `TODO` * Fix the grammar * Fix the bottom text in the filtering guide * Change the Docker Hub username of cross-compilation intermediate images * Add an install script * Fix `docker/login-action` in the CI * Delete `build-custom-branch.yml` GitHub workflow * Update `README.md` * Remove `install.sh` * Change the motto back to "Traffic viewer for Kubernetes"
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/kubeshark/kubeshark/cli/utils"
|
|
|
|
"github.com/kubeshark/kubeshark/cli/apiserver"
|
|
"github.com/kubeshark/kubeshark/cli/config"
|
|
"github.com/kubeshark/kubeshark/cli/kubeshark/fsUtils"
|
|
"github.com/kubeshark/kubeshark/cli/uiUtils"
|
|
"github.com/kubeshark/kubeshark/logger"
|
|
"github.com/kubeshark/kubeshark/shared/kubernetes"
|
|
)
|
|
|
|
func runKubesharkView() {
|
|
kubernetesProvider, err := getKubernetesProviderForCli()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
url := config.Config.View.Url
|
|
|
|
if url == "" {
|
|
exists, err := kubernetesProvider.DoesServiceExist(ctx, config.Config.KubesharkResourcesNamespace, kubernetes.ApiServerPodName)
|
|
if err != nil {
|
|
logger.Log.Errorf("Failed to found kubeshark service %v", err)
|
|
cancel()
|
|
return
|
|
}
|
|
if !exists {
|
|
logger.Log.Infof("%s service not found, you should run `kubeshark tap` command first", kubernetes.ApiServerPodName)
|
|
cancel()
|
|
return
|
|
}
|
|
|
|
url = GetApiServerUrl(config.Config.View.GuiPort)
|
|
|
|
response, err := http.Get(fmt.Sprintf("%s/", url))
|
|
if err == nil && response.StatusCode == 200 {
|
|
logger.Log.Infof("Found a running service %s and open port %d", kubernetes.ApiServerPodName, config.Config.View.GuiPort)
|
|
return
|
|
}
|
|
logger.Log.Infof("Establishing connection to k8s cluster...")
|
|
startProxyReportErrorIfAny(kubernetesProvider, ctx, cancel, config.Config.View.GuiPort)
|
|
}
|
|
|
|
apiServerProvider := apiserver.NewProvider(url, apiserver.DefaultRetries, apiserver.DefaultTimeout)
|
|
if err := apiServerProvider.TestConnection(); err != nil {
|
|
logger.Log.Errorf(uiUtils.Error, fmt.Sprintf("Couldn't connect to API server, for more info check logs at %s", fsUtils.GetLogFilePath()))
|
|
return
|
|
}
|
|
|
|
logger.Log.Infof("Kubeshark is available at %s", url)
|
|
|
|
if !config.Config.HeadlessMode {
|
|
uiUtils.OpenBrowser(url)
|
|
}
|
|
|
|
utils.WaitForFinish(ctx, cancel)
|
|
}
|