Merge branch 'develop' into feature/workin_first_and_ugly

This commit is contained in:
gadotroee
2021-04-29 08:17:40 +03:00
committed by GitHub
5 changed files with 36 additions and 15 deletions

View File

@@ -36,6 +36,8 @@ func init() {
rootCmd.Flags().StringVarP(&config.Configuration.Namespace, "namespace", "n", "", "Namespace selector")
rootCmd.Flags().BoolVarP(&config.Configuration.AllNamespaces, "all-namespaces", "A", false, "Select all namespaces")
rootCmd.Flags().StringVarP(&config.Configuration.KubeConfigPath, "kubeconfig", "k", "", "Path to kubeconfig file")
rootCmd.Flags().StringVarP(&config.Configuration.MizuImage, "mizu-image", "", "gcr.io/up9-docker-hub/mizu/develop/v1", "Custom image for mizu collector")
rootCmd.Flags().Uint16VarP(&config.Configuration.MizuPodPort, "mizu-port", "", 8899, "Port which mizu cli will attempt to forward from the mizu collector pod")
}
// Execute adds all child commands to the root command and sets flags appropriately.

View File

@@ -8,6 +8,8 @@ type Options struct {
Namespace string
AllNamespaces bool
KubeConfigPath string
MizuImage string
MizuPodPort uint16
}
var Configuration = &Options{}

View File

@@ -12,10 +12,6 @@ import (
"time"
)
var (
isPortForwarded = false
)
func Run(podRegex *regexp.Regexp) {
kubernetesProvider := kubernetes.NewProvider(config.Configuration.KubeConfigPath, config.Configuration.Namespace)
ctx, cancel := context.WithCancel(context.Background())
@@ -58,9 +54,7 @@ func watchPodsForTapping(ctx context.Context, kubernetesProvider *kubernetes.Pro
}
func createPodAndPortForward(ctx context.Context, kubernetesProvider *kubernetes.Provider, cancel context.CancelFunc, podName string) {
podImage := "kennethreitz/httpbin:latest"
pod, err := kubernetesProvider.CreatePod(ctx, podName, podImage)
pod, err := kubernetesProvider.CreatePod(ctx, podName, config.Configuration.MizuImage)
if err != nil {
fmt.Printf("error creating pod %s", err)
cancel()
@@ -82,7 +76,7 @@ func createPodAndPortForward(ctx context.Context, kubernetesProvider *kubernetes
if modifiedPod.Status.Phase == "Running" && !isPodReady {
isPodReady = true
var err error
portForward, err = kubernetes.NewPortForward(kubernetesProvider, kubernetesProvider.Namespace, podName, config.Configuration.DashboardPort, 80, cancel)
portForward, err = kubernetes.NewPortForward(kubernetesProvider, kubernetesProvider.Namespace, podName, config.Configuration.DashboardPort, config.Configuration.MizuPodPort, cancel)
if !config.Configuration.NoDashboard {
fmt.Printf("Dashboard is now available at http://localhost:%d\n", config.Configuration.DashboardPort)
}
@@ -92,7 +86,7 @@ func createPodAndPortForward(ctx context.Context, kubernetesProvider *kubernetes
}
}
case <- time.After(10 * time.Second):
case <- time.After(25 * time.Second):
if !isPodReady {
fmt.Printf("error: %s pod was not ready in time", podName)
cancel()