Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
add version info with ldflags
Browse files Browse the repository at this point in the history
  • Loading branch information
andyxning committed Nov 29, 2016
1 parent b82f78f commit 153abce
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
@@ -1,5 +1,3 @@
sudo: false

language: go

go_import_path: k8s.io/heapster
Expand Down
14 changes: 8 additions & 6 deletions Makefile
@@ -1,18 +1,20 @@
all: build

TAG = v1.2.0
PREFIX = gcr.io/google_containers
FLAGS =

VERSION = v1.2.0
GIT_COMMIT := `git rev-parse --short HEAD`

SUPPORTED_KUBE_VERSIONS = "1.4.6"
TEST_NAMESPACE = heapster-e2e-tests

deps:
which godep || go get github.com/tools/godep

build: clean deps
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -o heapster k8s.io/heapster/metrics
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -o eventer k8s.io/heapster/events
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -ldflags "-X k8s.io/heapster/version.HeapsterVersion=$(VERSION) -X k8s.io/heapster/version.GitCommit=$(GIT_COMMIT)" -o heapster k8s.io/heapster/metrics
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -ldflags "-X k8s.io/heapster/version.HeapsterVersion=$(VERSION) -X k8s.io/heapster/version.GitCommit=$(GIT_COMMIT)" -o eventer k8s.io/heapster/events

sanitize:
hooks/check_boilerplate.sh
Expand All @@ -31,13 +33,13 @@ test-integration: clean deps build
container: build
cp heapster deploy/docker/heapster
cp eventer deploy/docker/eventer
docker build -t $(PREFIX)/heapster:$(TAG) deploy/docker/
docker build -t $(PREFIX)/heapster:$(VERSION) deploy/docker/

grafana:
docker build -t $(PREFIX)/heapster_grafana:$(TAG) grafana/
docker build -t $(PREFIX)/heapster_grafana:$(VERSION) grafana/

influxdb:
docker build -t $(PREFIX)/heapster_influxdb:$(TAG) influxdb/
docker build -t $(PREFIX)/heapster_influxdb:$(VERSION) influxdb/

clean:
rm -f heapster
Expand Down
7 changes: 7 additions & 0 deletions events/eventer.go
Expand Up @@ -38,15 +38,22 @@ var (
argMaxProcs = flag.Int("max_procs", 0, "max number of CPUs that can be used simultaneously. Less than 1 for default (number of cores)")
argSources flags.Uris
argSinks flags.Uris
argVersion bool
)

func main() {
quitChannel := make(chan struct{}, 0)

flag.Var(&argSources, "source", "source(s) to read events from")
flag.Var(&argSinks, "sink", "external sink(s) that receive events")
flag.BoolVar(&argVersion, "version", false, "print version info and exit")
flag.Parse()

if argVersion {
fmt.Println(version.VersionInfo())
os.Exit(0)
}

logs.InitLogs()
defer logs.FlushLogs()

Expand Down
8 changes: 6 additions & 2 deletions metrics/heapster.go
Expand Up @@ -49,17 +49,21 @@ import (
"k8s.io/kubernetes/pkg/healthz"
"k8s.io/kubernetes/pkg/util/flag"
"k8s.io/kubernetes/pkg/util/logs"
"k8s.io/kubernetes/pkg/version/verflag"
)

func main() {
opt := options.NewHeapsterRunOptions()
opt.AddFlags(pflag.CommandLine)

flag.InitFlags()

if opt.Version {
fmt.Println(version.VersionInfo())
os.Exit(0)
}

logs.InitLogs()
defer logs.FlushLogs()
verflag.PrintAndExitIfRequested()

setMaxProcs(opt)
glog.Infof(strings.Join(os.Args, " "))
Expand Down
2 changes: 2 additions & 0 deletions metrics/options/options.go
Expand Up @@ -37,6 +37,7 @@ type HeapsterRunOptions struct {
Sources flags.Uris
Sinks flags.Uris
HistoricalSource string
Version bool
}

func NewHeapsterRunOptions() *HeapsterRunOptions {
Expand Down Expand Up @@ -65,4 +66,5 @@ func (h *HeapsterRunOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&h.TLSClientCAFile, "tls_client_ca", "", "file containing TLS client CA for client cert validation")
fs.StringVar(&h.AllowedUsers, "allowed_users", "", "comma-separated list of allowed users")
fs.StringVar(&h.HistoricalSource, "historical_source", "", "which source type to use for the historical API (should be exactly the same as one of the sink URIs), or empty to disable the historical API")
fs.BoolVar(&h.Version, "version", false, "print version info and exit")
}
11 changes: 10 additions & 1 deletion version/version.go
Expand Up @@ -14,9 +14,18 @@

package version

import "fmt"

// Heapster version. Update this whenever making a new release.
// The version is of the format Major.Minor.Patch
// Increment major number for new feature additions and behavioral changes.
// Increment minor number for bug fixes and performance enhancements.
// Increment patch number for critical fixes to existing releases.
const HeapsterVersion = "1.2.0"
var HeapsterVersion string

// Heapster git short commit hash.
var GitCommit string

func VersionInfo() string {
return fmt.Sprintf("version: %s\ncommit: %s", HeapsterVersion, GitCommit)
}

0 comments on commit 153abce

Please sign in to comment.