diff --git a/coredns/main.go b/coredns/main.go index c57505309..5c0f169ef 100644 --- a/coredns/main.go +++ b/coredns/main.go @@ -22,6 +22,8 @@ package main // https://coredns.io/2017/07/25/compile-time-enabling-or-disabling-plugins/#build-with-external-golang-source-code import ( + "flag" + "fmt" _ "github.com/coredns/caddy/onevent" "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/coremain" @@ -105,13 +107,23 @@ var directives = []string{ "on", } -var version = "not-compiled-properly" +var ( + version = "not-compiled-properly" + showVersion = false +) func init() { + flag.BoolVar(&showVersion, "subm-version", showVersion, "Show version") lighthouse.Version = version dnsserver.Directives = directives } func main() { + flag.Parse() + if showVersion { + fmt.Printf("submariner-lighthouse-coredns version: %s", version) + return + } + coremain.Run() } diff --git a/pkg/agent/main.go b/pkg/agent/main.go index 00a48d226..75d29ff1d 100644 --- a/pkg/agent/main.go +++ b/pkg/agent/main.go @@ -43,16 +43,20 @@ import ( mcsv1a1 "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1" ) +const componentName = "submariner-lighthouse-agent" + var ( - masterURL string - kubeConfig string - help = false - logger = log.Logger{Logger: logf.Log.WithName("main")} - version = "not-compiled-properly" + masterURL string + kubeConfig string + help = false + showVersion = false + logger = log.Logger{Logger: logf.Log.WithName("main")} + version = "not-compiled-properly" ) func init() { flag.BoolVar(&help, "help", help, "Print usage options") + flag.BoolVar(&showVersion, "version", showVersion, "Show version") } func exitOnError(err error, reason string) { @@ -84,6 +88,11 @@ func main() { return } + if showVersion { + fmt.Printf("%s version: %s", componentName, version) + return + } + kzerolog.InitK8sLogging() // initialize klog as well, since some internal k8s packages still log with klog directly @@ -112,7 +121,7 @@ func main() { localClient, err := dynamic.NewForConfig(cfg) exitOnError(err, "Error creating dynamic client") - logger.Infof("submariner-lighthouse-agent version: %v", version) + logger.Infof("%s version: %v", componentName, version) // set up signals so we handle the first shutdown signal gracefully ctx := signals.SetupSignalHandler()