Skip to content

Commit

Permalink
Add version flag to operator binary
Browse files Browse the repository at this point in the history
Refer submariner-io/enhancements#204

Fixes submariner-io#2751

Signed-off-by: Vishal Thapar <[email protected]>
  • Loading branch information
vthapar committed Aug 4, 2023
1 parent ffeb0c0 commit 6451ff8
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/submariner-io/submariner-operator/pkg/crd"
"github.com/submariner-io/submariner-operator/pkg/gateway"
"github.com/submariner-io/submariner-operator/pkg/lighthouse"
"github.com/submariner-io/submariner-operator/pkg/names"
submv1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiruntime "k8s.io/apimachinery/pkg/runtime"
Expand All @@ -58,20 +59,21 @@ var (
)

var (
scheme = apiruntime.NewScheme()
log = logf.Log.WithName("cmd")
help = false
version = "devel"
scheme = apiruntime.NewScheme()
log = logf.Log.WithName("cmd")
help = false
version = "devel"
showVersion = false
)

func printVersion() {
log.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
log.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH))
log.Info(fmt.Sprintf("Submariner operator version: %v", version))
}

func init() {
flag.BoolVar(&help, "help", help, "Print usage options")
flag.BoolVar(&showVersion, "version", showVersion, "Show version")
}

//nolint:gocyclo // No further refactors necessary
Expand All @@ -91,6 +93,12 @@ func main() {
return
}

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

if showVersion {
return
}

kzerolog.InitK8sLogging()
log.Info("Starting submariner-operator")

Expand Down

0 comments on commit 6451ff8

Please sign in to comment.