-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile
179 lines (146 loc) · 4.85 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
DOCKER ?= docker
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
GO_BUILD_DIR ?= ./bin
all: test build
# Run tests
.PHONY: test
test: fmt vet lint
go test -race -coverprofile cover.out ./...
.PHONY: lint
lint: golangci-lint
$(GOLANGCI_LINT) run ./...
.PHONY: build
build: build/api build/manager build/plugin/rpaasv2 build/purger
.PHONY: build/api
build/api: build-dirs
CGO_ENABLED=0 go build -o $(GO_BUILD_DIR)/ ./cmd/api
.PHONY: build/manager
build/manager: manager
.PHONY: build/plugin/rpaasv2
build/plugin/rpaasv2: build-dirs
go build -o $(GO_BUILD_DIR)/ ./cmd/plugin/rpaasv2
.PHONY: build/purger
build/purger: build-dirs
CGO_ENABLED=0 go build -o $(GO_BUILD_DIR)/ ./cmd/purger
.PHONY: build-dirs
build-dirs:
@mkdir -p $(GO_BUILD_DIR)
# Build manager binary
.PHONY: manager
manager: generate fmt vet build-dirs
go build -o $(GO_BUILD_DIR)/manager ./main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
.PHONY: run
run: generate fmt vet manifests
go run main.go --health-probe-bind-address=0 --metrics-bind-address=0 --leader-elect=false
.PHONY: run/api
run/api:
go run ./cmd/api
# Install CRDs into a cluster
.PHONY: install
install: manifests kustomize
$(KUBECTL) apply -k config/crd
# Uninstall CRDs from a cluster
.PHONY: uninstall
uninstall: manifests kustomize
$(KUBECTL) delete -k config/crd
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: deploy
deploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUBECTL) apply -k config/default
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) crd rbac:roleName=manager-role paths="./..." output:crd:artifacts:config=config/crd/bases
# Run go fmt against code
.PHONY: fmt
fmt:
go fmt ./...
# Run go vet against code
.PHONY: vet
vet:
go vet ./...
# Generate code
.PHONY: generate-cli
generate-cli: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
.PHONY: generate
generate: generate-cli manifests
# find or download controller-gen
# download controller-gen if necessary
.PHONY: controller-gen
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.15.0 ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
.PHONY: kustomize
kustomize:
ifeq (, $(shell which kustomize))
@{ \
set -e ;\
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif
# find or download golangci-lint
# download golangci-lint if necessary
.PHONY: golangci-lint
golangci-lint:
ifeq (, $(shell which golangci-lint))
@{ \
set -e ;\
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) ;\
}
GOLANGCI_LINT=$(GOBIN)/golangci-lint
else
GOLANGCI_LINT=$(shell which golangci-lint)
endif
#
# OpenAPI targets
#
OPENAPI_GENERATOR_IMAGE_CLI ?= openapitools/openapi-generator-cli
OPENAPI_GENERATOR_CLI_VERSION ?= v6.6.0
OPENAPI_SPEC_PATH = ./docs/openapi.yaml
OPENAPI_AUTOGENERATED_HTTP_CLIENT_DIR = ./pkg/rpaas/client/autogenerated
OPENAPI_AUTOGENERATED_PACKAGE_NAME = $(shell basename ${OPENAPI_AUTOGENERATED_HTTP_CLIENT_DIR})
.PHONY: openapi/generate-http-client
openapi/generate-http-client:
@ mkdir -p ${OPENAPI_AUTOGENERATED_HTTP_CLIENT_DIR}
@ echo "Cleaning up old autogenerated files in ${OPENAPI_AUTOGENERATED_HTTP_CLIENT_DIR} dir..."
@ find ${OPENAPI_AUTOGENERATED_HTTP_CLIENT_DIR} -type d -depth 1 ! -name '.openapi-generator' | xargs rm -rv
@ find ${OPENAPI_AUTOGENERATED_HTTP_CLIENT_DIR} -type f -depth 1 ! -name '.openapi-generator-ignore' | xargs rm -v
@ echo "Generating HTTP client written in Golang..."
@ ${DOCKER} run --rm \
-v ${OPENAPI_SPEC_PATH}:/mnt/openapi.yaml:ro \
-v ${OPENAPI_AUTOGENERATED_HTTP_CLIENT_DIR}:/mnt/autogenerated:rw \
${OPENAPI_GENERATOR_IMAGE_CLI}:${OPENAPI_GENERATOR_CLI_VERSION} \
generate -i /mnt/openapi.yaml -o /mnt/autogenerated -g go --package-name ${OPENAPI_AUTOGENERATED_PACKAGE_NAME} \
--global-property=apiDocs=false,apiTests=false,modelDocs=false,modelTests=false
gofmt -s -w ${OPENAPI_AUTOGENERATED_HTTP_CLIENT_DIR}
goimports -w ${OPENAPI_AUTOGENERATED_HTTP_CLIENT_DIR}
go mod tidy
.PHONY: openapi/validate-spec
openapi/validate-spec:
@ echo "Validating OpenAPI spec file at ${OPENAPI_SPEC_PATH}..."
@ ${DOCKER} run --rm \
-v ${OPENAPI_SPEC_PATH}:/mnt/openapi.yaml:ro \
${OPENAPI_GENERATOR_IMAGE_CLI}:${OPENAPI_GENERATOR_CLI_VERSION} \
validate -i /mnt/openapi.yaml