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 #2751

Signed-off-by: Vishal Thapar <[email protected]>
  • Loading branch information
vthapar authored and tpantelis committed Aug 7, 2023
1 parent 3e9f4e9 commit 86081de
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.67.1
github.com/prometheus-operator/prometheus-operator/pkg/client v0.67.1
github.com/prometheus/client_golang v1.16.0
github.com/submariner-io/admiral v0.16.0-m3
github.com/submariner-io/admiral v0.16.0-m3.0.20230807132642-3d805dda2f2c
github.com/submariner-io/shipyard v0.16.0-m3
github.com/submariner-io/submariner v0.16.0-m3
github.com/uw-labs/lichen v0.1.7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/submariner-io/admiral v0.16.0-m3 h1:qHpRw8mE80/Q3e/2z0ZPdqPVBESYWPPXRmJxUn5azeY=
github.com/submariner-io/admiral v0.16.0-m3/go.mod h1:wiU8hC/soJ6C3g634CFvaGq/Hptgy4D2Xpf8IlQ5y5A=
github.com/submariner-io/admiral v0.16.0-m3.0.20230807132642-3d805dda2f2c h1:Poy5ytHRcX/XET/5Ha4kC/BuWiKJSkfv2Hgyn/K/2zc=
github.com/submariner-io/admiral v0.16.0-m3.0.20230807132642-3d805dda2f2c/go.mod h1:wiU8hC/soJ6C3g634CFvaGq/Hptgy4D2Xpf8IlQ5y5A=
github.com/submariner-io/shipyard v0.16.0-m3 h1:795gM5zCjszEjQ5UM9LY/7vRTldHt16PdETTzjY265A=
github.com/submariner-io/shipyard v0.16.0-m3/go.mod h1:P6zHeYDcQMS24/8Z7NN2WP4Ydqdu4CB4HC+VRn3l2MA=
github.com/submariner-io/submariner v0.16.0-m3 h1:AMwSNZOv64XyLOrDxVFYOb2a+nZU7dwWam1Bkt23T7A=
Expand Down
19 changes: 14 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
configv1 "github.com/openshift/api/config/v1"
"github.com/operator-framework/operator-lib/leader"
"github.com/submariner-io/admiral/pkg/log/kzerolog"
"github.com/submariner-io/admiral/pkg/names"
admversion "github.com/submariner-io/admiral/pkg/version"
"github.com/submariner-io/submariner-operator/api/v1alpha1"
"github.com/submariner-io/submariner-operator/controllers/metrics"
"github.com/submariner-io/submariner-operator/controllers/servicediscovery"
Expand Down Expand Up @@ -58,20 +60,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 +94,12 @@ func main() {
return
}

admversion.Print(names.OperatorComponent, version)

if showVersion {
return
}

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

Expand Down
2 changes: 1 addition & 1 deletion scripts/test/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ subm_ns=submariner-operator
# Check that we're testing the version we expect
function check_operator_version() {
local opv
opv=$(kubectl --context="$cluster" logs -n submariner-operator -l name=submariner-operator --tail=-1 | awk '/Submariner operator version/ { print $NF }')
opv=$(kubectl --context="$cluster" logs -n submariner-operator -l name=submariner-operator --tail=-1 | awk '/submariner-operator version/ { print $NF }')
printf "Cluster %s is running operator version %s\n" "$cluster" "$opv"
if [ "$opv" != "$VERSION" ]; then
printf "Operator version mismatch: expected %s, got %s\n" "$VERSION" "$opv"
Expand Down

0 comments on commit 86081de

Please sign in to comment.