-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
123 lines (104 loc) · 3.15 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
# Path to Docker binary
DOCKER ?= docker
# Docker image name
IMAGE ?= tsuru/nginx-operator
# Docker image revision
TAG ?= ${VERSION}
KUBECTL ?= kubectl
# 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
VERSION ?= main
GIT_COMMIT ?= $(shell git rev-list -1 HEAD)
GO_BUILD_FLAGS = GO111MODULE=on CGO_ENABLED=0
GO_LDFLAGS = "-X=github.com/tsuru/nginx-operator/version.Version=$(VERSION) -X=github.com/tsuru/nginx-operator/version.GitCommit=$(GIT_COMMIT)"
.PHONY: test
test: generate
go test -race -cover ./...
.PHONY: lint
lint: golangci-lint
$(GOLANGCI_LINT) run -c .golangci.yml ./...
.PHONY: build
build: manager
.PHONY: manager
manager: generate
${GO_BUILD_FLAGS} go build -ldflags $(GO_LDFLAGS) -o bin/nginx-operator main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
.PHONY: run
run: generate manifests
go run ./main.go --enable-leader-election=false
# 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
$(KUSTOMIZE) build config/crd | kubectl delete -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: deploy
deploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMAGE):$(TAG)
$(KUBECTL) apply -k config/default
# Build the docker image
.PHONY: docker-build
docker-build:
$(DOCKER) build --build-arg VERSION=${VERSION} --build-arg GIT_COMMIT=${GIT_COMMIT} . -t $(IMAGE):$(TAG)
# Push the docker image
.PHONY: docker-push
docker-push:
$(DOCKER) push $(IMAGE):$(TAG)
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests: controller-gen
$(CONTROLLER_GEN) rbac:roleName=role crd paths=./... output:crd:artifacts:config=config/crd/bases
# Generate code (zz_generated.deepcopy.go files)
.PHONY: generate
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# 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.7.0 ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
# find or download kustomize
# download kustomize if necessary
.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