-
Notifications
You must be signed in to change notification settings - Fork 40
/
Makefile
145 lines (118 loc) · 3.67 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
export GO111MODULE=on
CONTROLLER_GEN_VERSION := v0.4.1
GO_MIN_VERSION := 12000 # go1.20
define generate_int_from_semver
echo $(1) |cut -dv -f2 |awk '{split($$0,a,"."); print a[3]+(100*a[2])+(10000* a[1])}'
endef
CONTROLLER_GEN_VERSION_CHECK = \
$(shell expr \
$(shell $(call generate_int_from_semver,$(shell $(CONTROLLER_GEN) --version | awk '{print $$2}' | cut -dv -f2))) \
\>= $(shell $(call generate_int_from_semver,$(shell echo $(CONTROLLER_GEN_VERSION) | cut -dv -f2))) \
)
GO_VERSION_CHECK := \
$(shell expr \
$(shell go version | \
awk '{print $$3}' | \
cut -do -f2 | \
sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/' \
) \>= $(GO_MIN_VERSION) \
)
# Default Go linker flags.
GO_LDFLAGS ?= -ldflags="-s -w"
# Image URL to use all building/pushing image targets
IMG ?= instance-manager:latest
INSTANCEMGR_TAG ?= latest
.PHONY: all
all: check-go test clean manager
# Run tests
.PHONY: test
test: generate fmt vet manifests
go test ./controllers/... ./api/... -coverprofile coverage.txt
.PHONY: bdd
bdd:
go test -timeout 60m -v ./test-bdd/ --godog.stop-on-failure
.PHONY: wip
wip:
go test -timeout 60m -v ./test-bdd/ --godog.tags "@wip"
.PHONY: coverage
coverage:
go test -coverprofile coverage.txt -v ./controllers/...
go tool cover -html=coverage.txt -o coverage.html
# Build manager binary
.PHONY: manager
manager: generate fmt vet
go build -o bin/manager main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
.PHONY: run
run: generate fmt vet
go run ./main.go
# Install CRDs into a cluster
.PHONY: install
install: manifests
kubectl apply -f config/rbac/service_account.yaml
kubectl auth reconcile -f config/rbac/role.yaml
kubectl auth reconcile -f config/rbac/strategy_role.yaml
kubectl auth reconcile -f config/rbac/role_binding.yaml
kubectl auth reconcile -f config/rbac/strategy_role_binding.yaml
kubectl apply -f config/crd/bases
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: deploy
deploy: manifests
kubectl apply -f config/crd/bases
kustomize build config/default | kubectl apply -f -
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests: controller-gen
$(CONTROLLER_GEN) rbac:roleName=instance-manager crd webhook paths="./api/...;./controllers/..." 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
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/...
# Build the docker image
.PHONY: docker-build
docker-build:
docker build . -t ${IMG}
# Push the docker image
.PHONY: docker-push
docker-push:
docker push ${IMG}
.PHONY: check-controller-gen
check-controller-gen:
@if [ $(CONTROLLER_GEN_VERSION_CHECK) -eq 0 ]; then \
echo "Need to upgrade controller-gen to $(CONTROLLER_GEN_VERSION) or higher"; \
exit 1; \
fi
# find or download controller-gen
# download controller-gen if necessary
.PHONY: controller-gen
controller-gen: controller-gen-find check-controller-gen
.PHONY: controller-gen-real
controller-gen-find:
ifeq (, $(shell which controller-gen))
go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)
CONTROLLER_GEN=$(shell go env GOPATH)/bin/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
.PHONY: check-go
check-go:
ifeq ($(GO_VERSION_CHECK),0)
$(error go 1.20 or higher is required)
endif
.PHONY: lint
lint: check-go
@echo "golint $(LINTARGS)"
@for pkg in $(shell go list ./...) ; do \
golint $(LINTARGS) $$pkg ; \
done
.PHONY: clean
clean:
@rm -rf ./bin