From 7e52f46030cb219b70849d43cb534d53ff707d39 Mon Sep 17 00:00:00 2001 From: nimrod-up9 Date: Thu, 15 Jul 2021 13:00:20 +0300 Subject: [PATCH] Default image uses semver. --- cli/Makefile | 1 + cli/cmd/tap.go | 6 +++++- cli/mizu/version.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 cli/mizu/version.go diff --git a/cli/Makefile b/cli/Makefile index b228e9fd1..0d8acf1f5 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -3,6 +3,7 @@ COMMIT_HASH=$(shell git rev-parse HEAD) GIT_BRANCH=$(shell git branch --show-current | tr '[:upper:]' '[:lower:]') GIT_VERSION=$(shell git branch --show-current | tr '[:upper:]' '[:lower:]') BUILD_TIMESTAMP=$(shell date +%s) +SEM_VER=0.0.0 .PHONY: help .DEFAULT_GOAL := help diff --git a/cli/cmd/tap.go b/cli/cmd/tap.go index 46cb4b69e..8f2dd5c5c 100644 --- a/cli/cmd/tap.go +++ b/cli/cmd/tap.go @@ -92,6 +92,10 @@ 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)") @@ -99,7 +103,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/%s:latest", mizu.Branch), "Custom image for mizu collector") + 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().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") diff --git a/cli/mizu/version.go b/cli/mizu/version.go new file mode 100644 index 000000000..67f818501 --- /dev/null +++ b/cli/mizu/version.go @@ -0,0 +1,28 @@ +package mizu + +import ( + "regexp" +) + +type Version string + +func (v Version) 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 { + major, _, _ := v.Breakdown() + return major +} + +func (v Version) Minor() string { + _, minor, _ := v.Breakdown() + return minor +} + +func (v Version) Patch() string { + _, _, patch := v.Breakdown() + return patch +}