-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathMakefile
More file actions
308 lines (244 loc) · 10.4 KB
/
Makefile
File metadata and controls
308 lines (244 loc) · 10.4 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
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
IMAGE_REG ?= quay.io
IMAGE_ORG ?= integreatly
IMAGE_NAME ?= cloud-resource-operator
OPERATOR_IMG = $(IMAGE_REG)/$(IMAGE_ORG)/$(IMAGE_NAME):v$(VERSION)
CONTAINER_PLATFORM ?= linux/amd64
MANIFEST_NAME ?= cloud-resources
NAMESPACE=cloud-resource-operator
PREV_VERSION=1.1.6
VERSION=1.1.7
COMPILE_TARGET=./tmp/_output/bin/$(IMAGE_NAME)
UPGRADE ?= true
CHANNEL ?= rhmi
REDIS_NODE_SIZE ?= ""
REDIS_NAME ?= example-redis
# openshift/aws
PROVIDER ?= openshift
CONTAINER_ENGINE ?= podman
ENVTEST_K8S_VERSION := $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
SHELL=/bin/bash
## Tool Binaries
KUBECTL ?= kubectl
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
## Tool Versions
KUSTOMIZE_VERSION ?= v5.4.3
CONTROLLER_TOOLS_VERSION ?= v0.18.0
ENVTEST_VERSION := $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
GOLANGCI_LINT_VERSION ?= v1.64.0
.PHONY: envtest
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
# Install the envtest binaries for the desired Kubernetes version into LOCALBIN.
.PHONY: setup-envtest
setup-envtest: $(ENVTEST)
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
echo "Error setting up envtest"; exit 1; }
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) GOFLAGS= go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef
# If the _correct_ version of operator-sdk is on the path, use that (faster);
# otherwise use it through "go run" (slower but will always work and will use correct version)
OPERATOR_SDK_VERSION=1.42.0
ifeq ($(shell operator-sdk version 2> /dev/null | sed -e 's/", .*/"/' -e 's/.* //'), "v$(OPERATOR_SDK_VERSION)")
OPERATOR_SDK ?= operator-sdk
else
OPERATOR_SDK ?= go run github.com/operator-framework/operator-sdk/cmd/operator-sdk
endif
AUTH_TOKEN=$(shell curl -sH "Content-Type: application/json" -XPOST https://quay.io/cnr/api/v1/users/login -d '{"user": {"username": "$(QUAY_USERNAME)", "password": "${QUAY_PASSWORD}"}}' | jq -r '.token')
OS := $(shell uname)
ifeq ($(OS),Darwin)
OPERATOR_SDK_OS := apple-darwin
else
OPERATOR_SDK_OS := linux-gnu
endif
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
.PHONY: build
build: code/gen
@GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o=$(COMPILE_TARGET) ./cmd/main.go
.PHONY: run
run:
RECTIME=30 WATCH_NAMESPACE=$(NAMESPACE) go run ./cmd/main.go
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: setup/service_account
setup/service_account: kustomize
@-oc new-project $(NAMESPACE)
@oc project $(NAMESPACE)
@-oc create -f config/rbac/service_account.yaml -n $(NAMESPACE)
@$(KUSTOMIZE) build config/rbac | oc replace --force -f -
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
.PHONY: code/run/service_account
code/run/service_account: setup/service_account
@oc login --token=$(shell oc create token cloud-resource-operator -n ${NAMESPACE} --duration=24h) --server=$(shell sh -c "oc cluster-info | grep -Eo 'https?://[-a-zA-Z0-9\.:]*'") --kubeconfig=TMP_SA_KUBECONFIG --insecure-skip-tls-verify=true
WATCH_NAMESPACE=$(NAMESPACE) go run ./cmd/main.go
PROJECT_ROOT := $(shell git rev-parse --show-toplevel)
.PHONY: code/gen
code/gen: manifests kustomize generate
# Make sure that the previous version and version values are set to correct values.
.PHONY: gen/csv
gen/csv: kustomize
@SEMVER=$(VERSION) PREV_VERSION=$(PREV_VERSION) ./scripts/gen-csv.sh
.PHONY: code/fix
code/fix:
@go mod tidy
@gofmt -w `find . -type f -name '*.go' -not -path "./vendor/*"`
.PHONY: code/check
code/check:
@diff -u <(echo -n) <(gofmt -d `find . -type f -name '*.go' -not -path "./vendor/*"`)
.PHONY: vendor/fix
vendor/fix:
go mod tidy
go mod vendor
.PHONY: vendor/check
vendor/check: vendor/fix
git diff --exit-code vendor/
.PHONY: cluster/prepare
cluster/prepare: kustomize setup/service_account
-oc new-project $(NAMESPACE) || true
-oc label namespace $(NAMESPACE) monitoring-key=middleware
-oc apply -f ./config/samples/cloud_resource_config.yaml -n $(NAMESPACE)
-oc apply -f ./config/samples/cloud_resources_$(PROVIDER)_strategies.yaml -n $(NAMESPACE)
$(KUSTOMIZE) build config/crd | oc apply -f -
.PHONY: cluster/seed/blobstorage
cluster/seed/blobstorage:
@cat config/samples/integreatly_v1alpha1_blobstorage.yaml | sed "s/type: REPLACE_ME/type: $(PROVIDER)/g" | oc apply -f - -n $(NAMESPACE)
.PHONY: cluster/seed/redis
cluster/seed/redis:
@cat config/samples/integreatly_v1alpha1_redis.yaml | sed "s/name: REPLACE_ME/name: $(REDIS_NAME)/g" | sed "s/type: REPLACE_ME/type: $(PROVIDER)/g" | sed "s/size: REPLACE_ME/size: '$(REDIS_NODE_SIZE)'/g" | oc apply -f - -n $(NAMESPACE)
.PHONY: cluster/seed/redissnapshot
cluster/seed/redissnapshot:
@cat config/samples/integreatly_v1alpha1_redissnapshot.yaml | sed "s/resourceName: REPLACE_ME/resourceName: example-redis/g" | oc apply -f - -n $(NAMESPACE)
.PHONY: cluster/seed/postgres
cluster/seed/postgres:
@cat config/samples/integreatly_v1alpha1_postgres.yaml | sed "s/type: REPLACE_ME/type: $(PROVIDER)/g" | oc apply -f - -n $(NAMESPACE)
.PHONY: cluster/seed/postgressnapshot
cluster/seed/postgressnapshot:
@cat config/samples/integreatly_v1alpha1_postgressnapshot.yaml | sed "s/resourceName: REPLACE_ME/resourceName: example-postgres/g" | oc apply -f - -n $(NAMESPACE)
.PHONY: cluster/clean
cluster/clean:
@$(KUSTOMIZE) build config/crd | oc delete -f -
@$(KUSTOMIZE) build config/rbac | oc delete --force -f -
oc delete project $(NAMESPACE)
.PHONY: test/unit
test/unit:
@echo Running tests:
GOFLAGS= go install github.com/rakyll/[email protected]
gotest -v -covermode=count -coverprofile=coverage.out ./pkg/providers/... ./pkg/resources/... ./api/integreatly/v1alpha1/types/... ./pkg/client/...
.PHONY: image/build
image/build: build
echo "build image ${OPERATOR_IMG}"
${CONTAINER_ENGINE} build --platform=$(CONTAINER_PLATFORM) -t ${OPERATOR_IMG} .
.PHONY: image/push
image/push: image/build
${CONTAINER_ENGINE} push ${OPERATOR_IMG}
.PHONY: test/e2e/prow
test/e2e/prow: export component := cloud-resource-operator
test/e2e/prow: export OPERATOR_IMAGE := ${IMAGE_FORMAT}
test/e2e/prow: cluster/prepare cluster/deploy
@echo Running e2e tests:
go clean -testcache && go test -v ./test/e2e -timeout=120m -ginkgo.v
oc delete project $(NAMESPACE)
.PHONY: test/e2e/local
test/e2e/local: cluster/prepare
@echo Running e2e tests:
go clean -testcache && go test -v ./test/e2e -timeout=120m -ginkgo.v
oc delete project $(NAMESPACE)
PROJECT_ROOT := $(shell git rev-parse --show-toplevel) # Define project root
.PHONY: test/lint
test/lint: golangci-lint
@cd $(PROJECT_ROOT) && $(GOLANGCI_LINT) run
.PHONY: cluster/deploy
cluster/deploy: kustomize
@echo Deploying operator with image: ${OPERATOR_IMAGE}
@ - cd config/manager && $(KUSTOMIZE) edit set image controller=${OPERATOR_IMAGE}
@ - $(KUSTOMIZE) build config/cloud-resource-operator | oc apply -f -
.PHONY: test/e2e/image
test/e2e/image:
@echo Running e2e tests:
$(OPERATOR_SDK) test local ./test/e2e --go-test-flags "-timeout=60m -v -parallel=2" --image $(IMAGE_REG)/$(IMAGE_ORG)/$(IMAGE_NAME):$(VERSION)
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests: controller-gen
$(CONTROLLER_GEN) "crd:crdVersions=v1" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Generate code
.PHONY: generate
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
.PHONY: code/audit
code/audit:
gosec ./...
.PHONY: code/gen
code/gen: setup/moq vendor/fix api/integreatly/v1alpha1/zz_generated.deepcopy.go
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook paths="./..."
@go generate ./...
.PHONY: setup/moq
setup/moq:
GOFLAGS= go install github.com/matryer/[email protected]
.PHONY: create/olm/bundle
create/olm/bundle:
@PREV_VERSION=$(PREV_VERSION) ./scripts/create-olm-bundle.sh
.PHONY: release/prepare
release/prepare: gen/csv image/push create/olm/bundle
# Commands added to support cro release pipeline, please remove once we move to CPaaS CRO builds
.PHONY: image/build/pipelines
image/build/pipelines: build
echo "build image ${OPERATOR_IMG}"
${CONTAINER_ENGINE} build --platform=$(CONTAINER_PLATFORM) --ulimit nofile=65535:65535 . -t ${OPERATOR_IMG}
${CONTAINER_ENGINE} save ${OPERATOR_IMG} | sudo -u jenkins ${CONTAINER_ENGINE} load
.PHONY: image/push/pipelines
image/push/pipelines: image/build/pipelines
echo "pushing image ${OPERATOR_IMG}"
${CONTAINER_ENGINE} push ${OPERATOR_IMG}
.PHONY: verify/release/exist
verify/release/exist:
IMAGE_TO_SCAN=${OPERATOR_IMG} ./scripts/imageExists.sh
.PHONY: coverage
coverage:
hack/codecov.sh
.PHONY: setup/sts
setup/sts:
NAMESPACE=$(NAMESPACE) ./scripts/sts/create-rhoam-policy.sh
.PHONY: gosec
gosec:
gosec -exclude-dir=hack/redis -exclude=G402,G115 test ./...
.PHONY: build-installer
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
mkdir -p dist
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default > dist/install.yaml