Skip to content

Commit

Permalink
Switch from dep to go modules
Browse files Browse the repository at this point in the history
* switch from dep to go modules
* upgrade dependencies
* simplify a bit the example and its instructions
* add containersol/helm-monitor Docker container
  • Loading branch information
etiennetremel authored Sep 7, 2018
1 parent 1d72a7b commit 4df71fb
Show file tree
Hide file tree
Showing 26 changed files with 467 additions and 480 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.DS_Store
.git
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
Makefile
README.md
asciinema_demo.json
examples
helm-monitor-diagram.jpg
helm-monitor-failure.png
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
vendor
examples/app/vendor
_dist
Expand Down
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
language: go

go:
- 1.9.2

install:
- make dep
- master

script:
- make test-all
Expand Down
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM golang:1.11 AS build
ENV GOPATH=""
ENV GO111MODULE=on
ARG LDFLAGS
COPY . /go
RUN go build -o helm-monitor -ldflags "$LDFLAGS" ./cmd/...

FROM alpine AS helm
ENV HELM_VERSION=v2.10.0
ENV HELM_TMP_FILE=helm-${HELM_VERSION}-linux-amd64.tar.gz
RUN wget https://storage.googleapis.com/kubernetes-helm/${HELM_TMP_FILE} && \
wget https://storage.googleapis.com/kubernetes-helm/${HELM_TMP_FILE}.sha256
RUN apk --no-cache add openssl
RUN if [ "$(openssl sha1 -sha256 ${HELM_TMP_FILE} | awk '{print $2}')" != "$(cat helm-${HELM_VERSION}-linux-amd64.tar.gz.sha256)" ]; \
then \
echo "SHA sum of ${HELM_TMP_FILE} does not match. Aborting."; \
exit 1; \
fi
RUN tar -xvf helm-${HELM_VERSION}-linux-amd64.tar.gz

FROM alpine:3.8
COPY --from=helm /linux-amd64/helm /usr/local/bin/helm
RUN helm init --skip-refresh --client-only && \
mkdir -p /root/.helm/plugins/helm-monitor
COPY plugin.yaml /root/.helm/plugins/helm-monitor/plugin.yaml
COPY --from=build /go/helm-monitor /root/.helm/plugins/helm-monitor/helm-monitor
ENTRYPOINT ["helm"]
105 changes: 0 additions & 105 deletions Gopkg.lock

This file was deleted.

34 changes: 0 additions & 34 deletions Gopkg.toml

This file was deleted.

32 changes: 22 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,30 @@ VERSION := $(shell sed -n -e 's/version:[ "]*\([^"]*\).*/\1/p' plugin.yaml)
DIST := $(CURDIR)/_dist
LDFLAGS := "-X main.version=${VERSION}"
BINARY := "helm-monitor"
DOCKER_IMAGE ?= containersol/helm-monitor
DOCKER_TAG ?= latest

.PHONY: dist release build install test lint vet dep
# go mod ftw
unexport GOPATH
GO111MODULE = on

install: dep build
.PHONY: install
install: build
cp $(BINARY) $(HELM_PLUGIN_DIR)
cp plugin.yaml $(HELM_PLUGIN_DIR)

.PHONY: build
build:
go build -o $(BINARY) -ldflags $(LDFLAGS) ./cmd/...

.PHONY: build.docker
build.docker:
docker build \
--build-arg LDFLAGS=$(LDFLAGS) \
--cache-from ${DOCKER_IMAGE} \
-t ${DOCKER_IMAGE}:$(DOCKER_TAG) .

.PHONY: dist
dist:
mkdir -p $(DIST)
GOOS=linux GOARCH=amd64 go build -o $(BINARY) -ldflags $(LDFLAGS) ./cmd/...
Expand All @@ -23,20 +37,18 @@ dist:
GOOS=windows GOARCH=amd64 go build -o $(BINARY).exe -ldflags $(LDFLAGS) ./cmd/...
tar -zcvf $(DIST)/helm-monitor_windows_$(VERSION).tar.gz $(BINARY).exe README.md LICENSE plugin.yaml

.PHONY: test-all
test-all: vet lint test

.PHONY: test
test:
go test -v -parallel=4 ./cmd/...

.PHONY: lint
lint:
@go get github.com/golang/lint/golint
go list ./cmd/... | grep -v vendor | xargs -n1 golint
@go get -u golang.org/x/lint/golint
go list ./cmd/... | xargs -n1 $${HOME}/go/bin/golint

.PHONY: vet
vet:
go vet ./cmd/...

dep:
ifndef HAS_DEP
go get -u github.com/golang/dep/cmd/dep
endif
dep ensure
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,28 @@ $ helm monitor elasticsearch --elasticsearch=http://elasticsearch:9200 \
'status:500 AND kubernetes.labels.app:app AND version:2.0.0'
```

## Development
## Docker

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

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

Install dependencies using [dep](https://github.com/golang/dep):

```bash
$ dep ensure
```
## Development

Build:
Require Go >= 1.11.

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

Run:
# Build:
$ GOPATH="" GO111MODULE=on go build -o helm-monitor ./cmd/...

```bash
# Run:
$ helm monitor elasticsearch my-release ./examples/elasticsearch-query.json
```

Expand Down
46 changes: 26 additions & 20 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
.PHONY: installtiller
installtiller:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.9/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/cluster-roles.yaml --validate=false
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
kubectl create serviceaccount tiller --namespace kube-system || true
kubectl create clusterrolebinding tiller \
--clusterrole=cluster-admin \
--serviceaccount=kube-system:tiller || true
helm init --upgrade --service-account tiller
PROMETHEUS_VERSION=7.0.2

.PHONY: prepare
prepare:
.PHONY: build
build:
eval $$(minikube docker-env) && \
docker build --build-arg "VERSION=1.0.0" -t app:1.0.0 app && \
docker build --build-arg "VERSION=2.0.0" -t app:2.0.0 app
docker build \
-v $${HOME}/go:/root/go \
--build-arg "LDFLAGS=-X main.version=1.0.0" \
-t my-app:1.0.0 \
app && \
docker build \
-v $${HOME}/go:/root/go \
--build-arg "LDFLAGS=-X main.version=2.0.0" \
-t my-app:2.0.0 \
app

.PHONY: deployv1
deployv1:
helm upgrade --install my-release ./app/charts --set image.tag=1.0.0
helm upgrade -i my-app --set image.tag=1.0.0 ./app/charts

.PHONY: deployv2
deployv2:
helm upgrade my-release ./app/charts --set image.tag=2.0.0
helm upgrade -i my-app --set image.tag=2.0.0 ./app/charts

.PHONY: installprometheus
installprometheus:
helm repo add coreos https://s3-eu-west-1.amazonaws.com/coreos-charts/stable/
helm upgrade --install prometheus-operator coreos/prometheus-operator
kubectl apply -f ./prometheus.yaml
helm upgrade -i \
--version $(PROMETHEUS_VERSION) \
--set server.service.type=LoadBalancer \
--set server.global.scrape_interval=30s \
--set alertmanager.enabled=false \
--set kubeStateMetrics.enabled=false \
--set nodeExporter.enabled=false \
--set pushgateway.enabled=false \
prometheus \
stable/prometheus

.PHONY: cleanup
kubectl delete -f ./prometheus.yaml
helm del --purge prometheus-operator my-release
helm del --purge prometheus my-app
Loading

0 comments on commit 4df71fb

Please sign in to comment.