forked from jaegertracing/jaeger-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
283 lines (234 loc) · 13 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
VERSION_DATE ?= $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GO_FLAGS ?= GOOS=linux GOARCH=amd64 CGO_ENABLED=0 GO111MODULE=on
KUBERNETES_CONFIG ?= "$(HOME)/.kube/config"
WATCH_NAMESPACE ?= ""
BIN_DIR ?= "build/_output/bin"
IMPORT_LOG=import.log
FMT_LOG=fmt.log
OPERATOR_NAME ?= jaeger-operator
NAMESPACE ?= "$(USER)"
BUILD_IMAGE ?= "$(NAMESPACE)/$(OPERATOR_NAME):latest"
OUTPUT_BINARY ?= "$(BIN_DIR)/$(OPERATOR_NAME)"
VERSION_PKG ?= "github.com/jaegertracing/jaeger-operator/pkg/version"
JAEGER_VERSION ?= "$(shell grep jaeger= versions.txt | awk -F= '{print $$2}')"
OPERATOR_VERSION ?= "$(shell git describe --tags)"
STORAGE_NAMESPACE ?= "${shell kubectl get sa default -o jsonpath='{.metadata.namespace}' || oc project -q}"
KAFKA_NAMESPACE ?= "kafka"
KAFKA_EXAMPLE ?= "https://raw.githubusercontent.com/strimzi/strimzi-kafka-operator/0.14.0/examples/kafka/kafka-persistent-single.yaml"
KAFKA_YAML ?= "https://github.com/strimzi/strimzi-kafka-operator/releases/download/0.14.0/strimzi-cluster-operator-0.14.0.yaml"
ES_OPERATOR_NAMESPACE ?= openshift-logging
ES_OPERATOR_BRANCH ?= release-4.2
PROMETHEUS_OPERATOR_TAG ?= v0.34.0
ES_OPERATOR_IMAGE ?= quay.io/openshift/origin-elasticsearch-operator:4.2
SDK_VERSION=v0.12.0
GOPATH ?= "$(HOME)/go"
LD_FLAGS ?= "-X $(VERSION_PKG).version=$(OPERATOR_VERSION) -X $(VERSION_PKG).buildDate=$(VERSION_DATE) -X $(VERSION_PKG).defaultJaeger=$(JAEGER_VERSION)"
PACKAGES := $(shell go list ./cmd/... ./pkg/... ./test/... | grep -v elasticsearch/v1 | grep -v kafka/v1beta1)
UNIT_TEST_PACKAGES := $(shell go list ./cmd/... ./pkg/... | grep -v elasticsearch/v1 | grep -v kafka/v1beta1)
TEST_OPTIONS = $(VERBOSE) -kubeconfig $(KUBERNETES_CONFIG) -namespacedMan ../../deploy/test/namespace-manifests.yaml -globalMan ../../deploy/crds/jaegertracing.io_jaegers_crd.yaml -root .
.DEFAULT_GOAL := build
.PHONY: check
check:
@echo Checking...
@GOPATH=${GOPATH} .ci/format.sh > $(FMT_LOG)
@[ ! -s "$(FMT_LOG)" ] || (echo "Go fmt, license check, or import ordering failures, run 'make format'" | cat - $(FMT_LOG) && false)
.PHONY: ensure-generate-is-noop
ensure-generate-is-noop: generate
@git diff -s --exit-code pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go || (echo "Build failed: a model has been changed but the deep copy functions aren't up to date. Run 'make generate' and update your PR." && exit 1)
.PHONY: format
format:
@echo Formatting code...
@GOPATH=${GOPATH} .ci/format.sh
.PHONY: lint
lint:
@echo Linting...
@${GOPATH}/bin/golint -set_exit_status=1 $(PACKAGES)
.PHONY: security
security:
@echo Security...
@${GOPATH}/bin/gosec -quiet -exclude=G104 $(PACKAGES) 2>/dev/null
.PHONY: build
build: format
@echo Building...
@${GO_FLAGS} go build -o $(OUTPUT_BINARY) -ldflags $(LD_FLAGS)
.PHONY: docker
docker:
@[ ! -z "$(PIPELINE)" ] || docker build --file build/Dockerfile -t "$(BUILD_IMAGE)" .
.PHONY: push
push:
ifeq ($(CI),true)
@echo Skipping push, as the build is running within a CI environment
else
@echo "Pushing image $(BUILD_IMAGE)..."
@docker push $(BUILD_IMAGE) > /dev/null
endif
.PHONY: unit-tests
unit-tests:
@echo Running unit tests...
@go test $(VERBOSE) $(UNIT_TEST_PACKAGES) -cover -coverprofile=cover.out
.PHONY: e2e-tests
e2e-tests: prepare-e2e-tests e2e-tests-smoke e2e-tests-cassandra e2e-tests-es e2e-tests-self-provisioned-es e2e-tests-streaming e2e-tests-examples1 e2e-tests-examples2
.PHONY: prepare-e2e-tests
prepare-e2e-tests: crd build docker push
@mkdir -p deploy/test
@cp test/role_binding.yaml deploy/test/namespace-manifests.yaml
@echo "---" >> deploy/test/namespace-manifests.yaml
@cat test/role.yaml >> deploy/test/namespace-manifests.yaml
@echo "---" >> deploy/test/namespace-manifests.yaml
@cat test/service_account.yaml >> deploy/test/namespace-manifests.yaml
@echo "---" >> deploy/test/namespace-manifests.yaml
@cat test/operator.yaml | sed "s~image: jaegertracing\/jaeger-operator\:.*~image: $(BUILD_IMAGE)~gi" >> deploy/test/namespace-manifests.yaml
.PHONY: e2e-tests-smoke
e2e-tests-smoke: prepare-e2e-tests
@echo Running Smoke end-to-end tests...
@BUILD_IMAGE=$(BUILD_IMAGE) go test -tags=smoke ./test/e2e/... $(TEST_OPTIONS)
.PHONY: e2e-tests-cassandra
e2e-tests-cassandra: prepare-e2e-tests cassandra
@echo Running Cassandra end-to-end tests...
@STORAGE_NAMESPACE=$(STORAGE_NAMESPACE) go test -tags=cassandra ./test/e2e/... $(TEST_OPTIONS)
.PHONY: e2e-tests-es
e2e-tests-es: prepare-e2e-tests es
@echo Running Elasticsearch end-to-end tests...
@STORAGE_NAMESPACE=$(STORAGE_NAMESPACE) go test -tags=elasticsearch ./test/e2e/... $(TEST_OPTIONS)
.PHONY: e2e-tests-self-provisioned-es
e2e-tests-self-provisioned-es: prepare-e2e-tests deploy-es-operator
@echo Running Self provisioned Elasticsearch end-to-end tests...
@STORAGE_NAMESPACE=$(STORAGE_NAMESPACE) ES_OPERATOR_NAMESPACE=$(ES_OPERATOR_NAMESPACE) ES_OPERATOR_IMAGE=$(ES_OPERATOR_IMAGE) go test -tags=self_provisioned_elasticsearch ./test/e2e/... $(TEST_OPTIONS)
.PHONY: e2e-tests-streaming
e2e-tests-streaming: prepare-e2e-tests es kafka
@echo Running Streaming end-to-end tests...
@STORAGE_NAMESPACE=$(STORAGE_NAMESPACE) KAFKA_NAMESPACE=$(KAFKA_NAMESPACE) go test -tags=streaming ./test/e2e/... $(TEST_OPTIONS)
.PHONY: e2e-tests-examples1
e2e-tests-examples1: prepare-e2e-tests es cassandra deploy-es-operator
@echo Running Example end-to-end tests part 1...
@STORAGE_NAMESPACE=$(STORAGE_NAMESPACE) KAFKA_NAMESPACE=$(KAFKA_NAMESPACE) go test -tags=examples1 ./test/e2e/... $(TEST_OPTIONS)
.PHONY: e2e-tests-examples2
e2e-tests-examples2: prepare-e2e-tests es kafka deploy-es-operator
@echo Running Example end-to-end tests part 2...
@STORAGE_NAMESPACE=$(STORAGE_NAMESPACE) KAFKA_NAMESPACE=$(KAFKA_NAMESPACE) go test -tags=examples2 ./test/e2e/... $(TEST_OPTIONS)
.PHONY: run
run: crd
@rm -rf /tmp/_cert*
@bash -c 'trap "exit 0" INT; POD_NAMESPACE=default OPERATOR_NAME=${OPERATOR_NAME} KUBERNETES_CONFIG=${KUBERNETES_CONFIG} WATCH_NAMESPACE=${WATCH_NAMESPACE} go run -ldflags ${LD_FLAGS} main.go start ${CLI_FLAGS}'
.PHONY: run-debug
run-debug: run
run-debug: CLI_FLAGS = "--log-level=debug"
.PHONY: set-max-map-count
set-max-map-count:
# This is not required in OCP 4.1. The node tuning operator configures the property automatically
# when label tuned.openshift.io/elasticsearch=true label is present on the ES pod. The label
# is configured by ES operator.
@minishift ssh -- 'sudo sysctl -w vm.max_map_count=262144' > /dev/null 2>&1 || true
.PHONY: set-node-os-linux
set-node-os-linux:
# Elasticsearch requires labeled nodes. These labels are by default present in OCP 4.2
@kubectl label nodes --all kubernetes.io/os=linux --overwrite
.PHONY: deploy-es-operator
deploy-es-operator: set-node-os-linux set-max-map-count
ifeq ($(OLM),true)
@echo Skipping es-operator deployment, assuming it has been installed via OperatorHub
else
@kubectl create namespace ${ES_OPERATOR_NAMESPACE} 2>&1 | grep -v "already exists" || true
@kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/${PROMETHEUS_OPERATOR_TAG}/example/prometheus-operator-crd/prometheusrule.crd.yaml
@kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/${PROMETHEUS_OPERATOR_TAG}/example/prometheus-operator-crd/servicemonitor.crd.yaml
@kubectl apply -f https://raw.githubusercontent.com/openshift/elasticsearch-operator/${ES_OPERATOR_BRANCH}/manifests/01-service-account.yaml -n ${ES_OPERATOR_NAMESPACE}
@kubectl apply -f https://raw.githubusercontent.com/openshift/elasticsearch-operator/${ES_OPERATOR_BRANCH}/manifests/02-role.yaml
@kubectl apply -f https://raw.githubusercontent.com/openshift/elasticsearch-operator/${ES_OPERATOR_BRANCH}/manifests/03-role-bindings.yaml
@kubectl apply -f https://raw.githubusercontent.com/openshift/elasticsearch-operator/${ES_OPERATOR_BRANCH}/manifests/04-crd.yaml -n ${ES_OPERATOR_NAMESPACE}
@kubectl apply -f https://raw.githubusercontent.com/openshift/elasticsearch-operator/${ES_OPERATOR_BRANCH}/manifests/05-deployment.yaml -n ${ES_OPERATOR_NAMESPACE}
@kubectl set image deployment/elasticsearch-operator elasticsearch-operator=${ES_OPERATOR_IMAGE} -n ${ES_OPERATOR_NAMESPACE}
endif
.PHONY: undeploy-es-operator
undeploy-es-operator:
ifeq ($(OLM),true)
@echo Skipping es-operator undeployment, as it should have been installed via OperatorHub
else
@kubectl delete -f https://raw.githubusercontent.com/openshift/elasticsearch-operator/${ES_OPERATOR_BRANCH}/manifests/05-deployment.yaml -n ${ES_OPERATOR_NAMESPACE} || true
@kubectl delete -f https://raw.githubusercontent.com/openshift/elasticsearch-operator/${ES_OPERATOR_BRANCH}/manifests/04-crd.yaml -n ${ES_OPERATOR_NAMESPACE} || true
@kubectl delete -f https://raw.githubusercontent.com/openshift/elasticsearch-operator/${ES_OPERATOR_BRANCH}/manifests/03-role-bindings.yaml || true
@kubectl delete -f https://raw.githubusercontent.com/openshift/elasticsearch-operator/${ES_OPERATOR_BRANCH}/manifests/02-role.yaml || true
@kubectl delete -f https://raw.githubusercontent.com/openshift/elasticsearch-operator/${ES_OPERATOR_BRANCH}/manifests/01-service-account.yaml -n ${ES_OPERATOR_NAMESPACE} || true
@kubectl delete -f https://raw.githubusercontent.com/coreos/prometheus-operator/${PROMETHEUS_OPERATOR_TAG}/example/prometheus-operator-crd/servicemonitor.crd.yaml || true
@kubectl delete -f https://raw.githubusercontent.com/coreos/prometheus-operator/${PROMETHEUS_OPERATOR_TAG}/example/prometheus-operator-crd/prometheusrule.crd.yaml || true
@kubectl delete namespace ${ES_OPERATOR_NAMESPACE} 2>&1 || true
endif
.PHONY: es
es: storage
@kubectl create -f ./test/elasticsearch.yml --namespace $(STORAGE_NAMESPACE) 2>&1 | grep -v "already exists" || true
.PHONY: cassandra
cassandra: storage
@kubectl create -f ./test/cassandra.yml --namespace $(STORAGE_NAMESPACE) 2>&1 | grep -v "already exists" || true
.PHONY: storage
storage:
@echo Creating namespace $(STORAGE_NAMESPACE)
@kubectl create namespace $(STORAGE_NAMESPACE) 2>&1 | grep -v "already exists" || true
.PHONY: kafka
kafka:
@echo Creating namespace $(KAFKA_NAMESPACE)
@kubectl create namespace $(KAFKA_NAMESPACE) 2>&1 | grep -v "already exists" || true
ifeq ($(OLM),true)
@echo Skipping kafka-operator deployment, assuming it has been installed via OperatorHub
else
@curl --location $(KAFKA_YAML) --output deploy/test/kafka-operator.yaml
@sed 's/namespace: .*/namespace: $(KAFKA_NAMESPACE)/' deploy/test/kafka-operator.yaml | kubectl -n $(KAFKA_NAMESPACE) apply -f - 2>&1 | grep -v "already exists" || true
endif
@curl --location $(KAFKA_EXAMPLE) --output deploy/test/kafka-example.yaml
@kubectl -n $(KAFKA_NAMESPACE) apply -f deploy/test/kafka-example.yaml 2>&1 | grep -v "already exists" || true
.PHONY: undeploy-kafka
undeploy-kafka:
@kubectl delete --namespace $(KAFKA_NAMESPACE) -f deploy/test/kafka-example.yaml 2>&1 || true
ifeq ($(OLM),true)
@echo Skiping kafka-operator undeploy
else
@kubectl delete --namespace $(KAFKA_NAMESPACE) -f deploy/test/kafka-operator.yaml 2>&1 || true
endif
@kubectl delete namespace $(KAFKA_NAMESPACE) 2>&1 || true
.PHONY: clean
clean: undeploy-kafka undeploy-es-operator
@rm -f deploy/test/*.yaml
@if [ -d deploy/test ]; then rmdir deploy/test ; fi
@kubectl delete -f ./test/cassandra.yml --ignore-not-found=true -n $(STORAGE_NAMESPACE) || true
@kubectl delete -f ./test/elasticsearch.yml --ignore-not-found=true -n $(STORAGE_NAMESPACE) || true
.PHONY: crd
crd:
@kubectl create -f deploy/crds/jaegertracing.io_jaegers_crd.yaml 2>&1 | grep -v "already exists" || true
.PHONY: ingress
ingress:
# see https://kubernetes.github.io/ingress-nginx/deploy/#verify-installation
@kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.18.0/deploy/mandatory.yaml
@minikube addons enable ingress
.PHONY: generate
generate:
@${GO_FLAGS} operator-sdk generate k8s
.PHONY: test
test: unit-tests e2e-tests
.PHONY: all
all: check format lint security build test
.PHONY: ci
ci: ensure-generate-is-noop check format lint security build unit-tests
.PHONY: scorecard
scorecard:
@operator-sdk scorecard --cr-manifest deploy/examples/simplest.yaml --csv-path deploy/olm-catalog/jaeger.clusterserviceversion.yaml --init-timeout 30
.PHONY: install-sdk
install-sdk:
@echo Installing SDK ${SDK_VERSION}
@SDK_VERSION=$(SDK_VERSION) GOPATH=$(GOPATH) ./.ci/install-sdk.sh
.PHONY: install-tools
install-tools:
@${GO_FLAGS} go get \
golang.org/x/lint/golint \
github.com/securego/gosec/cmd/gosec \
golang.org/x/tools/cmd/goimports
.PHONY: install
install: install-sdk install-tools
.PHONY: operatorhub
operatorhub: check-operatorhub-pr-template
@./.ci/operatorhub.sh
.PHONY: check-operatorhub-pr-template
check-operatorhub-pr-template:
@curl https://raw.githubusercontent.com/operator-framework/community-operators/master/docs/pull_request_template.md -o .ci/.operatorhub-pr-template.md -s > /dev/null 2>&1
@git diff -s --exit-code .ci/.operatorhub-pr-template.md || (echo "Build failed: the PR template for OperatorHub has changed. Sync it and try again." && exit 1)
.PHONY: local-jaeger-container
local-jaeger-container:
@echo "Starting local container with Jaeger. Check http://localhost:16686"
@docker run -d --rm -p 16686:16686 -p 6831:6831/udp --name jaeger jaegertracing/all-in-one:1.15 > /dev/null