mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-25 11:59:35 +00:00
Adding version check to all commands execution (#236)
This commit is contained in:
parent
7a31263e4a
commit
a34c2fc0dc
@ -7,6 +7,8 @@ import (
|
|||||||
"github.com/up9inc/mizu/cli/logger"
|
"github.com/up9inc/mizu/cli/logger"
|
||||||
"github.com/up9inc/mizu/cli/mizu"
|
"github.com/up9inc/mizu/cli/mizu"
|
||||||
"github.com/up9inc/mizu/cli/mizu/fsUtils"
|
"github.com/up9inc/mizu/cli/mizu/fsUtils"
|
||||||
|
"github.com/up9inc/mizu/cli/mizu/version"
|
||||||
|
"github.com/up9inc/mizu/cli/uiUtils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
@ -15,14 +17,9 @@ var rootCmd = &cobra.Command{
|
|||||||
Long: `A web traffic viewer for kubernetes
|
Long: `A web traffic viewer for kubernetes
|
||||||
Further info is available at https://github.com/up9inc/mizu`,
|
Further info is available at https://github.com/up9inc/mizu`,
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if err := fsUtils.EnsureDir(mizu.GetMizuFolderPath()); err != nil {
|
|
||||||
logger.Log.Errorf("Failed to use mizu folder, %v", err)
|
|
||||||
}
|
|
||||||
logger.InitLogger()
|
|
||||||
if err := config.InitConfig(cmd); err != nil {
|
if err := config.InitConfig(cmd); err != nil {
|
||||||
logger.Log.Fatal(err)
|
logger.Log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -31,8 +28,24 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().StringSlice(config.SetCommandName, []string{}, fmt.Sprintf("Override values using --%s", config.SetCommandName))
|
rootCmd.PersistentFlags().StringSlice(config.SetCommandName, []string{}, fmt.Sprintf("Override values using --%s", config.SetCommandName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printNewVersionIfNeeded(versionChan chan string) {
|
||||||
|
versionMsg := <-versionChan
|
||||||
|
if versionMsg != "" {
|
||||||
|
logger.Log.Infof(uiUtils.Yellow, versionMsg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
// 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.
|
// This is called by main.main(). It only needs to happen once to the tapCmd.
|
||||||
func Execute() {
|
func Execute() {
|
||||||
|
if err := fsUtils.EnsureDir(mizu.GetMizuFolderPath()); err != nil {
|
||||||
|
logger.Log.Errorf("Failed to use mizu folder, %v", err)
|
||||||
|
}
|
||||||
|
logger.InitLogger()
|
||||||
|
|
||||||
|
versionChan := make(chan string)
|
||||||
|
defer printNewVersionIfNeeded(versionChan)
|
||||||
|
go version.CheckNewerVersion(versionChan)
|
||||||
|
|
||||||
cobra.CheckErr(rootCmd.Execute())
|
cobra.CheckErr(rootCmd.Execute())
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/up9inc/mizu/cli/logger"
|
"github.com/up9inc/mizu/cli/logger"
|
||||||
"github.com/up9inc/mizu/cli/mizu/fsUtils"
|
"github.com/up9inc/mizu/cli/mizu/fsUtils"
|
||||||
"github.com/up9inc/mizu/cli/mizu/goUtils"
|
"github.com/up9inc/mizu/cli/mizu/goUtils"
|
||||||
"github.com/up9inc/mizu/cli/mizu/version"
|
|
||||||
"github.com/up9inc/mizu/cli/telemetry"
|
"github.com/up9inc/mizu/cli/telemetry"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -79,7 +78,7 @@ func RunMizuTap() {
|
|||||||
} else {
|
} else {
|
||||||
namespacesStr = "all namespaces"
|
namespacesStr = "all namespaces"
|
||||||
}
|
}
|
||||||
version.CheckNewerVersion()
|
|
||||||
logger.Log.Infof("Tapping pods in %s", namespacesStr)
|
logger.Log.Infof("Tapping pods in %s", namespacesStr)
|
||||||
|
|
||||||
if err, _ := updateCurrentlyTappedPods(kubernetesProvider, ctx, targetNamespaces); err != nil {
|
if err, _ := updateCurrentlyTappedPods(kubernetesProvider, ctx, targetNamespaces); err != nil {
|
||||||
|
@ -52,7 +52,7 @@ func CheckVersionCompatibility(port uint16) (bool, error) {
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckNewerVersion() {
|
func CheckNewerVersion(versionChan chan string) {
|
||||||
logger.Log.Debugf("Checking for newer version...")
|
logger.Log.Debugf("Checking for newer version...")
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
client := github.NewClient(nil)
|
client := github.NewClient(nil)
|
||||||
@ -88,11 +88,13 @@ func CheckNewerVersion() {
|
|||||||
}
|
}
|
||||||
gitHubVersion := string(data)
|
gitHubVersion := string(data)
|
||||||
gitHubVersion = gitHubVersion[:len(gitHubVersion)-1]
|
gitHubVersion = gitHubVersion[:len(gitHubVersion)-1]
|
||||||
logger.Log.Debugf("Finished version validation, took %v", time.Since(start))
|
|
||||||
|
|
||||||
gitHubVersionSemVer := semver.SemVersion(gitHubVersion)
|
gitHubVersionSemVer := semver.SemVersion(gitHubVersion)
|
||||||
currentSemVer := semver.SemVersion(mizu.SemVer)
|
currentSemVer := semver.SemVersion(mizu.SemVer)
|
||||||
|
logger.Log.Debugf("Finished version validation, github version %v, current version %v, took %v", gitHubVersion, currentSemVer, time.Since(start))
|
||||||
|
|
||||||
if gitHubVersionSemVer.GreaterThan(currentSemVer) {
|
if gitHubVersionSemVer.GreaterThan(currentSemVer) {
|
||||||
logger.Log.Infof(uiUtils.Yellow, fmt.Sprintf("Update available! %v -> %v (%v)", mizu.SemVer, gitHubVersion, *latestRelease.HTMLURL))
|
versionChan <- fmt.Sprintf("Update available! %v -> %v (%v)", mizu.SemVer, gitHubVersion, *latestRelease.HTMLURL)
|
||||||
}
|
}
|
||||||
|
versionChan <- ""
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user