-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
131 lines (107 loc) · 3.51 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
IMG ?= softonic/rate-limit-operator:1.1.0
CRD_OPTIONS ?= "crd:trivialVersions=true"
BIN := rate-limit-operator
PKG := github.com/softonic/rate-limit-operator
VERSION ?= 1.1.0
ARCH ?= amd64
APP ?= rate-limit-operator
NAMESPACE ?= rate-limit-operator-system
RELEASE_NAME ?= rate-limit-operator
REPOSITORY ?= softonic/rate-limit-operator
IMAGE := $(BIN)
BUILD_IMAGE ?= golang:1.14-buster
# 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: manager
.PHONY: all
all: dev
.PHONY: build
build: generate
go mod download
GOARCH=${ARCH} go build -ldflags "-X ${PKG}/pkg/version.Version=${VERSION}" .
.PHONY: image
image:
docker build -t $(IMG) -f Dockerfile .
docker tag $(IMG) $(REPOSITORY):latest
.PHONY: docker-push
docker-push:
docker push $(IMG)
docker push $(REPOSITORY):latest
.PHONY: make-manifest
make-manifest: controller-gen manifests
docker run --rm -v $(PWD):/app -w /app/ alpine/helm:3.2.3 template --release-name $(RELEASE_NAME) --set "image.tag=$(VERSION)" --set "image.repository=$(REPOSITORY)" -f chart/rate-limit-operator/values.yaml chart/rate-limit-operator > manifest.yaml
.PHONY: undeploy
undeploy:
kubectl delete -f manifest.yaml || true
.PHONY: deploy
deploy: make-manifest
kubectl apply -f manifest.yaml
.PHONY: helm-deploy
helm-deploy: install-crd
helm upgrade --install $(RELEASE_NAME) --namespace $(NAMESPACE) --create-namespace --set "image.tag=$(VERSION)" -f chart/rate-limit-operator/values.yaml chart/rate-limit-operator
.PHONY: install-crd
install-crd:
cp config/crd/bases/networking.softonic.io_ratelimits.yaml chart/rate-limit-operator/crds/networking.softonic.io_ratelimits.yaml
# Run tests
.PHONY: test
test: generate fmt vet manifests
go test ./... -coverprofile cover.out
# 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 manifests
go run ./main.go
# Install CRDs into a cluster
.PHONY: install
install: manifests
kustomize build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
.PHONY: uninstall
uninstall: manifests
kustomize build config/crd | kubectl delete -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: deploy
deploy: manifests
cd config/manager && kustomize edit set image controller=${IMG}
kustomize build config/default | kubectl apply -f -
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests: controller-gen
# $(CONTROLLER_GEN) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook 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
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 ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.0 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif