Files
kubeshark/cli/cmd/root.go
M. Mert Yildiran 8c97c4a120 🔥 Delete the ui directory and deploy kubeshark/front in a pod named front (#1246)
* Remove the `ui` directory

* Deploy the UI in a separate pod named `front`

* Fix the port number

* Fix the port forwarding

* Call `postFrontStarted` only after `kubeshark-api-server` and `front` are ready

* Fix linter

* Fix `yaml` comments
2022-11-24 00:13:04 +03:00

65 lines
1.9 KiB
Go

package cmd
import (
"fmt"
"time"
"github.com/creasty/defaults"
"github.com/kubeshark/kubeshark/cli/config"
"github.com/kubeshark/kubeshark/cli/kubeshark"
"github.com/kubeshark/kubeshark/cli/kubeshark/fsUtils"
"github.com/kubeshark/kubeshark/cli/kubeshark/version"
"github.com/kubeshark/kubeshark/cli/uiUtils"
"github.com/kubeshark/kubeshark/logger"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "kubeshark",
Short: "A web traffic viewer for kubernetes",
Long: `A web traffic viewer for kubernetes
Further info is available at https://github.com/kubeshark/kubeshark`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := config.InitConfig(cmd); err != nil {
logger.Log.Fatal(err)
}
return nil
},
}
func init() {
defaultConfig := config.CreateDefaultConfig()
if err := defaults.Set(&defaultConfig); err != nil {
logger.Log.Debug(err)
}
rootCmd.PersistentFlags().StringSlice(config.SetCommandName, []string{}, fmt.Sprintf("Override values using --%s", config.SetCommandName))
rootCmd.PersistentFlags().String(config.ConfigFilePathCommandName, defaultConfig.ConfigFilePath, fmt.Sprintf("Override config file path using --%s", config.ConfigFilePathCommandName))
}
func printNewVersionIfNeeded(versionChan chan string) {
select {
case versionMsg := <-versionChan:
if versionMsg != "" {
logger.Log.Infof(uiUtils.Yellow, versionMsg)
}
case <-time.After(2 * time.Second):
}
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the tapCmd.
func Execute() {
if err := fsUtils.EnsureDir(kubeshark.GetKubesharkFolderPath()); err != nil {
logger.Log.Errorf("Failed to use kubeshark folder, %v", err)
}
logger.InitLogger(fsUtils.GetLogFilePath())
versionChan := make(chan string)
defer printNewVersionIfNeeded(versionChan)
go version.CheckNewerVersion(versionChan)
cobra.CheckErr(rootCmd.Execute())
}