Skip to content

Commit

Permalink
chore: add version info
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Oct 15, 2020
1 parent 74a2344 commit 6088851
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 14 deletions.
31 changes: 17 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ GO_VERSION=1.14
REGISTRY=kubeovn
DEV_TAG=dev
RELEASE_TAG=$(shell cat VERSION)
COMMIT=git-$(shell git rev-parse HEAD)
GOLDFLAGS="-w -s -X github.com/alauda/kube-ovn/versions.COMMIT=${COMMIT} -X github.com/alauda/kube-ovn/versions.VERSION=${RELEASE_TAG}"

# ARCH could be amd64,arm64
ARCH=amd64
Expand All @@ -22,22 +24,22 @@ push-dev:
docker push ${REGISTRY}/kube-ovn:${DEV_TAG}

build-go:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn -ldflags "-w -s" -v ./cmd/cni
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-controller -ldflags "-w -s" -v ./cmd/controller
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-daemon -ldflags "-w -s" -v ./cmd/daemon
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-pinger -ldflags "-w -s" -v ./cmd/pinger
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-webhook -ldflags "-w -s" -v ./cmd/webhook
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-speaker -ldflags "-w -s" -v ./cmd/speaker
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-monitor -ldflags "-w -s" -v ./cmd/ovn_monitor
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn -ldflags $(GOLDFLAGS) -v ./cmd/cni
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-controller -ldflags $(GOLDFLAGS) -v ./cmd/controller
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-daemon -ldflags $(GOLDFLAGS) -v ./cmd/daemon
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-pinger -ldflags $(GOLDFLAGS) -v ./cmd/pinger
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-webhook -ldflags $(GOLDFLAGS) -v ./cmd/webhook
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-speaker -ldflags $(GOLDFLAGS) -v ./cmd/speaker
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(PWD)/dist/images/kube-ovn-monitor -ldflags $(GOLDFLAGS) -v ./cmd/ovn_monitor

build-go-arm:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn -ldflags "-w -s" -v ./cmd/cni
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-controller -ldflags "-w -s" -v ./cmd/controller
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-daemon -ldflags "-w -s" -v ./cmd/daemon
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-pinger -ldflags "-w -s" -v ./cmd/pinger
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-webhook -ldflags "-w -s" -v ./cmd/webhook
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-speaker -ldflags "-w -s" -v ./cmd/speaker
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-monitor -ldflags "-w -s" -v ./cmd/ovn_monitor
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn -ldflags $(GOLDFLAGS) -v ./cmd/cni
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-controller -ldflags $(GOLDFLAGS) -v ./cmd/controller
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-daemon -ldflags $(GOLDFLAGS) -v ./cmd/daemon
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-pinger -ldflags $(GOLDFLAGS) -v ./cmd/pinger
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-webhook -ldflags $(GOLDFLAGS) -v ./cmd/webhook
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-speaker -ldflags $(GOLDFLAGS) -v ./cmd/speaker
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(PWD)/dist/images/kube-ovn-monitor -ldflags $(GOLDFLAGS) -v ./cmd/ovn_monitor

release: lint build-go
docker buildx build --cache-from "type=local,src=/tmp/.buildx-cache" --cache-to "type=local,dest=/tmp/.buildx-cache" --platform linux/amd64 --build-arg ARCH=amd64 --build-arg RPM_ARCH=x86_64 -t ${REGISTRY}/kube-ovn:${RELEASE_TAG} -o type=docker -f dist/images/Dockerfile dist/images/
Expand All @@ -58,6 +60,7 @@ lint:
@GOOS=linux gosec -exclude=G204 ./...

build-bin:

docker run --rm -e GOOS=linux -e GOCACHE=/tmp -e GOARCH=${ARCH} -e GOPROXY=https://goproxy.cn \
-u $(shell id -u):$(shell id -g) \
-v $(CURDIR):/go/src/github.com/alauda/kube-ovn:ro \
Expand Down
2 changes: 2 additions & 0 deletions cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"github.com/alauda/kube-ovn/versions"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
_ "net/http/pprof" // #nosec
Expand All @@ -19,6 +20,7 @@ func main() {
defer klog.Flush()

stopCh := signals.SetupSignalHandler()
klog.Infof(versions.String())

config, err := controller.ParseFlags()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/daemon/cniserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"github.com/alauda/kube-ovn/pkg/util"
"github.com/alauda/kube-ovn/versions"
"github.com/prometheus/client_golang/prometheus/promhttp"
"io/ioutil"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -19,6 +20,7 @@ import (
func main() {
defer klog.Flush()

klog.Infof(versions.String())
config, err := daemon.ParseFlags()
if err != nil {
klog.Fatalf("parse config failed %v", err)
Expand Down
4 changes: 4 additions & 0 deletions cmd/ovn_monitor/ovn_monitor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"github.com/alauda/kube-ovn/versions"
"net/http"

ovn "github.com/alauda/kube-ovn/pkg/ovnmonitor"
Expand All @@ -9,6 +10,9 @@ import (
)

func main() {
defer klog.Flush()

klog.Infof(versions.String())
config, err := ovn.ParseFlags()
if err != nil {
klog.Fatalf("parse config failed %v", err)
Expand Down
4 changes: 4 additions & 0 deletions cmd/pinger/pinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"github.com/alauda/kube-ovn/versions"
"net/http"

"github.com/alauda/kube-ovn/pkg/pinger"
Expand All @@ -10,6 +11,9 @@ import (
)

func main() {
defer klog.Flush()

klog.Infof(versions.String())
config, err := pinger.ParseFlags()
if err != nil {
klog.Fatalf("parse config failed %v", err)
Expand Down
3 changes: 3 additions & 0 deletions cmd/speaker/speaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"github.com/alauda/kube-ovn/pkg/speaker"
"github.com/alauda/kube-ovn/versions"
"github.com/prometheus/client_golang/prometheus/promhttp"
"k8s.io/klog"
"k8s.io/sample-controller/pkg/signals"
Expand All @@ -11,6 +12,8 @@ import (

func main() {
defer klog.Flush()

klog.Infof(versions.String())
config, err := speaker.ParseFlags()
if err != nil {
klog.Fatalf("failed to parse config %v", err)
Expand Down
3 changes: 3 additions & 0 deletions cmd/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"github.com/alauda/kube-ovn/versions"
_ "net/http/pprof" // #nosec
"os"
"time"
Expand Down Expand Up @@ -47,6 +48,8 @@ func main() {
ovnNbTimeout int
defaultLS string
)
klog.Infof(versions.String())

flag.IntVar(&port, "port", 8443, "The port webhook listen on.")
flag.IntVar(&ovnNbPort, "ovn-nb-port", 6641, "OVN nb port")
flag.IntVar(&ovnNbTimeout, "ovn-nb-timeout", 30, "OVN nb timeout")
Expand Down
25 changes: 25 additions & 0 deletions versions/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package versions

import (
"fmt"
"runtime"
"time"
)

var (
COMMIT = "unknown"
VERSION = "unknown"
)

func String() string {
return fmt.Sprintf(`
-------------------------------------------------------------------------------
Kube-OVN:
Version: %v
Build: %v
Commit: %v
Go Version: %v
Arch: %v
-------------------------------------------------------------------------------
`, VERSION, time.Now().String(), COMMIT, runtime.Version(), runtime.GOARCH)
}

0 comments on commit 6088851

Please sign in to comment.