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.

Removed a log entry from metrics.go which didn't add much value
so we can have version as first entry in log file.

Refer submariner-io/enhancements#204

Fixes submariner-io#1333

Signed-off-by: Vishal Thapar <[email protected]>
  • Loading branch information
vthapar committed Aug 4, 2023
1 parent 7741325 commit d3c4f85
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
20 changes: 17 additions & 3 deletions coredns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ package main
// https://coredns.io/2017/07/25/compile-time-enabling-or-disabling-plugins/#build-with-external-golang-source-code

import (
"flag"
"fmt"
"os"

_ "github.com/coredns/caddy/onevent"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/coremain"
Expand Down Expand Up @@ -61,7 +65,7 @@ import (
_ "github.com/coredns/coredns/plugin/tls"
_ "github.com/coredns/coredns/plugin/trace"
_ "github.com/coredns/coredns/plugin/whoami"
lighthouse "github.com/submariner-io/lighthouse/coredns/plugin"
_ "github.com/submariner-io/lighthouse/coredns/plugin"
)

var directives = []string{
Expand Down Expand Up @@ -105,13 +109,23 @@ var directives = []string{
"on",
}

var version = "not-compiled-properly"
var (
version = "not-compiled-properly"
showVersion = false
)

func init() {
lighthouse.Version = version
flag.BoolVar(&showVersion, "subm-version", showVersion, "Show version")
dnsserver.Directives = directives
}

func main() {
flag.Parse()
fmt.Fprintf(os.Stderr, "submariner-lighthouse-coredns version: %s\n", version)

if showVersion {
return
}

coremain.Run()
}
2 changes: 0 additions & 2 deletions coredns/plugin/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ const (
var dnsQueryCounter *prometheus.GaugeVec

func init() {
log.Infof("Initializing dns query counter")

dnsQueryCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: ServiceDiscoveryQueryCounterName,
Expand Down
3 changes: 0 additions & 3 deletions coredns/plugin/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
var (
masterURL string
kubeconfig string
Version string
)

// Hooks for unit tests.
Expand Down Expand Up @@ -71,8 +70,6 @@ func init() {
// setup is the function that gets called when the config parser see the token "lighthouse". Setup is responsible
// for parsing any extra options the this plugin may have. The first token this function sees is "lighthouse".
func setupLighthouse(c *caddy.Controller) error {
log.Infof("submariner-lighthouse-coredns version: %v", Version)

l, err := lighthouseParse(c)
if err != nil {
return plugin.Error(PluginName, err) //nolint:wrapcheck // No need to wrap this.
Expand Down
22 changes: 15 additions & 7 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,12 @@ func main() {
return
}

fmt.Fprintf(os.Stderr, "%s version: %s\n", componentName, version)

if showVersion {
return
}

kzerolog.InitK8sLogging()

// initialize klog as well, since some internal k8s packages still log with klog directly
Expand Down Expand Up @@ -112,8 +122,6 @@ func main() {
localClient, err := dynamic.NewForConfig(cfg)
exitOnError(err, "Error creating dynamic client")

logger.Infof("submariner-lighthouse-agent version: %v", version)

// set up signals so we handle the first shutdown signal gracefully
ctx := signals.SetupSignalHandler()

Expand Down

0 comments on commit d3c4f85

Please sign in to comment.