Skip to content

Commit 2d8ce79

Browse files
committed
build fixes for k8s support
1 parent eb60b35 commit 2d8ce79

File tree

6 files changed

+28
-23
lines changed

6 files changed

+28
-23
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ REPOSITORY := mattdeboer/mpp
55
DOCKER_IMAGE = ${REPOSITORY}:${VERSION}
66
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
77
REVISION ?= $(shell git rev-parse HEAD)
8-
LD_FLAGS ?= -s -X main.Name=$(TARGET) -X main.Revision=$(REVISION) -X main.Branch=$(BRANCH) -X main.Version=$(VERSION)
8+
LD_FLAGS ?= -s -X version.Name=$(TARGET) -X version.Revision=$(REVISION) -X version.Branch=$(BRANCH) -X version.Version=$(VERSION)
99

1010
default: test build
1111

pkg/router/metrics.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package router
22

3-
import "github.com/prometheus/client_golang/prometheus"
4-
5-
const metricsNamespace = "mpp"
3+
import (
4+
"github.com/prometheus/client_golang/prometheus"
5+
)
66

77
type metrics struct {
88
selectedBackends prometheus.Gauge

pkg/router/router.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
log "github.com/Sirupsen/logrus"
1313
"github.com/matt-deboer/mpp/pkg/locator"
1414
"github.com/matt-deboer/mpp/pkg/selector"
15+
"github.com/matt-deboer/mpp/pkg/version"
1516
"github.com/vulcand/oxy/buffer"
1617
"github.com/vulcand/oxy/forward"
1718
)
@@ -58,7 +59,7 @@ func NewRouter(interval time.Duration, affinityOptions []AffinityOption,
5859
selector: sel,
5960
affinityOptions: affinityOptions,
6061
interval: interval,
61-
metrics: newMetrics(metricsNamespace),
62+
metrics: newMetrics(version.Name),
6263
theConch: make(chan struct{}, 1),
6364
}
6465

pkg/server/handler.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
log "github.com/Sirupsen/logrus"
1111
"github.com/matt-deboer/mpp/pkg/router"
12+
"github.com/matt-deboer/mpp/pkg/version"
1213
"github.com/prometheus/client_golang/prometheus"
1314
"github.com/prometheus/client_golang/prometheus/promhttp"
1415
)
@@ -31,10 +32,10 @@ func newMPPHandler(r *router.Router) *mppHandler {
3132
Name: "build_info",
3233
Help: "The number of currently selected backends",
3334
ConstLabels: prometheus.Labels{
34-
"branch": Branch,
35+
"branch": version.Branch,
3536
"goversion": runtime.Version(),
36-
"version": Version,
37-
"revision": Revision,
37+
"version": version.Version,
38+
"revision": version.Revision,
3839
},
3940
})
4041
buildInfo.Set(1)
@@ -56,7 +57,7 @@ func (p *mppHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
5657
data := &templateData{
5758
RouterStatus: p.router.Status(),
5859
Uptime: time.Now().Sub(p.started),
59-
Version: Version,
60+
Version: version.Version,
6061
GoVersion: runtime.Version(),
6162
}
6263
if log.GetLevel() >= log.DebugLevel {

pkg/server/main.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package main // import "github.com/matt-deboer/mpp/pkg/server"
22

33
import (
44
"fmt"
@@ -16,29 +16,19 @@ import (
1616
_ "github.com/matt-deboer/mpp/pkg/selector/strategy/minimumhistory"
1717
_ "github.com/matt-deboer/mpp/pkg/selector/strategy/random"
1818
_ "github.com/matt-deboer/mpp/pkg/selector/strategy/singlemostdata"
19+
"github.com/matt-deboer/mpp/pkg/version"
1920
"github.com/urfave/cli"
2021
)
2122

22-
var (
23-
// Name is set at compile time based on the git repository
24-
Name string
25-
// Version is set at compile time with the git version
26-
Version string
27-
// Branch is set at compile time with the git version
28-
Branch string
29-
// Revision is set at compile time with the git version
30-
Revision string
31-
)
32-
3323
func main() {
3424

3525
app := cli.NewApp()
36-
app.Name = Name
26+
app.Name = version.Name
3727
app.Usage = `
3828
Launch a dynamically configured proxy over multiple prometheus endpoints
3929
which selects a single endpoint based on configurable criteria.
4030
`
41-
app.Version = Version
31+
app.Version = version.Version
4232
app.Flags = []cli.Flag{
4333
cli.StringFlag{
4434
Name: "kubeconfig",

pkg/version/doc.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Package version contains build-time version info
2+
package version // import "github.com/matt-deboer/mpp/pkg/version"
3+
4+
var (
5+
// Name is set at compile time based on the git repository
6+
Name string
7+
// Version is set at compile time with the git version
8+
Version string
9+
// Branch is set at compile time with the git version
10+
Branch string
11+
// Revision is set at compile time with the git version
12+
Revision string
13+
)

0 commit comments

Comments
 (0)