Skip to content

Commit

Permalink
Metrics Server: print versions during startup (#748)
Browse files Browse the repository at this point in the history
* print versions during startup
  • Loading branch information
zroubalik authored Apr 20, 2020
1 parent 1a643cf commit ac8d350
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ release: release_prepare release_file release_pkg

.PHONY: release_file
release_file:
@sed -i 's@Version =.*@Version = "$(VERSION)"@g' ./version/version.go;
@sed -i 's@Version =.*@Version = "$(VERSION)"@g' ./version/version.go;
@for file in $(K8S_DEPLOY_FILES); do \
sed -i '[email protected]/version:.*@app.kubernetes.io/version: "$(VERSION)"@g' $$file; \
sed -i 's@image: docker.io/kedacore/keda:.*@image: docker.io/kedacore/keda:$(VERSION)@g' $$file; \
Expand Down Expand Up @@ -98,12 +98,12 @@ build: checkenv build-adapter build-controller
.PHONY: build-controller
build-controller: generate-api pkg/scalers/liiklus/LiiklusService.pb.go
$(GO_BUILD_VARS) operator-sdk build $(IMAGE_CONTROLLER) \
--go-build-args "-ldflags -X=main.GitCommit=$(GIT_COMMIT) -ldflags -X=github.com/kedacore/keda/version.Version=$(VERSION) -o build/_output/bin/keda"
--go-build-args "-ldflags -X=github.com/kedacore/keda/version.Version=$(VERSION) -o build/_output/bin/keda"

.PHONY: build-adapter
build-adapter: generate-api pkg/scalers/liiklus/LiiklusService.pb.go
$(GO_BUILD_VARS) go build \
-ldflags "-X=main.GitCommit=$(GIT_COMMIT) -X=github.com/kedacore/keda/version.Version=$(VERSION)" \
-ldflags "-X=github.com/kedacore/keda/version.GitCommit=$(GIT_COMMIT) -X=github.com/kedacore/keda/version.Version=$(VERSION)" \
-o build/_output/bin/keda-adapter \
cmd/adapter/main.go
docker build -f build/Dockerfile.adapter -t $(IMAGE_ADAPTER) .
Expand Down
12 changes: 12 additions & 0 deletions cmd/adapter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package main

import (
"flag"
"fmt"
"os"
"runtime"

"github.com/kedacore/keda/pkg/handler"
kedaprovider "github.com/kedacore/keda/pkg/provider"
"github.com/kedacore/keda/version"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog"
Expand Down Expand Up @@ -70,9 +73,18 @@ func (a *Adapter) makeProviderOrDie() provider.MetricsProvider {
return kedaprovider.NewProvider(logger, handler, kubeclient, namespace)
}

func printVersion() {
logger.Info(fmt.Sprintf("KEDA Version: %s", version.Version))
logger.Info(fmt.Sprintf("KEDA Commit: %s", version.GitCommit))
logger.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
logger.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH))
}

func main() {
defer klog.Flush()

printVersion()

cmd := &Adapter{}
cmd.Flags().StringVar(&cmd.Message, "msg", "starting adapter...", "startup message")
cmd.Flags().AddGoFlagSet(flag.CommandLine) // make sure we get the klog flags
Expand Down
5 changes: 3 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"k8s.io/client-go/rest"

"github.com/kedacore/keda/pkg/apis"
"github.com/kedacore/keda/version"
"github.com/kedacore/keda/pkg/controller"

"github.com/operator-framework/operator-sdk/pkg/k8sutil"
Expand All @@ -32,18 +33,18 @@ import (

// Change below variables to serve metrics on different host or port.
var (
GitCommit string
metricsHost = "0.0.0.0"
metricsPort int32 = 8383
operatorMetricsPort int32 = 8686
)
var log = logf.Log.WithName("cmd")

func printVersion() {
log.Info(fmt.Sprintf("KEDA Version: %s", version.Version))
//log.Info(fmt.Sprintf("KEDA Commit: %s", version.GitCommit)) // multiple -ldflags doesn't work with operator-sdk v0.12, let's reenable this for KEDA v2
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("Version of operator-sdk: %v", sdkVersion.Version))
log.Info(fmt.Sprintf("Keda Commit: %s", GitCommit))
}

func main() {
Expand Down
3 changes: 2 additions & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package version

var (
Version = "1.4.0"
Version = "1.4.0"
GitCommit string
)

0 comments on commit ac8d350

Please sign in to comment.