mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-04-07 03:07:25 +00:00
51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/up9inc/mizu/cli/kubernetes"
|
|
"github.com/up9inc/mizu/cli/mizu"
|
|
"k8s.io/client-go/tools/clientcmd"
|
|
"net/http"
|
|
)
|
|
|
|
func runMizuView(mizuViewOptions *MizuViewOptions) {
|
|
kubernetesProvider, err := kubernetes.NewProvider(mizuViewOptions.KubeConfigPath)
|
|
if err != nil {
|
|
if clientcmd.IsEmptyConfig(err) {
|
|
fmt.Printf(mizu.Red, "Couldn't find the kube config file, or file is empty. Try adding '--kube-config=<path to kube config file>'\n")
|
|
return
|
|
}
|
|
if clientcmd.IsConfigurationInvalid(err) {
|
|
fmt.Printf(mizu.Red, "Invalid kube config file. Try using a different config with '--kube-config=<path to kube config file>'\n")
|
|
return
|
|
}
|
|
}
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
exists, err := kubernetesProvider.DoesServicesExist(ctx, mizu.ResourcesNamespace, mizu.AggregatorPodName)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if !exists {
|
|
fmt.Printf("The %s service not found\n", mizu.AggregatorPodName)
|
|
return
|
|
}
|
|
|
|
mizuProxiedUrl := kubernetes.GetMizuCollectorProxiedHostAndPath(mizuViewOptions.GuiPort)
|
|
_, err = http.Get(fmt.Sprintf("http://%s/", mizuProxiedUrl))
|
|
if err == nil {
|
|
fmt.Printf("Found a running service %s and open port %d\n", mizu.AggregatorPodName, mizuViewOptions.GuiPort)
|
|
return
|
|
}
|
|
fmt.Printf("Found service %s, creating k8s proxy\n", mizu.AggregatorPodName)
|
|
|
|
fmt.Printf("Mizu is available at http://%s\n", kubernetes.GetMizuCollectorProxiedHostAndPath(mizuViewOptions.GuiPort))
|
|
err = kubernetes.StartProxy(kubernetesProvider, mizuViewOptions.GuiPort, mizu.ResourcesNamespace, mizu.AggregatorPodName)
|
|
if err != nil {
|
|
fmt.Printf("Error occured while running k8s proxy %v\n", err)
|
|
}
|
|
}
|