forked from banzaicloud/koperator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
144 lines (112 loc) · 4.31 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
# Image URL to use all building/pushing image targets
TAG ?= $(shell git describe --tags --abbrev=0 --match 'v[0-9].*[0-9].*[0-9]' 2>/dev/null )
IMG ?= banzaicloud/kafka-operator:$(TAG)
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
RELEASE_TYPE ?= p
RELEASE_MSG ?= "operator release"
REL_TAG = $(shell ./scripts/increment_version.sh -${RELEASE_TYPE} ${TAG})
GOLANGCI_VERSION = 1.21.0
LICENSEI_VERSION = 0.2.0
GOPROXY=https://proxy.golang.org
CONTROLLER_GEN_VERSION = v0.2.5
CONTROLLER_GEN = $(PWD)/bin/controller-gen
KUSTOMIZE_BASE = config/overlays/specific-manager-version
# 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
export PATH := $(PWD)/bin:$(PATH)
all: test manager
.PHONY: check
check: test lint ## Run tests and linters
bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION}
@ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint
bin/golangci-lint-${GOLANGCI_VERSION}:
@mkdir -p bin
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b ./bin v${GOLANGCI_VERSION}
@mv bin/golangci-lint $@
.PHONY: lint
lint: bin/golangci-lint ## Run linter
@bin/golangci-lint run -v
cd pkg/sdk && golangci-lint run -c ../../.golangci.yml
bin/licensei: bin/licensei-${LICENSEI_VERSION}
@ln -sf licensei-${LICENSEI_VERSION} bin/licensei
bin/licensei-${LICENSEI_VERSION}:
@mkdir -p bin
curl -sfL https://raw.githubusercontent.com/goph/licensei/master/install.sh | bash -s v${LICENSEI_VERSION}
@mv bin/licensei $@
.PHONY: license-check
license-check: bin/licensei ## Run license check
bin/licensei check
./scripts/check-header.sh
.PHONY: license-cache
license-cache: bin/licensei ## Generate license cache
bin/licensei cache
# Install kustomize
install-kustomize:
@ if ! which bin/kustomize &>/dev/null; then\
scripts/install_kustomize.sh;\
fi
# Install kubebuilder
install-kubebuilder:
@ if ! which bin/kubebuilder/bin/kubebuilder &>/dev/null; then\
scripts/install_kubebuilder.sh;\
fi
# Run tests
test: install-kubebuilder generate fmt vet manifests
cd pkg/sdk && go test ./...
KUBEBUILDER_ASSETS="$${PWD}/bin/kubebuilder/bin" go test ./... -coverprofile cover.out
# Build manager binary
manager: generate fmt vet
go build -o bin/manager main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
go run ./main.go
# Install CRDs into a cluster
install: manifests
kubectl apply -f config/base/crds
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: install-kustomize manifests
bin/kustomize build config | kubectl apply -f -
./scripts/image_patch.sh "${KUSTOMIZE_BASE}/manager_image_patch.yaml" ${IMG}
bin/kustomize build $(KUSTOMIZE_BASE) | kubectl apply -f -
# Generate manifests e.g. CRD, RBAC etc.
manifests: bin/controller-gen
cd pkg/sdk && $(CONTROLLER_GEN) $(CRD_OPTIONS) webhook paths="./..." output:crd:artifacts:config=../../config/base/crds output:webhook:artifacts:config=../../config/base/webhook
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role paths="./controllers/..." output:rbac:artifacts:config=./config/base/rbac
# Run go fmt against code
fmt:
go fmt ./...
cd pkg/sdk && go fmt ./...
# Run go vet against code
vet:
go vet ./...
cd pkg/sdk && go fmt ./...
# Generate code
generate: bin/controller-gen
cd pkg/sdk && $(CONTROLLER_GEN) object:headerFile=./../../hack/boilerplate.go.txt paths="./..."
# Build the docker image
docker-build:
docker build . -t ${IMG}
# Push the docker image
docker-push:
docker push ${IMG}
# find or download controller-gen
# download controller-gen if necessary
bin/controller-gen:
@ if ! test -x bin/controller-gen; then \
set -ex ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
GOBIN=$(PWD)/bin go get sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_GEN_VERSION} ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
fi
check_release:
@echo "A new tag (${REL_TAG}) will be pushed to Github, and a new Docker image will be released. Are you sure? [y/N] " && read ans && [ $${ans:-N} == y ]
release: check_release
git tag -a ${REL_TAG} -m ${RELEASE_MSG}
git push origin ${REL_TAG}