mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-07-04 11:58:41 +00:00
🐛 Fix the version
command
This commit is contained in:
parent
f31ad4f9f0
commit
fa0fb62e07
@ -5,7 +5,6 @@ import (
|
|||||||
|
|
||||||
"github.com/creasty/defaults"
|
"github.com/creasty/defaults"
|
||||||
"github.com/kubeshark/kubeshark/config"
|
"github.com/kubeshark/kubeshark/config"
|
||||||
"github.com/kubeshark/kubeshark/kubeshark/version"
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -32,13 +31,11 @@ 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))
|
||||||
rootCmd.PersistentFlags().String(config.ConfigFilePathCommandName, defaultConfig.ConfigFilePath, fmt.Sprintf("Override config file path using --%s", config.ConfigFilePathCommandName))
|
rootCmd.PersistentFlags().String(config.ConfigFilePathCommandName, defaultConfig.ConfigFilePath, fmt.Sprintf("Override config file path using --%s", config.ConfigFilePathCommandName))
|
||||||
rootCmd.PersistentFlags().Bool("debug", false, "Enable debug mode.")
|
rootCmd.PersistentFlags().BoolP("debug", "d", false, "Enable debug mode.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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() {
|
||||||
go version.CheckNewerVersion()
|
|
||||||
|
|
||||||
cobra.CheckErr(rootCmd.Execute())
|
cobra.CheckErr(rootCmd.Execute())
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/creasty/defaults"
|
"github.com/kubeshark/kubeshark/config"
|
||||||
"github.com/kubeshark/kubeshark/config/configStructs"
|
|
||||||
"github.com/kubeshark/kubeshark/kubeshark"
|
"github.com/kubeshark/kubeshark/kubeshark"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -16,24 +16,20 @@ var versionCmd = &cobra.Command{
|
|||||||
Short: "Print version info",
|
Short: "Print version info",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
timeStampInt, _ := strconv.ParseInt(kubeshark.BuildTimestamp, 10, 0)
|
timeStampInt, _ := strconv.ParseInt(kubeshark.BuildTimestamp, 10, 0)
|
||||||
log.Info().
|
if config.DebugMode {
|
||||||
Str("version", kubeshark.Ver).
|
log.Info().
|
||||||
Str("branch", kubeshark.Branch).
|
Str("version", kubeshark.Ver).
|
||||||
Str("commit-hash", kubeshark.GitCommitHash).
|
Str("branch", kubeshark.Branch).
|
||||||
Time("build-time", time.Unix(timeStampInt, 0)).
|
Str("commit-hash", kubeshark.GitCommitHash).
|
||||||
Send()
|
Time("build-time", time.Unix(timeStampInt, 0)).
|
||||||
|
Send()
|
||||||
|
} else {
|
||||||
|
fmt.Println(kubeshark.Ver)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(versionCmd)
|
rootCmd.AddCommand(versionCmd)
|
||||||
|
|
||||||
defaultVersionConfig := configStructs.VersionConfig{}
|
|
||||||
if err := defaults.Set(&defaultVersionConfig); err != nil {
|
|
||||||
log.Error().Err(err).Send()
|
|
||||||
}
|
|
||||||
|
|
||||||
versionCmd.Flags().BoolP(configStructs.DebugInfoVersionName, "d", defaultVersionConfig.DebugInfo, "Provide all information about version")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/creasty/defaults"
|
"github.com/creasty/defaults"
|
||||||
|
"github.com/kubeshark/kubeshark/kubeshark/version"
|
||||||
"github.com/kubeshark/kubeshark/utils"
|
"github.com/kubeshark/kubeshark/utils"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
@ -27,20 +28,28 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Config = ConfigStruct{}
|
Config = ConfigStruct{}
|
||||||
cmdName string
|
DebugMode bool
|
||||||
|
cmdName string
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitConfig(cmd *cobra.Command) error {
|
func InitConfig(cmd *cobra.Command) error {
|
||||||
debugMode, err := cmd.Flags().GetBool(DebugFlag)
|
var err error
|
||||||
|
DebugMode, err = cmd.Flags().GetBool(DebugFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg(fmt.Sprintf("Can't recieve '%s' flag", DebugFlag))
|
log.Error().Err(err).Msg(fmt.Sprintf("Can't recieve '%s' flag", DebugFlag))
|
||||||
}
|
}
|
||||||
|
|
||||||
if debugMode {
|
if DebugMode {
|
||||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cmd.Use == "version" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
go version.CheckNewerVersion()
|
||||||
|
|
||||||
Config.Hub = HubConfig{
|
Config.Hub = HubConfig{
|
||||||
PortForward{
|
PortForward{
|
||||||
8898,
|
8898,
|
||||||
|
@ -55,24 +55,23 @@ func CreateDefaultConfig() ConfigStruct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ConfigStruct struct {
|
type ConfigStruct struct {
|
||||||
Hub HubConfig `yaml:"hub"`
|
Hub HubConfig `yaml:"hub"`
|
||||||
Front FrontConfig `yaml:"front"`
|
Front FrontConfig `yaml:"front"`
|
||||||
Tap configStructs.TapConfig `yaml:"tap"`
|
Tap configStructs.TapConfig `yaml:"tap"`
|
||||||
Check configStructs.CheckConfig `yaml:"check"`
|
Check configStructs.CheckConfig `yaml:"check"`
|
||||||
Version configStructs.VersionConfig `yaml:"version"`
|
View configStructs.ViewConfig `yaml:"view"`
|
||||||
View configStructs.ViewConfig `yaml:"view"`
|
Logs configStructs.LogsConfig `yaml:"logs"`
|
||||||
Logs configStructs.LogsConfig `yaml:"logs"`
|
Config configStructs.ConfigConfig `yaml:"config,omitempty"`
|
||||||
Config configStructs.ConfigConfig `yaml:"config,omitempty"`
|
ImagePullPolicyStr string `yaml:"image-pull-policy" default:"Always"`
|
||||||
ImagePullPolicyStr string `yaml:"image-pull-policy" default:"Always"`
|
ResourcesNamespace string `yaml:"resources-namespace" default:"kubeshark"`
|
||||||
ResourcesNamespace string `yaml:"resources-namespace" default:"kubeshark"`
|
DumpLogs bool `yaml:"dump-logs" default:"false"`
|
||||||
DumpLogs bool `yaml:"dump-logs" default:"false"`
|
KubeConfigPathStr string `yaml:"kube-config-path"`
|
||||||
KubeConfigPathStr string `yaml:"kube-config-path"`
|
KubeContext string `yaml:"kube-context"`
|
||||||
KubeContext string `yaml:"kube-context"`
|
ConfigFilePath string `yaml:"config-path,omitempty" readonly:""`
|
||||||
ConfigFilePath string `yaml:"config-path,omitempty" readonly:""`
|
HeadlessMode bool `yaml:"headless" default:"false"`
|
||||||
HeadlessMode bool `yaml:"headless" default:"false"`
|
LogLevelStr string `yaml:"log-level,omitempty" default:"info" readonly:""`
|
||||||
LogLevelStr string `yaml:"log-level,omitempty" default:"info" readonly:""`
|
ServiceMap bool `yaml:"service-map" default:"true"`
|
||||||
ServiceMap bool `yaml:"service-map" default:"true"`
|
OAS models.OASConfig `yaml:"oas"`
|
||||||
OAS models.OASConfig `yaml:"oas"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *ConfigStruct) validate() error {
|
func (config *ConfigStruct) validate() error {
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package configStructs
|
|
||||||
|
|
||||||
const (
|
|
||||||
DebugInfoVersionName = "debug"
|
|
||||||
)
|
|
||||||
|
|
||||||
type VersionConfig struct {
|
|
||||||
DebugInfo bool `yaml:"debug" default:"false"`
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user