Skip to content

Commit

Permalink
Add version flag to LH binaries
Browse files Browse the repository at this point in the history
Adds `--version` flag to Lighthouse Agent and `--subm-version`
flag to Lighthouse Coredns. CoreDNS already has `--version` which
prints CoreDNS version, so we can't use the same flag for
Lighthouse version.

Refer submariner-io/enhancements#204

Signed-off-by: Vishal Thapar <[email protected]>
  • Loading branch information
vthapar committed Aug 2, 2023
1 parent 31eaa99 commit d75ec96
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
14 changes: 13 additions & 1 deletion coredns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
}
21 changes: 15 additions & 6 deletions pkg/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d75ec96

Please sign in to comment.