|
1 | | - |
2 | | -# Image URL to use all building/pushing image targets |
3 | | -CONTROLLER_IMG ?= ibmcloud-cluster-api-controller |
4 | | -CLUSTERCTL_IMG ?= ibmcloud-cluster-api-clusterctl |
5 | | -VERSION ?= $(shell git describe --exact-match 2> /dev/null || \ |
6 | | - git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8) |
7 | | -REGISTRY ?= k8scloudprovider |
8 | | - |
| 1 | +GIT_HOST = sigs.k8s.io |
9 | 2 | PWD := $(shell pwd) |
10 | 3 | BASE_DIR := $(shell basename $(PWD)) |
11 | 4 | # Keep an existing GOPATH, make a private one if it is undefined |
12 | 5 | GOPATH_DEFAULT := $(PWD)/.go |
13 | 6 | export GOPATH ?= $(GOPATH_DEFAULT) |
14 | 7 | GOBIN_DEFAULT := $(GOPATH)/bin |
15 | 8 | export GOBIN ?= $(GOBIN_DEFAULT) |
16 | | - |
17 | | -# goang dep tools |
18 | | -DEP = github.com/golang/dep/cmd/dep |
19 | | -DEP_CHECK := $(shell command -v dep 2> /dev/null) |
| 9 | +TESTARGS_DEFAULT := "-v" |
| 10 | +export TESTARGS ?= $(TESTARGS_DEFAULT) |
| 11 | +PKG := $(shell awk -F "\"" '/^ignored = / { print $$2 }' Gopkg.toml) |
| 12 | +DEST := $(GOPATH)/src/$(GIT_HOST)/$(BASE_DIR) |
| 13 | +SOURCES := $(shell find $(DEST) -name '*.go') |
20 | 14 |
|
21 | 15 | HAS_DEP := $(shell command -v dep;) |
| 16 | +HAS_LINT := $(shell command -v golint;) |
22 | 17 | HAS_KUSTOMIZE := $(shell command -v kustomize;) |
| 18 | +GOX_PARALLEL ?= 3 |
| 19 | +TARGETS ?= darwin/amd64 linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le |
| 20 | +DIST_DIRS = find * -type d -exec |
23 | 21 |
|
24 | 22 | GENERATE_YAML_PATH=cmd/clusterctl/examples/ibmcloud |
25 | 23 | GENERATE_YAML_EXEC=generate-yaml.sh |
26 | 24 | GENERATE_YAML_TEST_FOLDER=dummy-make-auto-test |
27 | 25 |
|
28 | | -all: test manager |
| 26 | +GOOS ?= $(shell go env GOOS) |
| 27 | +VERSION ?= $(shell git describe --exact-match 2> /dev/null || \ |
| 28 | + git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8) |
| 29 | +GOFLAGS := |
| 30 | +TAGS := |
| 31 | +LDFLAGS := "-w -s -X 'main.version=${VERSION}'" |
29 | 32 |
|
30 | | -# Run tests |
31 | | -test: depend generate fmt vet manifests generate_yaml_test |
32 | | - go test ./pkg/... ./cmd/... -coverprofile cover.out |
| 33 | +# Image URL to use all building/pushing image targets |
| 34 | +CONTROLLER_IMG ?= ibmcloud-cluster-api-controller |
| 35 | +CLUSTERCTL_IMG ?= ibmcloud-cluster-api-clusterctl |
| 36 | +VERSION ?= $(shell git describe --exact-match 2> /dev/null || \ |
| 37 | + git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8) |
| 38 | +REGISTRY ?= k8scloudprovider |
33 | 39 |
|
| 40 | +ifneq ("$(realpath $(DEST))", "$(realpath $(PWD))") |
| 41 | + $(error Please run 'make' from $(DEST). Current directory is $(PWD)) |
| 42 | +endif |
34 | 43 |
|
35 | | -# Build manager binary |
36 | | -build: manager clusterctl |
| 44 | +all: test build images |
37 | 45 |
|
38 | | -manager: generate fmt vet |
39 | | - go build -o bin/manager cmd/manager/main.go |
| 46 | +############################################################ |
| 47 | +# depend section |
| 48 | +############################################################ |
| 49 | +$(GOBIN): |
| 50 | + echo "create gobin" |
| 51 | + mkdir -p $(GOBIN) |
40 | 52 |
|
41 | | -clusterctl: |
42 | | - go build -o bin/clusterctl cmd/clusterctl/main.go |
| 53 | +work: $(GOBIN) |
43 | 54 |
|
44 | | -# Run against the configured Kubernetes cluster in ~/.kube/config |
45 | | -run: depend generate fmt vet |
46 | | - go run ./cmd/manager/main.go |
| 55 | +depend: work |
| 56 | +ifndef HAS_DEP |
| 57 | + curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh |
| 58 | +endif |
| 59 | + dep ensure |
47 | 60 |
|
48 | | -# Install CRDs into a cluster |
49 | | -install: manifests |
50 | | - kubectl apply -f config/crds |
| 61 | +depend-update: work |
| 62 | + dep ensure -update |
51 | 63 |
|
52 | | -# Deploy controller in the configured Kubernetes cluster in ~/.kube/config |
53 | | -deploy: manifests |
54 | | - cat provider-components.yaml | kubectl apply -f - |
| 64 | +############################################################ |
| 65 | +# generate section |
| 66 | +############################################################ |
| 67 | +generate: |
| 68 | +ifndef GOPATH |
| 69 | + $(error GOPATH not defined, please define GOPATH. Run "go help gopath" to learn more about GOPATH) |
| 70 | +endif |
| 71 | + go generate ./pkg/... ./cmd/... |
55 | 72 |
|
56 | | -# Generate manifests e.g. CRD, RBAC etc. |
57 | | -manifests: |
58 | | - go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go crd |
59 | | - kustomize build config/default/ > provider-components.yaml |
60 | | - echo "---" >> provider-components.yaml |
61 | | - kustomize build vendor/sigs.k8s.io/cluster-api/config/default/ >> provider-components.yaml |
| 73 | +############################################################ |
| 74 | +# check section |
| 75 | +############################################################ |
| 76 | +check: fmt vet lint |
62 | 77 |
|
63 | | -# Run go fmt against code |
64 | | -fmt: |
65 | | - go fmt ./pkg/... ./cmd/... |
| 78 | +fmt: depend generate |
| 79 | + hack/verify-gofmt.sh |
66 | 80 |
|
67 | | -# Run go vet against code |
68 | | -vet: |
69 | | - go vet ./pkg/... ./cmd/... |
| 81 | +lint: depend generate |
| 82 | +ifndef HAS_LINT |
| 83 | + go get -u golang.org/x/lint/golint |
| 84 | + echo "installing golint" |
| 85 | +endif |
| 86 | + hack/verify-golint.sh |
70 | 87 |
|
71 | | -generate_yaml_test: |
| 88 | +vet: depend generate |
| 89 | + go vet ./... |
| 90 | + |
| 91 | +############################################################ |
| 92 | +# test section |
| 93 | +############################################################ |
| 94 | +test: unit functional fmt vet generate_yaml_test |
72 | 95 |
|
| 96 | +unit: depend generate check |
| 97 | + go test -tags=unit $(shell go list ./...) $(TESTARGS) |
| 98 | + |
| 99 | +functional: |
| 100 | + @echo "$@ not yet implemented" |
| 101 | + |
| 102 | +# Generate manifests e.g. CRD, RBAC etc. |
| 103 | +generate_yaml_test: |
73 | 104 | ifndef HAS_KUSTOMIZE |
74 | 105 | # for now, higher version has some problem so we stick to 1.0.11 |
75 | 106 | wget https://github.com/kubernetes-sigs/kustomize/releases/download/v1.0.11/kustomize_1.0.11_linux_amd64 |
76 | 107 | mv kustomize_1.0.11_linux_amd64 /usr/local/bin/kustomize |
77 | 108 | chmod +x /usr/local/bin/kustomize |
78 | 109 | endif |
79 | | - |
80 | 110 | # Create a dummy file for test only |
81 | 111 | echo 'clouds' > cmd/clusterctl/examples/ibmcloud/dummy-clouds-test.yaml |
82 | 112 | $(GENERATE_YAML_PATH)/$(GENERATE_YAML_EXEC) -f dummy-clouds-test.yaml ubuntu $(GENERATE_YAML_TEST_FOLDER) |
83 | 113 | # the folder will be generated under same folder of $(GENERATE_YAML_PATH) |
84 | 114 | rm -fr $(GENERATE_YAML_PATH)/$(GENERATE_YAML_TEST_FOLDER) |
85 | 115 | rm -f cmd/clusterctl/examples/ibmcloud/dummy-clouds-test.yaml |
86 | 116 |
|
87 | | -# Generate code |
88 | | -generate: |
89 | | -ifndef GOPATH |
90 | | - $(error GOPATH not defined, please define GOPATH. Run "go help gopath" to learn more about GOPATH) |
91 | | -endif |
92 | | - go generate ./pkg/... ./cmd/... |
| 117 | +############################################################ |
| 118 | +# build section |
| 119 | +############################################################ |
| 120 | +build: manager clusterctl |
| 121 | + |
| 122 | +manager: depend generate check |
| 123 | + CGO_ENABLED=0 GOOS=$(GOOS) go build \ |
| 124 | + -ldflags $(LDFLAGS) \ |
| 125 | + -o bin/manager \ |
| 126 | + cmd/manager/main.go |
| 127 | + |
| 128 | +clusterctl: depend generate check |
| 129 | + CGO_ENABLED=0 GOOS=$(GOOS) go build \ |
| 130 | + -ldflags $(LDFLAGS) \ |
| 131 | + -o bin/clusterctl \ |
| 132 | + cmd/clusterctl/main.go |
| 133 | + |
| 134 | +############################################################ |
| 135 | +# deploy section |
| 136 | +############################################################ |
| 137 | +# Run against the configured Kubernetes cluster in ~/.kube/config |
| 138 | +run: depend generate check |
| 139 | + go run ./cmd/manager/main.go |
93 | 140 |
|
| 141 | +# Install CRDs into a cluster |
| 142 | +install: generate_yaml_test |
| 143 | + kubectl apply -f config/crds |
| 144 | + |
| 145 | +# Deploy controller in the configured Kubernetes cluster in ~/.kube/config |
| 146 | +deploy: generate_yaml_test |
| 147 | + cat provider-components.yaml | kubectl apply -f - |
| 148 | + |
| 149 | +############################################################ |
| 150 | +# images section |
| 151 | +############################################################ |
94 | 152 | # Build the docker image |
95 | | -docker-build: test |
| 153 | +build-images: test |
96 | 154 | docker build . -f cmd/manager/Dockerfile -t $(REGISTRY)/$(CONTROLLER_IMG):$(VERSION) |
97 | 155 | docker build . -f cmd/clusterctl/Dockerfile -t $(REGISTRY)/$(CLUSTERCTL_IMG):$(VERSION) |
98 | 156 |
|
99 | 157 | # Push the docker image |
100 | | -docker-push: |
| 158 | +push-images: |
| 159 | + @echo "push images to $(REGISTRY)" |
101 | 160 | docker push $(REGISTRY)/$(CONTROLLER_IMG):$(VERSION) |
102 | 161 | docker push $(REGISTRY)/$(CLUSTERCTL_IMG):$(VERSION) |
103 | 162 |
|
104 | | -quick-image: |
| 163 | +build-push-images: |
105 | 164 | docker build . -f cmd/manager/Dockerfile -t $(REGISTRY)/$(CONTROLLER_IMG):$(VERSION) |
106 | 165 | docker push $(REGISTRY)/$(CONTROLLER_IMG):$(VERSION) |
107 | 166 | docker build . -f cmd/clusterctl/Dockerfile -t $(REGISTRY)/$(CLUSTERCTL_IMG):$(VERSION) |
108 | 167 | docker push $(REGISTRY)/$(CLUSTERCTL_IMG):$(VERSION) |
109 | 168 |
|
110 | | -$(GOBIN): |
111 | | - echo "create gobin" |
112 | | - mkdir -p $(GOBIN) |
113 | | - |
114 | | -work: $(GOBIN) |
115 | | - |
116 | | -depend: work |
117 | | -ifndef HAS_DEP |
118 | | - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh |
119 | | -endif |
120 | | - dep ensure |
121 | | - |
| 169 | +############################################################ |
| 170 | +# clean section |
| 171 | +############################################################ |
122 | 172 | clean: |
123 | 173 | rm -f bin/manager bin/clusterctl |
| 174 | + |
| 175 | +realclean: clean |
| 176 | + rm -rf vendor |
| 177 | + if [ "$(GOPATH)" = "$(GOPATH_DEFAULT)" ]; then \ |
| 178 | + rm -rf $(GOPATH); \ |
| 179 | + fi |
0 commit comments