Skip to content

Commit 4df71fb

Browse files
Switch from dep to go modules
* switch from dep to go modules * upgrade dependencies * simplify a bit the example and its instructions * add containersol/helm-monitor Docker container
1 parent 1d72a7b commit 4df71fb

26 files changed

+467
-480
lines changed

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.DS_Store
2+
.git
3+
.gitignore
4+
.travis.yml
5+
CHANGELOG.md
6+
LICENSE
7+
Makefile
8+
README.md
9+
asciinema_demo.json
10+
examples
11+
helm-monitor-diagram.jpg
12+
helm-monitor-failure.png

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.DS_Store
12
vendor
23
examples/app/vendor
34
_dist

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
language: go
22

33
go:
4-
- 1.9.2
5-
6-
install:
7-
- make dep
4+
- master
85

96
script:
107
- make test-all

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM golang:1.11 AS build
2+
ENV GOPATH=""
3+
ENV GO111MODULE=on
4+
ARG LDFLAGS
5+
COPY . /go
6+
RUN go build -o helm-monitor -ldflags "$LDFLAGS" ./cmd/...
7+
8+
FROM alpine AS helm
9+
ENV HELM_VERSION=v2.10.0
10+
ENV HELM_TMP_FILE=helm-${HELM_VERSION}-linux-amd64.tar.gz
11+
RUN wget https://storage.googleapis.com/kubernetes-helm/${HELM_TMP_FILE} && \
12+
wget https://storage.googleapis.com/kubernetes-helm/${HELM_TMP_FILE}.sha256
13+
RUN apk --no-cache add openssl
14+
RUN if [ "$(openssl sha1 -sha256 ${HELM_TMP_FILE} | awk '{print $2}')" != "$(cat helm-${HELM_VERSION}-linux-amd64.tar.gz.sha256)" ]; \
15+
then \
16+
echo "SHA sum of ${HELM_TMP_FILE} does not match. Aborting."; \
17+
exit 1; \
18+
fi
19+
RUN tar -xvf helm-${HELM_VERSION}-linux-amd64.tar.gz
20+
21+
FROM alpine:3.8
22+
COPY --from=helm /linux-amd64/helm /usr/local/bin/helm
23+
RUN helm init --skip-refresh --client-only && \
24+
mkdir -p /root/.helm/plugins/helm-monitor
25+
COPY plugin.yaml /root/.helm/plugins/helm-monitor/plugin.yaml
26+
COPY --from=build /go/helm-monitor /root/.helm/plugins/helm-monitor/helm-monitor
27+
ENTRYPOINT ["helm"]

Gopkg.lock

Lines changed: 0 additions & 105 deletions
This file was deleted.

Gopkg.toml

Lines changed: 0 additions & 34 deletions
This file was deleted.

Makefile

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,30 @@ VERSION := $(shell sed -n -e 's/version:[ "]*\([^"]*\).*/\1/p' plugin.yaml)
44
DIST := $(CURDIR)/_dist
55
LDFLAGS := "-X main.version=${VERSION}"
66
BINARY := "helm-monitor"
7+
DOCKER_IMAGE ?= containersol/helm-monitor
8+
DOCKER_TAG ?= latest
79

8-
.PHONY: dist release build install test lint vet dep
10+
# go mod ftw
11+
unexport GOPATH
12+
GO111MODULE = on
913

10-
install: dep build
14+
.PHONY: install
15+
install: build
1116
cp $(BINARY) $(HELM_PLUGIN_DIR)
1217
cp plugin.yaml $(HELM_PLUGIN_DIR)
1318

19+
.PHONY: build
1420
build:
1521
go build -o $(BINARY) -ldflags $(LDFLAGS) ./cmd/...
1622

23+
.PHONY: build.docker
24+
build.docker:
25+
docker build \
26+
--build-arg LDFLAGS=$(LDFLAGS) \
27+
--cache-from ${DOCKER_IMAGE} \
28+
-t ${DOCKER_IMAGE}:$(DOCKER_TAG) .
29+
30+
.PHONY: dist
1731
dist:
1832
mkdir -p $(DIST)
1933
GOOS=linux GOARCH=amd64 go build -o $(BINARY) -ldflags $(LDFLAGS) ./cmd/...
@@ -23,20 +37,18 @@ dist:
2337
GOOS=windows GOARCH=amd64 go build -o $(BINARY).exe -ldflags $(LDFLAGS) ./cmd/...
2438
tar -zcvf $(DIST)/helm-monitor_windows_$(VERSION).tar.gz $(BINARY).exe README.md LICENSE plugin.yaml
2539

40+
.PHONY: test-all
2641
test-all: vet lint test
2742

43+
.PHONY: test
2844
test:
2945
go test -v -parallel=4 ./cmd/...
3046

47+
.PHONY: lint
3148
lint:
32-
@go get github.com/golang/lint/golint
33-
go list ./cmd/... | grep -v vendor | xargs -n1 golint
49+
@go get -u golang.org/x/lint/golint
50+
go list ./cmd/... | xargs -n1 $${HOME}/go/bin/golint
3451

52+
.PHONY: vet
3553
vet:
3654
go vet ./cmd/...
37-
38-
dep:
39-
ifndef HAS_DEP
40-
go get -u github.com/golang/dep/cmd/dep
41-
endif
42-
dep ensure

README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,28 @@ $ helm monitor elasticsearch --elasticsearch=http://elasticsearch:9200 \
6969
'status:500 AND kubernetes.labels.app:app AND version:2.0.0'
7070
```
7171

72-
## Development
72+
## Docker
7373

74-
Clone the repo, then add a symlink to the Helm plugin directory:
74+
You can also use the Helm monitor backed Docker image to monitor:
7575

7676
```bash
77-
$ ln -s $GOPATH/src/github.com/ContainerSolutions/helm-monitor ~/.helm/plugins/helm-monitor
77+
$ docker run -ti -v $HOME/.kube:/root/.kube containersol/helm-monitor \
78+
monitor prometheus --prometheus=http://prometheus:9090 my-release \
79+
'rate(http_requests_total{code=~"^5.*$"}[5m]) > 0'
7880
```
7981

80-
Install dependencies using [dep](https://github.com/golang/dep):
81-
82-
```bash
83-
$ dep ensure
84-
```
82+
## Development
8583

86-
Build:
84+
Require Go >= 1.11.
8785

8886
```bash
89-
$ go build -o helm-monitor ./cmd/...
90-
```
87+
# Clone the repo, then add a symlink to the Helm plugin directory:
88+
$ ln -s $GOPATH/src/github.com/ContainerSolutions/helm-monitor ~/.helm/plugins/helm-monitor
9189

92-
Run:
90+
# Build:
91+
$ GOPATH="" GO111MODULE=on go build -o helm-monitor ./cmd/...
9392

94-
```bash
93+
# Run:
9594
$ helm monitor elasticsearch my-release ./examples/elasticsearch-query.json
9695
```
9796

examples/Makefile

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
1-
.PHONY: installtiller
2-
installtiller:
3-
kubectl apply -f https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.9/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/cluster-roles.yaml --validate=false
4-
kubectl apply -f https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.9/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/cluster-role-bindings.yaml --validate=false
5-
kubectl create serviceaccount tiller --namespace kube-system || true
6-
kubectl create clusterrolebinding tiller \
7-
--clusterrole=cluster-admin \
8-
--serviceaccount=kube-system:tiller || true
9-
helm init --upgrade --service-account tiller
1+
PROMETHEUS_VERSION=7.0.2
102

11-
.PHONY: prepare
12-
prepare:
3+
.PHONY: build
4+
build:
135
eval $$(minikube docker-env) && \
14-
docker build --build-arg "VERSION=1.0.0" -t app:1.0.0 app && \
15-
docker build --build-arg "VERSION=2.0.0" -t app:2.0.0 app
6+
docker build \
7+
-v $${HOME}/go:/root/go \
8+
--build-arg "LDFLAGS=-X main.version=1.0.0" \
9+
-t my-app:1.0.0 \
10+
app && \
11+
docker build \
12+
-v $${HOME}/go:/root/go \
13+
--build-arg "LDFLAGS=-X main.version=2.0.0" \
14+
-t my-app:2.0.0 \
15+
app
1616

1717
.PHONY: deployv1
1818
deployv1:
19-
helm upgrade --install my-release ./app/charts --set image.tag=1.0.0
19+
helm upgrade -i my-app --set image.tag=1.0.0 ./app/charts
2020

2121
.PHONY: deployv2
2222
deployv2:
23-
helm upgrade my-release ./app/charts --set image.tag=2.0.0
23+
helm upgrade -i my-app --set image.tag=2.0.0 ./app/charts
2424

2525
.PHONY: installprometheus
2626
installprometheus:
27-
helm repo add coreos https://s3-eu-west-1.amazonaws.com/coreos-charts/stable/
28-
helm upgrade --install prometheus-operator coreos/prometheus-operator
29-
kubectl apply -f ./prometheus.yaml
27+
helm upgrade -i \
28+
--version $(PROMETHEUS_VERSION) \
29+
--set server.service.type=LoadBalancer \
30+
--set server.global.scrape_interval=30s \
31+
--set alertmanager.enabled=false \
32+
--set kubeStateMetrics.enabled=false \
33+
--set nodeExporter.enabled=false \
34+
--set pushgateway.enabled=false \
35+
prometheus \
36+
stable/prometheus
3037

3138
.PHONY: cleanup
32-
kubectl delete -f ./prometheus.yaml
33-
helm del --purge prometheus-operator my-release
39+
helm del --purge prometheus my-app

0 commit comments

Comments
 (0)