Skip to content

Commit

Permalink
log submariner component's version on startup
Browse files Browse the repository at this point in the history
Signed-off-by: cyclinder <[email protected]>
  • Loading branch information
cyclinder committed Jun 19, 2023
1 parent 3e0ab8b commit 2d6d145
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
BASE_BRANCH ?= devel
export BASE_BRANCH
export VERSION="devel"
PROTOC_VERSION=3.17.3

# Running in Dapper
Expand All @@ -18,7 +19,9 @@ endif
include $(SHIPYARD_DIR)/Makefile.inc

TARGETS := $(shell ls -p scripts | grep -v -e /)
export LDFLAGS = -X main.VERSION=$(VERSION)
GIT_COMMIT_VERSION := $(shell git show -s --format='format:%H')
GIT_COMMIT_TIME := $(shell git show -s --format='format:%aI')
export LDFLAGS = -X github.com/submariner-io/submariner/pkg/version/version.version=$(VERSION) github.com/submariner-io/submariner/pkg/version/version.gitCommit=$(GIT_COMMIT_VERSION) github.com/submariner-io/submariner/pkg/version/version.gitBuildDate=$(GIT_COMMIT_TIME)

ifneq (,$(filter external-net,$(_using)))
export TESTDIR = test/external
Expand Down Expand Up @@ -63,16 +66,24 @@ bin/protoc:
rm -f protoc-$(PROTOC_VERSION)-linux-x86_64.zip

bin/%/submariner-gateway: main.go $(shell find pkg -not \( -path 'pkg/globalnet*' -o -path 'pkg/routeagent*' \)) pkg/natdiscovery/proto/natdiscovery.pb.go
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ .
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) \
LDFLAGS=$(LDFLAGS) \
${SCRIPTS_DIR}/compile.sh $@ .

bin/%/submariner-route-agent: $(shell find pkg/routeagent_driver)
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ ./pkg/routeagent_driver
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) \
LDFLAGS=$(LDFLAGS) \
${SCRIPTS_DIR}/compile.sh $@ ./pkg/routeagent_driver

bin/%/submariner-globalnet: $(shell find pkg/globalnet)
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ ./pkg/globalnet
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) \
LDFLAGS=$(LDFLAGS) \
${SCRIPTS_DIR}/compile.sh $@ ./pkg/globalnet

bin/%/submariner-networkplugin-syncer: $(shell find pkg/networkplugin-syncer)
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ ./pkg/networkplugin-syncer
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) \
LDFLAGS=$(LDFLAGS) \
${SCRIPTS_DIR}/compile.sh $@ ./pkg/networkplugin-syncer

nullstring :=
space := $(nullstring) # end of the line
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"errors"
"flag"
"fmt"
"github.com/submariner-io/submariner/pkg/version"
"net/http"
"net/http/pprof"
"os"
Expand Down Expand Up @@ -114,6 +115,8 @@ func main() {
flag.Parse()
kzerolog.InitK8sLogging()

version.PrintVersion(&logger)

logger.Info("Starting the submariner gateway engine")

components := &componentsType{
Expand Down
3 changes: 3 additions & 0 deletions pkg/globalnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package main
import (
"context"
"flag"
"github.com/submariner-io/submariner/pkg/version"
"net/http"
"net/http/pprof"
"time"
Expand Down Expand Up @@ -54,6 +55,8 @@ func main() {
flag.Parse()
kzerolog.InitK8sLogging()

version.PrintVersion(&logger)

var spec controllers.Specification

err := envconfig.Process("submariner", &spec)
Expand Down
3 changes: 3 additions & 0 deletions pkg/networkplugin-syncer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
eventlogger "github.com/submariner-io/submariner/pkg/event/logger"
"github.com/submariner-io/submariner/pkg/networkplugin-syncer/handlers/ovn"
"github.com/submariner-io/submariner/pkg/routeagent_driver/environment"
"github.com/submariner-io/submariner/pkg/version"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -49,6 +50,8 @@ func main() {
flag.Parse()
kzerolog.InitK8sLogging()

version.PrintVersion(&logger)

logger.Info("Starting submariner-networkplugin-syncer")
// set up signals so we handle the first shutdown signal gracefully
stopCh := signals.SetupSignalHandler().Done()
Expand Down
3 changes: 3 additions & 0 deletions pkg/routeagent_driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/submariner-io/submariner/pkg/routeagent_driver/handlers/kubeproxy"
"github.com/submariner-io/submariner/pkg/routeagent_driver/handlers/mtu"
"github.com/submariner-io/submariner/pkg/routeagent_driver/handlers/ovn"
"github.com/submariner-io/submariner/pkg/version"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand All @@ -59,6 +60,8 @@ func main() {
flag.Parse()
kzerolog.InitK8sLogging()

version.PrintVersion(&logger)

logger.Info("Starting submariner-route-agent using the event framework")
// set up signals so we handle the first shutdown signal gracefully
stopCh := signals.SetupSignalHandler().Done()
Expand Down
40 changes: 40 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
SPDX-License-Identifier: Apache-2.0
Copyright Contributors to the Submariner project.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package version

import (
"fmt"
"runtime"

"github.com/submariner-io/admiral/pkg/log"
)

var (
version = "devel"
goRuntimeString = fmt.Sprintf("%s / %s / %s", runtime.Compiler, runtime.Version(), runtime.GOARCH)
gitCommit string
gitBuildDate string
)

func PrintVersion(logger *log.Logger) {
logger.Info(fmt.Sprintf("Go Version: %s", goRuntimeString))
logger.Info(fmt.Sprintf("Git Commit: %s", gitCommit))
logger.Info(fmt.Sprintf("Git Commit Time: %s", gitBuildDate))
logger.Info(fmt.Sprintf("Submariner version: %v", version))
}

0 comments on commit 2d6d145

Please sign in to comment.