forked from rhobs/observability-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
220 lines (175 loc) · 7.1 KB
/
Makefile
File metadata and controls
220 lines (175 loc) · 7.1 KB
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
SHELL=/usr/bin/env bash -o pipefail
include Makefile.tools
# IMAGE_BASE defines the registry/namespace and part of the image name
# This variable is used to construct full image tags for bundle and catalog images.
IMAGE_BASE ?= monitoring-stack-operator
VERSION ?= $(shell cat VERSION)
OPERATOR_IMG = $(IMAGE_BASE):$(VERSION)
# running `make` builds the operator (default target)
all: operator
## Development
.PHONY: lint
lint: lint-golang lint-jsonnet
.PHONY: lint-golang
lint-golang: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run ./... --fix
.PHONY: lint-jsonnet
lint-jsonnet: $(JSONNET_LINT) jsonnet-vendor
find jsonnet/ -name 'vendor' -prune \
-o -name '*.libsonnet' -print \
-o -name '*.jsonnet' -print \
| xargs -n 1 -- $(JSONNET_LINT) -J $(JSONNET_VENDOR)
.PHONY: fmt-jsonnet
fmt-jsonnet: $(JSONNETFMT) jsonnet-vendor
find jsonnet/ -name 'vendor' -prune \
-o -name '*.libsonnet' -print \
-o -name '*.jsonnet' -print \
| xargs -n 1 -- $(JSONNETFMT) $(JSONNETFMT_ARGS) -i
.PHONY: check-jq
check-jq:
jq --version > /dev/null
.PHONY: jsonnet-vendor
jsonnet-vendor: $(JB)
cd jsonnet && $(JB) install
.PHONY: generate-prometheus-rules
generate-prometheus-rules: jsonnet-tools check-jq kustomize jsonnet-vendor
for dir in jsonnet/components/*/; do \
component=$$(basename $$dir) ;\
echo "Generating prometheusrule file for $$component" ;\
$(JSONNET) -J $(JSONNET_VENDOR) $$dir/main.jsonnet \
| jq .rule \
| $(GOJSONTOYAML) > deploy/operator/monitoring-stack-operator-$$component-rules.yaml ;\
cd deploy/operator && \
$(KUSTOMIZE) edit add resource "monitoring-stack-operator-$$component-rules.yaml" && cd - ;\
done;
.PHONY: docs
docs: $(CRDOC)
mkdir -p docs
$(CRDOC) --resources deploy/crds/common --output docs/api.md
.PHONY: generate-crds
generate-crds: $(CONTROLLER_GEN)
$(CONTROLLER_GEN) crd \
paths=./pkg/apis/... \
paths=./pkg/controllers/... \
rbac:roleName=monitoring-stack-operator \
output:dir=. \
output:rbac:dir=./deploy/operator \
output:crd:dir=./deploy/crds/common
mv deploy/operator/role.yaml deploy/operator/monitoring-stack-operator-cluster-role.yaml
.PHONY: generate-kustomize
generate-kustomize: $(KUSTOMIZE)
cd deploy/operator && \
$(KUSTOMIZE) edit set image monitoring-stack-operator=*:$(VERSION)
.PHONY: generate-deepcopy
generate-deepcopy: $(CONTROLLER_GEN)
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/apis/..."
.PHONY: generate
generate: generate-crds generate-deepcopy generate-kustomize generate-prometheus-rules docs
operator: generate
go build -o ./tmp/operator ./cmd/operator/...
.PHONY: operator-image
operator-image: generate
docker build -f build/Dockerfile . -t $(OPERATOR_IMG)
.PHONY: operator-push
operator-push:
docker push ${OPERATOR_IMG}
.PHONY: test-e2e
test-e2e:
go test ./test/e2e/...
## OLM - Bundle
# BUNDLE_IMG defines the image:tag used for the bundle.
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
BUNDLE_IMG ?= $(IMAGE_BASE)-bundle:$(VERSION)
# CHANNELS define the bundle channels used in the bundle.
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
CHANNELS ?= development
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
# DEFAULT_CHANNEL defines the default channel used in the bundle.
# To re-generate a bundle for any other default channel without changing the default setup, use:
# - DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
# - environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
DEFAULT_CHANNEL ?= development
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
.PHONY: bundle
bundle: $(KUSTOMIZE) $(OPERATOR_SDK) generate
cd deploy/olm && \
$(KUSTOMIZE) edit set image monitoring-stack-operator=$(OPERATOR_IMG)
$(KUSTOMIZE) build deploy/olm | tee tmp/pre-bundle.yaml | \
$(OPERATOR_SDK) generate bundle \
--overwrite \
--version $(VERSION) \
--kustomize-dir=deploy/olm \
--package=monitoring-stack-operator \
$(BUNDLE_METADATA_OPTS)
$(OPERATOR_SDK) bundle validate ./bundle
.PHONY: bundle-image
bundle-image: bundle ## Build the bundle image.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
.PHONY: bundle-push
bundle-push: ## Build the bundle image.
docker push $(BUNDLE_IMG)
# A comma-separated list of bundle images e.g.
# make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
#
# NOTE: These images MUST exist in a registry and be pull-able.
BUNDLE_IMGS ?= $(BUNDLE_IMG)
# The image tag given to the resulting catalog image
# The tag is used as latest since it allows a CatalogSubscription to point to
# a single image which keeps updating
CATALOG_IMG ?= $(IMAGE_BASE)-catalog:latest
# enable continuous release by referring to the same catalog image for `--from-index`
CATALOG_BASE_IMG ?= $(CATALOG_IMG)
# mark release as first by default for easier/quicker development
FIRST_OLM_RELEASE ?= true
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to
# that image except for FIRST_OLM_RELEASE
ifeq ($(FIRST_OLM_RELEASE), false)
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
endif
# Build a catalog image by adding bundle images to an empty catalog using the
# operator package manager tool, 'opm'.
#
# NOTE: This recipe invokes 'opm' in 'semver' bundle add mode. For more information
# on add modes, see:
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
.PHONY: catalog-image
catalog-image: $(OPM)
$(OPM) index add \
--container-tool docker \
--mode semver \
--tag $(CATALOG_IMG) \
--bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
# Push the catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
docker push $(CATALOG_IMG)
.PHONY: release
release: operator-image operator-push bundle-image bundle-push catalog-image catalog-push
STANDARD_VERSION=$(TOOLS_DIR)/standard-version
$(STANDARD_VERSION):
npm install -g --prefix tmp standard-version
.PHONY: initiate-release
initiate-release: $(STANDARD_VERSION)
git fetch git@github.com:rhobs/monitoring-stack-operator.git --tags
$(STANDARD_VERSION) -a --skip.tag # The tag will be created in the pipeline
.PHONY: initiate-release-as
initiate-release-as: $(STANDARD_VERSION)
git fetch git@github.com:rhobs/monitoring-stack-operator.git --tags
$(STANDARD_VERSION) -a --skip.tag --release-as $(RELEASE_VERSION)
.PHONY: kind-cluster
kind-cluster: $(OPERATOR_SDK)
kind create cluster --config hack/kind/config.yaml
$(OPERATOR_SDK) olm install
kubectl apply -f hack/kind/registry.yaml -n operators
kubectl create -k deploy/crds/kubernetes/
kubectl create -k deploy/dependencies
.PHONY: clean
clean: clean-tools
rm -rf $(JSONNET_VENDOR) bundle/ bundle.Dockerfile