forked from openshift/cluster-monitoring-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
198 lines (150 loc) · 5.7 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
SHELL=/usr/bin/env bash -o pipefail
GO_PKG=github.com/openshift/cluster-monitoring-operator
REPO?=quay.io/openshift/cluster-monitoring-operator
TAG?=$(shell git rev-parse --short HEAD)
VERSION=$(shell cat VERSION | tr -d " \t\n\r")
GOOS?=$(shell go env GOOS)
GOARCH?=$(shell go env GOARCH)
GO111MODULE?=on
GOPROXY?=http://proxy.golang.org
export GO111MODULE
export GOPROXY
PKGS=$(shell go list ./... | grep -v -E '/vendor/|/test|/examples')
GOLANG_FILES:=$(shell find . -name \*.go -print)
ASSETS=$(shell grep -oh '[^"]*/.*\.yaml' pkg/manifests/manifests.go | sed 's/^/assets\//')
BIN_DIR ?= $(shell pwd)/tmp/bin
EMBEDMD_BIN=$(BIN_DIR)/embedmd
JB_BIN=$(BIN_DIR)/jb
GOJSONTOYAML_BIN=$(BIN_DIR)/gojsontoyaml
JSONNET_BIN=$(BIN_DIR)/jsonnet
JSONNETFMT_BIN=$(BIN_DIR)/jsonnetfmt
PROMTOOL_BIN=$(BIN_DIR)/promtool
TOOLING=$(EMBEDMD_BIN) $(JB_BIN) $(GOJSONTOYAML_BIN) $(JSONNET_BIN) $(JSONNETFMT_BIN) $(PROMTOOL_BIN)
MANIFESTS_DIR ?= $(shell pwd)/manifests
JSON_MANIFESTS_DIR ?= $(shell pwd)/tmp/json-manifests/manifests
MANIFESTS ?= $(wildcard $(MANIFESTS_DIR)/*.yaml)
JSON_MANIFESTS ?= $(patsubst $(MANIFESTS_DIR)%,$(JSON_MANIFESTS_DIR)%,$(patsubst %.yaml,%.json,$(MANIFESTS)))
JSONNET_SRC=$(shell find ./jsonnet -type f -not -path "./jsonnet/vendor*")
JSONNET_VENDOR=jsonnet/vendor
GO_BUILD_RECIPE=GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build --ldflags="-s -X $(GO_PKG)/pkg/operator.Version=$(VERSION)"
.PHONY: all
all: clean format generate build test
.PHONY: clean
clean:
rm -rf $(JSONNET_VENDOR) operator .hack-operator-image tmp/
############
# Building #
############
.PHONY: run-local
run-local: build
KUBECONFIG=$(KUBECONFIG) ./hack/local-cmo.sh
.PHONY: build
build: operator
.PHONY: operator
operator: $(GOLANG_FILES)
$(GO_BUILD_RECIPE) -o operator $(GO_PKG)/cmd/operator
# We need this Make target so that we can build the operator depending
# only on what is checked into the repo, without calling to the internet.
.PHONY: operator-no-deps
operator-no-deps:
$(GO_BUILD_RECIPE) -o operator $(GO_PKG)/cmd/operator
.PHONY: image
image: .hack-operator-image
.hack-operator-image: Dockerfile operator
# Create empty target file, for the sole purpose of recording when this target
# was last executed via the last-modification timestamp on the file. See
# https://www.gnu.org/software/make/manual/make.html#Empty-Targets
docker build -t $(REPO):$(TAG) .
touch $@
##############
# Generating #
##############
.PHONY: vendor
vendor:
go mod tidy
go mod vendor
go mod verify
.PHONY: update
update: $(JB_BIN)
cd jsonnet && $(JB_BIN) update $(COMPONENTS)
.PHONY: generate
generate: build-jsonnet docs check-assets check-runbooks
# TODO(paulfantom): generate-in-docker can be completely removed after OpenShift 4.7 is EOL
.PHONY: generate-in-docker
generate-in-docker:
echo -e "FROM golang:1.14 \n RUN apt update && apt install python-yaml jq -y \n RUN mkdir /.cache && chown $(shell id -u):$(shell id -g) /.cache" | docker build -t cmo-tooling -
docker run -it --user $(shell id -u):$(shell id -g) \
-w /go/src/github.com/openshift/cluster-monitoring-operator \
-v ${PWD}:/go/src/github.com/openshift/cluster-monitoring-operator \
cmo-tooling make generate
$(JSONNET_VENDOR): $(JB_BIN) jsonnet/jsonnetfile.json jsonnet/jsonnetfile.lock.json
cd jsonnet && $(JB_BIN) install
$(ASSETS): build-jsonnet
# Check if files were properly generated
[ -f "$@" ] || exit 1
.PHONY: build-jsonnet
build-jsonnet: $(JSONNET_BIN) $(GOJSONTOYAML_BIN) $(JSONNET_SRC) $(JSONNET_VENDOR) json-manifests
./hack/build-jsonnet.sh
$(JSON_MANIFESTS): $(MANIFESTS)
cat $(MANIFESTS_DIR)/$(patsubst %.json,%.yaml,$(@F)) | $(GOJSONTOYAML_BIN) -yamltojson > $@
.PHONY: json-manifests
json-manifests: $(JSON_MANIFESTS_DIR) $(JSON_MANIFESTS)
.PHONY: versions
versions: $(GOJSONTOYAML_BIN)
./hack/generate-versions.sh
.PHONY: docs
docs: $(EMBEDMD_BIN) Documentation/telemetry/telemeter_query
$(EMBEDMD_BIN) -w `find Documentation -name "*.md"`
Documentation/telemeter_query: manifests/0000_50_cluster-monitoring-operator_04-config.yaml hack/telemeter_query.go
go generate ./hack/telemeter_query.go > Documentation/telemeter_query
##############
# Formatting #
##############
.PHONY: format
format: go-fmt shellcheck jsonnet-fmt check-rules
.PHONY: go-fmt
go-fmt:
go fmt $(PKGS)
.PHONY: jsonnet-fmt
jsonnet-fmt: $(JSONNETFMT_BIN)
find jsonnet/ -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | xargs -n 1 -- $(JSONNETFMT_BIN) -i
.PHONY: shellcheck
shellcheck:
hack/shellcheck.sh
tmp/rules.yaml: $(GOJSONTOYAML_BIN) $(ASSETS)
mkdir -p tmp/rules
hack/find-rules.sh | $(GOJSONTOYAML_BIN) > tmp/rules.yaml
.PHONY: check-rules
check-rules: $(PROMTOOL_BIN) tmp/rules.yaml
rm -f tmp/"$@".out
@$(PROMTOOL_BIN) check rules tmp/rules.yaml | tee "tmp/[email protected]"
.PHONY: test-rules
test-rules: check-rules
hack/test-rules.sh | tee "tmp/[email protected]"
.PHONY: check-assets
check-assets:
hack/check-assets.sh
.PHONY: check-runbooks
check-runbooks:
# Get runbook urls from the alerts annotations and test if a link is broken
# with wget. It also make sure that the command succeed when there are no urls.
@grep -rho 'runbook_url.*' assets || true | cut -f2- -d: | wget --spider -nv -i -
###########
# Testing #
###########
.PHONY: test
test: test-unit test-rules test-e2e
.PHONY: test-unit
test-unit:
go test -race -short $(PKGS) -count=1
.PHONY: test-e2e
test-e2e: KUBECONFIG?=$(HOME)/.kube/config
test-e2e:
go test -v -timeout=120m ./test/e2e/ --kubeconfig $(KUBECONFIG)
$(BIN_DIR):
mkdir -p $(BIN_DIR)
$(JSON_MANIFESTS_DIR):
mkdir -p $(JSON_MANIFESTS_DIR)
$(TOOLING): $(BIN_DIR)
@echo Installing tools from hack/tools.go
@cd hack/tools && go list -mod=mod -tags tools -f '{{ range .Imports }}{{ printf "%s\n" .}}{{end}}' ./ | xargs -tI % go build -mod=mod -o $(BIN_DIR) %