Moved version parser to shared.

This commit is contained in:
nimrod-up9
2021-07-15 13:20:42 +03:00
parent 7e52f46030
commit d93913733e
2 changed files with 7 additions and 11 deletions

View File

@@ -92,10 +92,6 @@ Supported protocols are HTTP and gRPC.`,
func init() {
rootCmd.AddCommand(tapCmd)
mizuVersion := mizu.Version(mizu.SemVer)
majorVersion := mizuVersion.Major()
minorVersion := mizuVersion.Minor()
tapCmd.Flags().Uint16VarP(&mizuTapOptions.GuiPort, "gui-port", "p", 8899, "Provide a custom port for the web interface webserver")
tapCmd.Flags().StringVarP(&mizuTapOptions.Namespace, "namespace", "n", "", "Namespace selector")
tapCmd.Flags().BoolVar(&mizuTapOptions.Analysis, "analysis", false, "Uploads traffic to UP9 for further analysis (Beta)")
@@ -103,7 +99,7 @@ func init() {
tapCmd.Flags().Uint16VarP(&mizuTapOptions.SleepIntervalSec, "upload-interval", "", 10, "Interval in seconds for uploading data to UP9")
tapCmd.Flags().BoolVarP(&mizuTapOptions.AllNamespaces, "all-namespaces", "A", false, "Tap all namespaces")
tapCmd.Flags().StringVarP(&mizuTapOptions.KubeConfigPath, "kube-config", "k", "", "Path to kube-config file")
tapCmd.Flags().StringVarP(&mizuTapOptions.MizuImage, "mizu-image", "", fmt.Sprintf("gcr.io/up9-docker-hub/mizu/main:%s.%s", majorVersion, minorVersion), "Custom image for mizu collector")
tapCmd.Flags().StringVarP(&mizuTapOptions.MizuImage, "mizu-image", "", fmt.Sprintf("gcr.io/up9-docker-hub/mizu/%s:%s", mizu.Branch, mizu.SemVer), "Custom image for mizu collector")
tapCmd.Flags().StringArrayVarP(&mizuTapOptions.PlainTextFilterRegexes, "regex-masking", "r", nil, "List of regex expressions that are used to filter matching values from text/plain http bodies")
tapCmd.Flags().StringVarP(&direction, "direction", "", "in", "Record traffic that goes in this direction (relative to the tapped pod): in/any")
tapCmd.Flags().BoolVar(&mizuTapOptions.HideHealthChecks, "hide-healthchecks", false, "hides requests with kube-probe or prometheus user-agent headers")

View File

@@ -1,28 +1,28 @@
package mizu
package semver
import (
"regexp"
)
type Version string
type SemVersion string
func (v Version) Breakdown() (string, string, string) {
func (v SemVersion) Breakdown() (string, string, string) {
re := regexp.MustCompile(`\d+`)
breakdown := re.FindAllString(string(v), 3)
return breakdown[0], breakdown[1], breakdown[2]
}
func (v Version) Major() string {
func (v SemVersion) Major() string {
major, _, _ := v.Breakdown()
return major
}
func (v Version) Minor() string {
func (v SemVersion) Minor() string {
_, minor, _ := v.Breakdown()
return minor
}
func (v Version) Patch() string {
func (v SemVersion) Patch() string {
_, _, patch := v.Breakdown()
return patch
}