This repository has been archived by the owner on Oct 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
143 lines (112 loc) · 5.04 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
SOURCES_DIRS = cmd pkg
SOURCES_DIRS_GO = ./pkg/... ./cmd/...
SOURCES_API_DIR = ./pkg/apis/kubic
GO := GO111MODULE=on GO15VENDOREXPERIMENT=1 go
GO_NOMOD := GO111MODULE=off go
GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/')
GO_VERSION_MAJ := $(shell echo $(GO_VERSION) | cut -f1 -d'.')
GO_VERSION_MIN := $(shell echo $(GO_VERSION) | cut -f2 -d'.')
GO_BIN := $(shell [ -n "${GOBIN}" ] && echo ${GOBIN} || (echo `echo ${GOPATH} | cut -f1 -d':'`/bin))
DEEPCOPY_GENERATOR := $(GO_BIN)/deepcopy-gen
KUSTOMIZE := $(GO_BIN)/kustomize
# go source files, ignore vendor directory
REGS_OPER_SRCS = $(shell find $(SOURCES_DIRS) -type f -name '*.go' -not -path "*generated*")
REGS_OPER_MAIN_SRCS = $(shell find $(SOURCES_DIRS) -type f -name '*.go' -not -path "*_test.go")
REGS_OPER_GEN_SRCS = $(shell grep -l -r "//go:generate" $(SOURCES_DIRS) 2>/dev/null)
REGS_OPER_CRD_TYPES_SRCS = $(shell find $(SOURCES_API_DIR) -type f -name "*_types.go")
REGS_OPER_EXE = cmd/registries-operator/registries-operator
REGS_OPER_MAIN = cmd/registries-operator/main.go
.DEFAULT_GOAL: $(REGS_OPER_EXE)
# These will be provided to the target
REGS_OPER_VERSION := 1.0.0
REGS_OPER_BUILD := `git rev-parse HEAD 2>/dev/null`
# Use linker flags to provide version/build settings to the target
REGS_OPER_LDFLAGS = -ldflags "-X=main.Version=$(REGS_OPER_VERSION) -X=main.Build=$(REGS_OPER_BUILD)"
# the deployment manifest for the operator
REGS_DEPLOY = deployments/registries-operator-full.yaml
# the kubebuilder generator
CONTROLLER_GEN := sigs.k8s.io/controller-tools/cmd/controller-gen
#############################################################
# Build targets
#############################################################
all: $(REGS_OPER_EXE)
#
# NOTE: we are currently not using the RBAC rules generated by kubebuilder:
# we are just assigning the "cluster-admin" role to the manager (as we
# must generate ClusterRoles/ClusterRoleBindings)
# TODO: investigate if we can reduce these privileges...
#
#manifests-rbac:
# @echo ">>> Creating RBAC manifests..."
# @rm -rf config/rbac/*.yaml
# @$(GO) run ${CONTROLLER_GEN} rbac --name $(CONTROLLER_GEN_RBAC_NAME)
# Generate manifests e.g. CRD, RBAC etc.
manifests: $(REGS_DEPLOY)
#############################################################
# Analyze targets
#############################################################
.PHONY: fmt
fmt: $(REGS_OPER_SRCS)
@echo ">>> Reformatting code"
@$(GO) fmt $(SOURCES_DIRS_GO)
.PHONY: simplify
simplify:
@gofmt -s -l -w $(REGS_OPER_SRCS)
.PHONY: golint
golint:
-@$(GO_NOMOD) get -u golang.org/x/lint/golint
.PHONY: check
check: fmt golint
@for d in $$($(GO) list ./... | grep -v /vendor/); do golint -set_exit_status $${d}; done
@$(GO) tool vet ${REGS_OPER_SRCS}
.PHONY: test
test:
@$(GO) test -short -v $(SOURCES_DIRS_GO) -coverprofile cover.out
.PHONY: integration
integration: controller-gen
@$(GO) test -v $(SOURCES_DIRS_GO) -coverprofile cover.out
.PHONY: clean
clean: docker-image-clean
rm -f $(REGS_OPER_EXE) go.sum
# rm -rf `find . -name zz_generated.deepcopy.go` go.sum
#############################################################
# Support targets
#############################################################
$(KUSTOMIZE):
@echo ">>> Getting kustomize..."
-@$(GO_NOMOD) get -u sigs.k8s.io/kustomize
# NOTE: deepcopy-gen doesn't support go1.11's modules, so we must 'go get' it
$(DEEPCOPY_GENERATOR):
@[ -n "${GOPATH}" ] || ( echo "FATAL: GOPATH not defined" ; exit 1 ; )
@echo ">>> Getting deepcopy-gen (for $(DEEPCOPY_GENERATOR))"
-@$(GO_NOMOD) get -u k8s.io/code-generator/cmd/deepcopy-gen
-@$(GO_NOMOD) get -d -u k8s.io/apimachinery
generate: $(REGS_OPER_GEN_SRCS) $(DEEPCOPY_GENERATOR)
@echo ">>> Generating files..."
@$(GO) generate -x $(SOURCES_DIRS_GO)
$(REGS_OPER_EXE): $(REGS_OPER_MAIN_SRCS) go-version-check
@echo ">>> Building $(REGS_OPER_EXE)..."
$(GO) build $(REGS_OPER_LDFLAGS) -o $(REGS_OPER_EXE) $(REGS_OPER_MAIN)
controller-gen: $(REGS_OPER_CRD_TYPES_SRCS)
@echo ">>> Creating manifests..."
@$(GO) run $(CONTROLLER_GEN) all
$(REGS_DEPLOY): $(KUSTOMIZE) controller-gen
@echo ">>> Collecting all the manifests for generating $(REGS_DEPLOY)..."
@rm -f $(REGS_DEPLOY)
@echo "#" >> $(REGS_DEPLOY)
@echo "# DO NOT EDIT! Generated automatically with 'make $(REGS_DEPLOY)'" >> $(REGS_DEPLOY)
@echo "# from files in 'config/*'" >> $(REGS_DEPLOY)
@echo "#" >> $(REGS_DEPLOY)
@for i in $(shell find config/sas config/crds -name '*.yaml') ; do \
echo -e "\n---" >> $(REGS_DEPLOY) ; \
cat $$i >> $(REGS_DEPLOY) ; \
done
@echo -e "\n---" >> $(REGS_DEPLOY)
@kustomize build config/default >> $(REGS_DEPLOY)
#############################################################
# Other stuff
#############################################################
go-version-check:
@[ $(GO_VERSION_MAJ) -ge 2 ] || \
[ $(GO_VERSION_MAJ) -eq 1 -a $(GO_VERSION_MIN) -ge 11 ] || (echo "FATAL: Go version:$(GO_VERSION) does not support modules" ; exit 1 ; )
-include build/make/*.mk