forked from openshift/elasticsearch-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·226 lines (178 loc) · 7.93 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
CURPATH=$(PWD)
export GOBIN=$(CURDIR)/bin
export PATH:=$(GOBIN):$(PATH)
include .bingo/Variables.mk
export GOROOT=$(shell go env GOROOT)
export GOFLAGS=-mod=vendor
export GO111MODULE=on
export OCP_VERSION=5.0
export APP_NAME=elasticsearch-operator
export ARTIFACT_DIR?=./tmp/artifacts
export JUNIT_REPORT_OUTPUT_DIR=$(ARTIFACT_DIR)/junit
COVERAGE_DIR=$(ARTIFACT_DIR)/coverage
IMAGE_TAG?=127.0.0.1:5000/openshift/origin-$(APP_NAME):latest
APP_REPO=github.com/openshift/$(APP_NAME)
KUBECONFIG?=$(HOME)/.kube/config
MAIN_PKG=main.go
RUN_LOG?=elasticsearch-operator.log
RUN_PID?=elasticsearch-operator.pid
LOGGING_IMAGE_STREAM?=stable
OPERATOR_NAMESPACE=openshift-operators-redhat
DEPLOYMENT_NAMESPACE?=openshift-logging
REPLICAS?=0
OS_NAME=$(shell uname -s | tr '[:upper:]' '[:lower:]')
GO_FILES := $(shell find . -type f -name '*.go')
MANIFEST_FILES := $(shell find manifests/ -type f)
OTHER_FILES := $(shell find files/ -type f)
.PHONY: all build clean fmt generate gobindir run test-e2e test-unit
all: build
artifactdir:
@mkdir -p $(ARTIFACT_DIR)
.PHONY: artifactdir
coveragedir: artifactdir
@mkdir -p $(COVERAGE_DIR)
.PHONY: junitreportdir
junitreportdir: artifactdir
@mkdir -p $(JUNIT_REPORT_OUTPUT_DIR)
.PHONY: junitreportdir
gobindir:
@mkdir -p $(GOBIN)
GEN_TIMESTAMP=.zz_generate_timestamp
generate: $(GEN_TIMESTAMP) $(OPERATOR_SDK) $(CONTROLLER_GEN)
$(GEN_TIMESTAMP): $(shell find apis -name '*.go')
@$(CONTROLLER_GEN) object paths="./apis/..."
@$(CONTROLLER_GEN) crd:crdVersions=v1 rbac:roleName=elasticsearch-operator paths="./..." output:crd:artifacts:config=config/crd/bases
@$(MAKE) fmt
@touch $@
regenerate: $(OPERATOR_SDK) $(CONTROLLER_GEN)
@rm -f $(GEN_TIMESTAMP)
@$(MAKE) generate
build:
@go build -o $(GOBIN)/elasticsearch-operator $(MAIN_PKG)
clean:
@rm -rf bin tmp _output
go clean -cache -testcache ./...
fmt: $(GOFUMPORTS)
@$(GOFUMPORTS) -l -w $(shell find internal apis controllers test version -name '*.go') ./*.go
lint: $(GOLANGCI_LINT) fmt lint-prom
@$(GOLANGCI_LINT) run -c golangci.yaml
lint-prom: $(PROMTOOL)
@$(PROMTOOL) check rules ./files/prometheus_recording_rules.yml
@$(PROMTOOL) check rules ./files/prometheus_alerts.yml
.INTERMEDIATE: Dockerfile.dev
Dockerfile.dev: Dockerfile Dockerfile.centos.patch
patch -o Dockerfile.dev Dockerfile Dockerfile.centos.patch
image: .output/image
.output/image: Dockerfile.dev $(GO_FILES) $(MANIFEST_FILES) $(OTHER_FILES)
podman build -f Dockerfile.dev -t $(IMAGE_TAG) .
@touch $@
test-unit: $(GO_JUNIT_REPORT) coveragedir junitreportdir test-unit-prom
@set -o pipefail && \
go test -v -race -coverprofile=$(COVERAGE_DIR)/test-unit.cov ./internal/... ./apis/... ./controllers/... ./. 2>&1 | \
tee /dev/stderr | \
$(GO_JUNIT_REPORT) > $(JUNIT_REPORT_OUTPUT_DIR)/junit.xml
@grep -v 'zz_generated\.' $(COVERAGE_DIR)/test-unit.cov > $(COVERAGE_DIR)/nogen.cov
@go tool cover -html=$(COVERAGE_DIR)/nogen.cov -o $(COVERAGE_DIR)/test-unit-coverage.html
@go tool cover -func=$(COVERAGE_DIR)/nogen.cov | tail -n 1
test-unit-prom: $(PROMTOOL)
@$(PROMTOOL) test rules ./test/files/prometheus-unit-tests/test.yml
deploy: deploy-image
LOCAL_IMAGE_ELASTICSEARCH_OPERATOR_REGISTRY=127.0.0.1:5000/openshift/elasticsearch-operator-registry \
$(MAKE) elasticsearch-catalog-build && \
IMAGE_ELASTICSEARCH_OPERATOR_REGISTRY=image-registry.openshift-image-registry.svc:5000/openshift/elasticsearch-operator-registry \
IMAGE_ELASTICSEARCH_OPERATOR=image-registry.openshift-image-registry.svc:5000/openshift/origin-elasticsearch-operator:latest \
$(MAKE) elasticsearch-catalog-deploy && \
IMAGE_ELASTICSEARCH_OPERATOR=image-registry.openshift-image-registry.svc:5000/openshift/origin-elasticsearch-operator:latest \
$(MAKE) elasticsearch-operator-install
.PHONY: deploy
deploy-image: image
IMAGE_TAG=$(IMAGE_TAG) hack/deploy-image.sh
.PHONY: deploy-image
deploy-example: deploy deploy-example-secret
@oc create -n $(DEPLOYMENT_NAMESPACE) -f hack/cr.yaml
.PHONY: deploy-example
deploy-example-secret: gen-example-certs
hack/deploy-example-secrets.sh $(DEPLOYMENT_NAMESPACE)
.PHONY: deploy-example-secret
gen-example-certs:
@rm -rf /tmp/example-secrets ||: \
mkdir /tmp/example-secrets && \
hack/cert_generation.sh /tmp/example-secrets $(DEPLOYMENT_NAMESPACE) elasticsearch
.PHONY: gen-example-certs
run: deploy deploy-example
@ALERTS_FILE_PATH=files/prometheus_alerts.yml \
RULES_FILE_PATH=files/prometheus_recording_rules.yml \
OPERATOR_NAME=elasticsearch-operator WATCH_NAMESPACE=$(DEPLOYMENT_NAMESPACE) \
KUBERNETES_CONFIG=/etc/origin/master/admin.kubeconfig \
go run ${MAIN_PKG} > $(RUN_LOG) 2>&1 & echo $$! > $(RUN_PID)
run-local:
@ALERTS_FILE_PATH=files/prometheus_alerts.yml \
RULES_FILE_PATH=files/prometheus_recording_rules.yml \
OPERATOR_NAME=elasticsearch-operator WATCH_NAMESPACE=$(DEPLOYMENT_NAMESPACE) \
KUBERNETES_CONFIG=$(KUBECONFIG) \
go run ${MAIN_PKG} LOG_LEVEL=debug
.PHONY: run-local
scale-cvo:
@oc -n openshift-cluster-version scale deployment/cluster-version-operator --replicas=$(REPLICAS)
.PHONY: scale-cvo
scale-olm:
@oc -n openshift-operator-lifecycle-manager scale deployment/olm-operator --replicas=$(REPLICAS)
.PHONY: scale-olm
uninstall:
$(MAKE) elasticsearch-catalog-uninstall
.PHONY: uninstall
# Generate bundle manifests and metadata, then validate generated files.
# - the bundle manifests are copied to ./manifests/${OCP_VERSION}/, e.g., ./manifests/4.7/
BUNDLE_VERSION?=$(OCP_VERSION).0
# Options for 'bundle-build'
BUNDLE_CHANNELS := --channels=${OCP_VERSION}
BUNDLE_DEFAULT_CHANNEL := --default-channel=${OCP_VERSION}
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
bundle: regenerate $(KUSTOMIZE)
$(OPERATOR_SDK) generate kustomize manifests -q
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(BUNDLE_VERSION) $(BUNDLE_METADATA_OPTS)
$(OPERATOR_SDK) bundle validate ./bundle
cp bundle/manifests/elasticsearch-operator.clusterserviceversion.yaml manifests/${OCP_VERSION}/elasticsearch-operator.v${BUNDLE_VERSION}.clusterserviceversion.yaml
cp bundle/manifests/logging.openshift.io_elasticsearches.yaml manifests/${OCP_VERSION}/logging.openshift.io_elasticsearches_crd.yaml
cp bundle/manifests/logging.openshift.io_kibanas.yaml manifests/${OCP_VERSION}/logging.openshift.io_kibanas_crd.yaml
.PHONY: bundle
test-e2e-upgrade:
hack/testing-olm-upgrade/test-030-olm-upgrade-n-1-n.sh
.PHONY: test-e2e-upgrade
# to use these targets, ensure the following env vars are set:
# either each IMAGE env var:
# IMAGE_ELASTICSEARCH_OPERATOR_REGISTRY
# IMAGE_ELASTICSEARCH_OPERATOR
# IMAGE_ELASTICSEARCH6
# IMAGE_ELASTICSEARCH_PROXY
# IMAGE_LOGGING_KIBANA6
# IMAGE_OAUTH_PROXY
# or the image format:
# IMAGE_FORMAT
#
# You must also set:
# ELASTICSEARCH_OPERATOR_NAMESPACE (Default: openshift-operators-redhat)
RANDOM_SUFFIX:=$(shell echo $$RANDOM)
TEST_NAMESPACE?="e2e-test-${RANDOM_SUFFIX}"
test-e2e-olm: DEPLOYMENT_NAMESPACE="${TEST_NAMESPACE}"
test-e2e-olm: $(GO_JUNIT_REPORT) $(JUNITMERGE) $(JUNITREPORT) junitreportdir
TEST_NAMESPACE=${TEST_NAMESPACE} hack/test-e2e-olm.sh
$(JUNITMERGE) $$(find $$JUNIT_REPORT_OUTPUT_DIR -iname *.xml) > $(JUNIT_REPORT_OUTPUT_DIR)/junit.xml
.PHONY: test-e2e-olm
elasticsearch-catalog: elasticsearch-catalog-build elasticsearch-catalog-deploy
elasticsearch-cleanup: elasticsearch-operator-uninstall elasticsearch-catalog-uninstall
# builds an operator-registry image containing the elasticsearch operator
elasticsearch-catalog-build:
olm_deploy/scripts/catalog-build.sh
# deploys the operator registry image and creates a catalogsource referencing it
elasticsearch-catalog-deploy:
olm_deploy/scripts/catalog-deploy.sh
# deletes the catalogsource and catalog namespace
elasticsearch-catalog-uninstall:
olm_deploy/scripts/catalog-uninstall.sh
# installs the elasticsearch operator from the deployed operator-registry/catalogsource.
elasticsearch-operator-install:
olm_deploy/scripts/operator-install.sh
# uninstalls the elasticsearch operator
elasticsearch-operator-uninstall:
olm_deploy/scripts/operator-uninstall.sh