diff --git a/Makefile b/Makefile index ab31e4562..42e644e1e 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,12 @@ .PHONY: clean local linux macos docker push scm-source.json +ifeq ($(RACE),1) + GOFLAGS=-race +endif + BINARY ?= postgres-operator -BUILD_FLAGS ?= -i +BUILD_FLAGS ?= -i -v +LDFLAGS ?= -X=main.version=$(VERSION) DOCKERFILE = docker/Dockerfile IMAGE ?= pierone.example.com/acid/$(BINARY) TAG ?= $(VERSION) @@ -11,6 +16,8 @@ GITSTATUS = $(shell git status --porcelain || echo "no changes") SOURCES = cmd/main.go VERSION ?= $(shell git describe --tags --always --dirty) IMAGE ?= pierone.example.com/acid/$(BINARY) +DIRS := cmd pkg +PKG := `go list ./... | grep -v /vendor/` default: local @@ -22,13 +29,13 @@ linux: build/linux/${BINARY} macos: build/macos/${BINARY} build/${BINARY}: ${SOURCES} - go build -o $@ $(BUILD_FLAGS) $^ + go build -o $@ $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" $^ build/linux/${BINARY}: ${SOURCES} - GOOS=linux GOARCH=amd64 go build -o $@ ${BUILD_FLAGS} $^ + GOOS=linux GOARCH=amd64 go build -o $@ ${BUILD_FLAGS} -ldflags "$(LDFLAGS)" $^ build/macos/${BINARY}: ${SOURCES} - GOOS=darwin GOARCH=amd64 go build -o $@ ${BUILD_FLAGS} $^ + GOOS=darwin GOARCH=amd64 go build -o $@ ${BUILD_FLAGS} -ldflags "$(LDFLAGS)" $^ docker-context: scm-source.json linux mkdir -p docker/build/ @@ -43,3 +50,16 @@ push: scm-source.json: .git echo '{\n "url": "$(GITURL)",\n "revision": "$(GITHEAD)",\n "author": "$(USER)",\n "status": "$(GITSTATUS)"\n}' > scm-source.json +tools: + @go get -u honnef.co/go/staticcheck/cmd/staticcheck + @go get -u github.com/Masterminds/glide + +fmt: + @gofmt -l -w -s $(DIRS) + +vet: + @go vet $(PKG) + @$(GOPATH)/bin/staticcheck $(PKG) + +deps: + @$(GOPATH)/bin/glide install \ No newline at end of file diff --git a/README.md b/README.md index 19e748bdf..f2e23157a 100644 --- a/README.md +++ b/README.md @@ -13,27 +13,25 @@ $ export GOPATH=~/git/go $ mkdir -p ${GOPATH}/src/github.bus.zalan.do/acid/ $ cd ${GOPATH}/src/github.bus.zalan.do/acid/ && git clone https://github.bus.zalan.do/acid/postgres-operator -b prototype - -### Install Glide on OS X - $ brew install glide +### Install Glide and Staticcheck -### Install Glide on Ubuntu - - # sudo add-apt-repository ppa:masterminds/glide && sudo apt-get update - # sudo apt-get install glide + $ make tools ### Install dependencies with Glide - $ glide update && glide install + $ make deps ### Build dependencies $ go build -i -v cmd -### Run operator (outside kubernetes cluster) - - $ go run cmd/main.go +## Run operator (as a pod) + + $ docker build -t postgres-operator:0.1 . + $ kubectl create -f postgres-operator.yaml + + If you are building docker image by yourself on OS X make sure postgres-operator is compiled with GOOS=linux flag ### Check if ThirdPartyResource has been registered @@ -45,7 +43,7 @@ ### Create a new spilo cluster - $ kubectl create -f testcluster.yaml + $ kubectl create -f manifests/testspilo.yaml ### Watch Pods being created diff --git a/build-ci.sh b/build-ci.sh index 6ca08fbaf..7c9194daf 100755 --- a/build-ci.sh +++ b/build-ci.sh @@ -9,5 +9,4 @@ mkdir -p "$team_repo" ln -s "$PWD" "$project_dir" cd "$project_dir" -glide install -make clean docker push +make deps clean docker push diff --git a/cmd/main.go b/cmd/main.go index 4ed0e4a4e..3e11a2ad4 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -13,6 +13,7 @@ import ( ) var options controller.Options +var version string func init() { pflag.StringVar(&options.KubeConfig, "kubeconfig", "", "Path to kubeconfig file with authorization and master location information.") @@ -22,6 +23,7 @@ func init() { func main() { // Set logging output to standard console out log.SetOutput(os.Stdout) + log.Printf("Spilo operator %s\n", version) pflag.CommandLine.AddGoFlagSet(flag.CommandLine) pflag.Parse() @@ -32,8 +34,8 @@ func main() { wg := &sync.WaitGroup{} // Goroutines can add themselves to this to be waited on - spiloOperator := controller.New(options) - spiloOperator.Run(stop, wg) + c := controller.New(options) + c.Run(stop, wg) sig := <-sigs // Wait for signals (this hangs until a signal arrives) log.Printf("Shutting down... %+v", sig) diff --git a/docker/Dockerfile b/docker/Dockerfile index 64a488163..c55a82abd 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -3,4 +3,4 @@ MAINTAINER Team ACID @ Zalando COPY build/* / -ENTRYPOINT ["/postres-operator"] +ENTRYPOINT ["/postgres-operator"] diff --git a/glide.lock b/glide.lock index 7083f22ea..c39d79bac 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: c45b505f8cf3c9b967a7244e0a675ae11c158d0168496bed18a43270e2cebfe9 -updated: 2017-01-09T11:28:31.075588565+01:00 +hash: 19831a9408f172d009617c781ea65141606a216aa8e238797e102c511f4afb1f +updated: 2017-01-27T13:24:40.647376238+01:00 imports: - name: cloud.google.com/go version: 3b1ae45394a234c385be014e9a488f2bb6eef821 @@ -9,7 +9,7 @@ imports: - name: github.com/blang/semver version: 31b736133b98f26d5e078ec9eb591666edfd091f - name: github.com/coreos/etcd - version: 3d5ba43211beec7fbb1472634a9c3b464581658a + version: 8ba2897a21e4fc51b298ca553d251318425f93ae subpackages: - client - pkg/pathutil @@ -25,7 +25,6 @@ imports: - name: github.com/coreos/pkg version: fa29b1d70f0beaddd4c7021607cc3c3be8ce94b8 subpackages: - - capnslog - health - httputil - timeutil @@ -54,16 +53,15 @@ imports: - name: github.com/go-openapi/swag version: 1d0bd113de87027671077d3c71eb3ac5d7dbba72 - name: github.com/gogo/protobuf - version: 8d70fb3182befc465c4a1eac8ad4d38ff49778e2 + version: e18d7aa8f8c624c915db340349aad4c49b10d173 subpackages: - proto - sortkeys - name: github.com/golang/glog version: 44145f04b68cf362d9c4df2182967c2275eaefed - name: github.com/golang/protobuf - version: 4bd1920723d7b7c925de087aa32e2187708897f7 + version: 8616e8ee5e20a1704615e6c8d7afcdac06087a67 subpackages: - - jsonpb - proto - name: github.com/google/gofuzz version: bbcb9da2d746f8bdbd6a936686a0a6067ada0ec5 @@ -72,7 +70,7 @@ imports: - name: github.com/imdario/mergo version: 6633656539c1639d9d78127b7d47c622b5d7b6dc - name: github.com/jonboulle/clockwork - version: 2eee05ed794112d45db504eb05aa693efd2b8b09 + version: 72f9bd7c4e0c2a40055ab3d0f09654f730cce982 - name: github.com/mailru/easyjson version: d5b7844b561a7bc640052f1b935f7b800330d7e0 subpackages: @@ -92,19 +90,18 @@ imports: subpackages: - codec - name: golang.org/x/crypto - version: 1351f936d976c60a0a48d728281922cf63eafb8d + version: 1f22c0103821b9390939b6776727195525381532 subpackages: - - bcrypt - - blowfish - ssh/terminal - name: golang.org/x/net - version: 6acef71eb69611914f7a30939ea9f6e194c78172 + version: e90d6d0afc4c315a0d87a568ae68577cc15149a0 subpackages: - context - context/ctxhttp - http2 - http2/hpack - idna + - lex/httplex - name: golang.org/x/oauth2 version: 3c3a985cb79f52a3190fbc056984415ca6763d01 subpackages: diff --git a/postgres-operator.yaml b/manifests/postgres-operator.yaml similarity index 100% rename from postgres-operator.yaml rename to manifests/postgres-operator.yaml diff --git a/testcluster.yaml b/manifests/testspilo.yaml similarity index 100% rename from testcluster.yaml rename to manifests/testspilo.yaml diff --git a/pkg/controller/spilo.go b/pkg/controller/spilo.go index bd61820a2..8523c33b3 100644 --- a/pkg/controller/spilo.go +++ b/pkg/controller/spilo.go @@ -67,8 +67,6 @@ func New(options Options) *SpiloOperator { } func (o *SpiloOperator) Run(stopCh <-chan struct{}, wg *sync.WaitGroup) { - log.Printf("Spilo operator %v\n", VERSION) - go o.Controller.Run(stopCh, wg) log.Println("Started working in background")