-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
177 lines (136 loc) · 5.18 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
SHELL=/usr/bin/env bash -o pipefail
# Image URL to use all building/pushing image targets
REPO ?= "matrixorigin/matrixone-operator"
TAG ?= "latest"
GOPROXY ?= "https://proxy.golang.org,direct"
MO_VERSION ?= "nightly-d98832bb"
MO_IMAGE_REPO ?= "matrixorigin/matrixone"
BRANCH ?= main
ENVTEST_K8S_VERSION = 1.24.1
# 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
all: build
.PHONY: build
# Build operator image
build: generate manifests pkg
docker build -f Dockerfile . -t ${REPO}:${TAG} --build-arg GOPROXY=$(GOPROXY)
# Push operator image
push:
docker push ${IMG}
# Build manager binary
manager: generate fmt vet
CGO_ENABLED=0 go build -o manager cmd/operator/main.go
## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
.PHONY: manifests
manifests:
cd api && make manifests
## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
.PHONY: generate
generate:
cd api && make generate
.PHONY: docs
docs:
cd api && make docs
.PHONY: mockgen
generate-mockgen: mockgen ## General gomock(https://github.com/golang/mock) files
$(MOCKGEN) -source=./runtime/pkg/reconciler/event.go -package fake > ./runtime/pkg/fake/event.go
# helm package
helm-pkg: manifests generate helm-lint
helm dependency build charts/matrixone-operator
helm package -u charts/matrixone-operator -d charts/
# Make sure the generated files are up to date before open PR
reviewable: ci-reviewable go-lint check-license test
ci-reviewable: generate manifests docs test
go mod tidy
# Check whether the pull request is reviewable in CI, go-lint is delibrately excluded since we already have golangci-lint action
verify: ci-reviewable
echo "checking that branch is clean"
test -z "$$(git status --porcelain)" || (echo "unclean working tree, did you forget to run make reviewable?" && exit 1)
echo "branch is clean"
# Run go fmt against code
fmt:
go fmt ./...
# Run go vet against code
vet:
go vet ./...
# helm lint
helm-lint:
helm lint charts/matrixone-operator
# golangci-lint
go-lint: golangci-lint
$(GOLANGCI_LINT) run
# license check
check-license: license-eye
$(LICENSE_EYE) -v info -c .licenserc.yml header check
LOCALBIN ?= $(shell pwd)/api/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
ENVTEST ?= $(LOCALBIN)/setup-envtest
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
# TODO: include E2E
test: api-test unit
# Run unit tests
unit: generate fmt vet manifests envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" CGO_ENABLED=0 go test ./pkg/... -coverprofile cover.out
api-test:
cd api && make test
# Run kind e2e tests
e2e-kind: ginkgo
REPO=${REPO} TAG=${TAG} MO_IMAGE_REPO=$(MO_IMAGE_REPO) MO_VERSION=$(MO_VERSION) GINKGO=$(GINKGO) ./hack/kind-e2e.sh
# Launch a kind cluster and install mo operator
up:
REPO=${REPO} TAG=${TAG} MO_IMAGE_REPO=$(MO_IMAGE_REPO) MO_VERSION=$(MO_VERSION) ./hack/kind.sh up
# Run e2e tests
# KUBECONFIG is your kubernetes config path, OP_IMAGE_TAG is operator image tag
# export KUBECONFIG=<KUBECONFIG PATH> OP_IMAGE_TAG="sha-c1a16ce"
e2e: ginkgo
REPO=${REPO} TAG=${TAG} MO_IMAGE_REPO=$(MO_IMAGE_REPO) MO_VERSION=$(MO_VERSION) GINKGO=$(GINKGO) ./hack/e2e.sh
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests install
CGO_ENABLED=0 go run cmd/operator/main.go
# Install CRDs into a cluster
install: manifests
kubectl apply -f deploy/crds
# Uninstall CRDs from a cluster
uninstall: manifests
kubectl delete -f deploy/crds
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: install manifests
kubectl apply -f deploy/service_account.yaml
# Destroy Controller the configured Kubernetes cluster in ~/.kube/config
undeploy: uninstall manifests
kustomize build deploy/ | kubectl delete -f -
# Build playground image
build-pgd:
docker build -f playground/Dockerfile . -t matrixorigin/operator-playground:latest
# Run playground container
run-pgd: build-pgd
docker run --privileged --name playground -p 6001:6001 --rm -it matrixorigin/operator-playground:latest
GINKGO = $(shell pwd)/bin/ginkgo
ginkgo:
$(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo@v2.9.2)
MOCKGEN = $(shell pwd)/bin/mockgen
mockgen: ## Download mockgen locally if necessary
$(call go-get-tool,$(MOCKGEN),github.com/golang/mock/mockgen@v1.6.0)
LICENSE_EYE = $(shell pwd)/bin/license-eye
license-eye: ## Download license-eye locally if necessary
$(call go-get-tool,$(LICENSE_EYE),github.com/apache/skywalking-eyes/cmd/license-eye@v0.4.0)
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
golangci-lint:
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2)
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2); \
}
endef