-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile
2534 lines (2230 loc) · 137 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
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ----------------------------------------------------------------------------------------------------------------------
# Copyright (c) 2019, 2024, Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
#
# ----------------------------------------------------------------------------------------------------------------------
# This is the Makefile to build the Coherence Kubernetes Operator.
# ----------------------------------------------------------------------------------------------------------------------
# ======================================================================================================================
# Makefile Variables
#
# The following section contains all of the variables and properties used by other targets in the Makefile
# to set things like build directories, version numbers etc.
# ======================================================================================================================
# The version of the Operator being build - this should be a valid SemVer format
VERSION ?= 3.4.1
MVN_VERSION ?= $(VERSION)
# The version number to be replaced by this release
PREV_VERSION ?= 3.4.0
# The operator version to use to run certification tests against
CERTIFICATION_VERSION ?= $(VERSION)
# The previous Operator version used to run the compatibility tests.
COMPATIBLE_VERSION ?= 3.4.0
# The selector to use to find Operator Pods of the COMPATIBLE_VERSION (do not put in double quotes!!)
COMPATIBLE_SELECTOR ?= control-plane=coherence
# The GitHub project URL
PROJECT_URL = https://github.com/oracle/coherence-operator
KUBERNETES_DOC_VERSION=v1.30
# ----------------------------------------------------------------------------------------------------------------------
# The Coherence image to use for deployments that do not specify an image
# ----------------------------------------------------------------------------------------------------------------------
# The Coherence version to build against - must be a Java 8 compatible version
COHERENCE_VERSION ?= 21.12.5
COHERENCE_VERSION_LTS ?= 22.06.10
# The default Coherence image the Operator will run if no image is specified
COHERENCE_IMAGE_REGISTRY ?= ghcr.io/oracle
COHERENCE_IMAGE_NAME ?= coherence-ce
COHERENCE_IMAGE_TAG ?= $(COHERENCE_VERSION_LTS)
COHERENCE_IMAGE ?= $(COHERENCE_IMAGE_REGISTRY)/$(COHERENCE_IMAGE_NAME):$(COHERENCE_IMAGE_TAG)
COHERENCE_GROUP_ID ?= com.oracle.coherence.ce
# The Java version that tests will be compiled to.
# This should match the version required by the COHERENCE_IMAGE version
BUILD_JAVA_VERSION ?= 11
COHERENCE_TEST_BASE_IMAGE ?= gcr.io/distroless/java11-debian11
# This is the Coherence image that will be used in tests.
# Changing this variable will allow test builds to be run against different Coherence versions
# without altering the default image name.
TEST_COHERENCE_IMAGE ?= $(COHERENCE_IMAGE)
TEST_COHERENCE_VERSION ?= $(COHERENCE_VERSION)
TEST_COHERENCE_GID ?= com.oracle.coherence.ce
# The current working directory
CURRDIR := $(shell pwd)
GH_TOKEN ?=
ifeq ("$(GH_TOKEN)", "")
GH_AUTH := 'Foo: Bar'
else
GH_AUTH := 'authorization: Bearer $(GH_TOKEN)'
endif
# ----------------------------------------------------------------------------------------------------------------------
# By default we target amd64 as this is by far the most common local build environment
# We actually build images for amd64 and arm64
# ----------------------------------------------------------------------------------------------------------------------
UNAME_S = $(shell uname -s)
UNAME_M = $(shell uname -m)
ifeq (x86_64, $(UNAME_M))
IMAGE_ARCH = amd64
ARCH = amd64
else
IMAGE_ARCH = $(UNAME_M)
ARCH = $(UNAME_M)
endif
OS ?= linux
GOPROXY ?= https://proxy.golang.org
# ----------------------------------------------------------------------------------------------------------------------
# Set the location of the Operator SDK executable
# ----------------------------------------------------------------------------------------------------------------------
OPERATOR_SDK_VERSION := v1.9.0
# ----------------------------------------------------------------------------------------------------------------------
# Options to append to the Maven command
# ----------------------------------------------------------------------------------------------------------------------
MAVEN_OPTIONS ?= -Dmaven.wagon.httpconnectionManager.ttlSeconds=25 -Dmaven.wagon.http.retryHandler.count=3
MAVEN_BUILD_OPTS :=$(USE_MAVEN_SETTINGS) -Drevision=$(MVN_VERSION) -Dcoherence.version=$(COHERENCE_VERSION) -Dcoherence.version=$(COHERENCE_VERSION_LTS) -Dcoherence.groupId=$(COHERENCE_GROUP_ID) -Dcoherence.test.base.image=$(COHERENCE_TEST_BASE_IMAGE) -Dbuild.java.version=$(BUILD_JAVA_VERSION) $(MAVEN_OPTIONS)
# ----------------------------------------------------------------------------------------------------------------------
# Operator image names
# ----------------------------------------------------------------------------------------------------------------------
BASE_IMAGE_REGISTRY ?= ghcr.io
BASE_IMAGE_REPO ?= oracle
OPERATOR_IMAGE_REGISTRY ?= $(BASE_IMAGE_REGISTRY)/$(BASE_IMAGE_REPO)
RELEASE_IMAGE_PREFIX ?= $(OPERATOR_IMAGE_REGISTRY)/
OPERATOR_IMAGE_NAME := coherence-operator
OPERATOR_BASE_IMAGE ?= scratch
OPERATOR_OL_BASE_IMAGE ?= container-registry.oracle.com/java/jdk:17
OPERATOR_IMAGE_REPO := $(RELEASE_IMAGE_PREFIX)$(OPERATOR_IMAGE_NAME)
OPERATOR_IMAGE := $(OPERATOR_IMAGE_REPO):$(VERSION)
OPERATOR_IMAGE_DELVE := $(OPERATOR_IMAGE_REPO):delve
OPERATOR_IMAGE_DEBUG := $(OPERATOR_IMAGE_REPO):debug
TEST_BASE_IMAGE ?= $(OPERATOR_IMAGE_REPO)-test-base:$(VERSION)
# The Operator images to push
OPERATOR_RELEASE_REPO ?= $(OPERATOR_IMAGE_REPO)
OPERATOR_RELEASE_IMAGE := $(OPERATOR_RELEASE_REPO):$(VERSION)
TEST_BASE_RELEASE_IMAGE := $(OPERATOR_RELEASE_REPO)-test-base:$(VERSION)
BUNDLE_RELEASE_IMAGE := $(OPERATOR_RELEASE_REPO)-bundle:$(VERSION)
OPERATOR_PACKAGE_PREFIX := $(OPERATOR_IMAGE_REPO)-package
OPERATOR_PACKAGE_IMAGE := $(OPERATOR_PACKAGE_PREFIX):$(VERSION)
OPERATOR_REPO_PREFIX := $(OPERATOR_IMAGE_REPO)-repo
OPERATOR_REPO_IMAGE := $(OPERATOR_REPO_PREFIX):$(VERSION)
# ----------------------------------------------------------------------------------------------------------------------
# The test application images used in integration tests
# ----------------------------------------------------------------------------------------------------------------------
TEST_APPLICATION_IMAGE := $(RELEASE_IMAGE_PREFIX)operator-test:1.0.0
TEST_COMPATIBILITY_IMAGE := $(RELEASE_IMAGE_PREFIX)operator-test-compatibility:1.0.0
TEST_APPLICATION_IMAGE_CLIENT := $(RELEASE_IMAGE_PREFIX)operator-test-client:1.0.0
TEST_APPLICATION_IMAGE_HELIDON := $(RELEASE_IMAGE_PREFIX)operator-test-helidon:1.0.0
TEST_APPLICATION_IMAGE_SPRING := $(RELEASE_IMAGE_PREFIX)operator-test-spring:1.0.0
TEST_APPLICATION_IMAGE_SPRING_FAT := $(RELEASE_IMAGE_PREFIX)operator-test-spring-fat:1.0.0
TEST_APPLICATION_IMAGE_SPRING_CNBP := $(RELEASE_IMAGE_PREFIX)operator-test-spring-cnbp:1.0.0
# ----------------------------------------------------------------------------------------------------------------------
# Operator Lifecycle Manager properties
# ----------------------------------------------------------------------------------------------------------------------
# CHANNELS define the bundle channels used in the Operator Lifecycle Manager bundle.
CHANNELS := stable
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable")
# 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=preview,fast,stable)
# - use environment variables to overwrite this value (e.g export CHANNELS="preview,fast,stable")
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
# DEFAULT_CHANNEL defines the default channel used in the bundle.
DEFAULT_CHANNEL := stable
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
# To re-generate a bundle for any other default channel without changing the default setup, you can:
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# 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 ?= $(OPERATOR_IMAGE_REPO)-bundle:$(VERSION)
# ----------------------------------------------------------------------------------------------------------------------
# Release build options
# ----------------------------------------------------------------------------------------------------------------------
RELEASE_DRY_RUN ?= true
PRE_RELEASE ?= true
# ----------------------------------------------------------------------------------------------------------------------
# Testing properties
# ----------------------------------------------------------------------------------------------------------------------
# Extra arguments to pass to the go test command for the various test steps.
# For example, when running make e2e-test we can run just a single test such
# as the zone test using the go test -run=regex argument like this
# make e2e-test GO_TEST_FLAGS_E2E=-run=^TestZone$
ifeq ($(origin RUN_ONE), undefined)
GO_TEST_FLAGS ?= -timeout=20m
GO_TEST_FLAGS_E2E ?= -timeout=100m
else
GO_TEST_FLAGS ?= -timeout=20m -run=^$(RUN_ONE)$$
GO_TEST_FLAGS_E2E ?= -timeout=100m -run=^$(RUN_ONE)$$
endif
# default test namespace, as in test/e2e/helper/proj_helpers.go
OPERATOR_NAMESPACE ?= operator-test
# default test cluster namespace, as in test/e2e/helper/proj_helpers.go
CLUSTER_NAMESPACE ?= coherence-test
# the test client namespace
OPERATOR_NAMESPACE_CLIENT ?= operator-test-client
# the optional namespaces the operator should watch
WATCH_NAMESPACE ?=
# flag indicating whether the test namespace should be reset (deleted and recreated) before tests
CREATE_OPERATOR_NAMESPACE ?= true
# restart local storage for persistence
LOCAL_STORAGE_RESTART ?= false
# ----------------------------------------------------------------------------------------------------------------------
# Env variables used to create pull secrets
# This is required if building and testing in environments that need to pull or push
# images to private registries. For example building and testing with k8s in OCI.
# ----------------------------------------------------------------------------------------------------------------------
DOCKER_SERVER ?=
DOCKER_USERNAME ?=
DOCKER_PASSWORD ?=
OCR_DOCKER_USERNAME ?=
OCR_DOCKER_PASSWORD ?=
MAVEN_USER ?=
MAVEN_PASSWORD ?=
ifneq ("$(MAVEN_SETTINGS)","")
USE_MAVEN_SETTINGS = -s $(MAVEN_SETTINGS)
else
USE_MAVEN_SETTINGS =
endif
# Configure the image pull secrets information.
ifneq ("$(or $(DOCKER_USERNAME),$(DOCKER_PASSWORD))","")
DOCKER_SECRET = coherence-k8s-operator-development-secret
else
DOCKER_SECRET =
endif
ifneq ("$(or $(OCR_DOCKER_USERNAME),$(OCR_DOCKER_PASSWORD))","")
OCR_DOCKER_SECRET = ocr-k8s-operator-development-secret
else
OCR_DOCKER_SECRET =
endif
ifneq ("$(and $(DOCKER_SECRET),$(OCR_DOCKER_SECRET))","")
IMAGE_PULL_SECRETS ?= $(DOCKER_SECRET),$(OCR_DOCKER_SECRET)
else
ifneq ("$(DOCKER_SECRET)","")
IMAGE_PULL_SECRETS ?= $(DOCKER_SECRET)
else
ifneq ("$(OCR_DOCKER_SECRET)","")
IMAGE_PULL_SECRETS ?= $(OCR_DOCKER_SECRET)
else
IMAGE_PULL_SECRETS ?=
endif
endif
endif
ifeq (Darwin, $(UNAME_S))
SED = sed -i ''
else
SED = sed -i
endif
IMAGE_PULL_POLICY ?= IfNotPresent
# Env variable used by the kubectl test framework to locate the kubectl binary
TEST_ASSET_KUBECTL ?= $(shell which kubectl)
# ----------------------------------------------------------------------------------------------------------------------
# Build output directories
# ----------------------------------------------------------------------------------------------------------------------
override BUILD_OUTPUT := $(CURRDIR)/build/_output
override BUILD_ASSETS := pkg/data/assets
override BUILD_BIN := $(CURRDIR)/bin
override BUILD_BIN_AMD64 := $(BUILD_BIN)/linux/amd64
override BUILD_BIN_ARM64 := $(BUILD_BIN)/linux/arm64
override BUILD_DEPLOY := $(BUILD_OUTPUT)/config
override BUILD_HELM := $(BUILD_OUTPUT)/helm-charts
override BUILD_MANIFESTS := $(BUILD_OUTPUT)/manifests
override BUILD_MANIFESTS_PKG := $(BUILD_OUTPUT)/coherence-operator-manifests.tar.gz
override BUILD_PROPS := $(BUILD_OUTPUT)/build.properties
override BUILD_TARGETS := $(BUILD_OUTPUT)/targets
override SCRIPTS_DIR := $(CURRDIR)/hack
override EXAMPLES_DIR := $(CURRDIR)/examples
override TEST_LOGS_DIR := $(BUILD_OUTPUT)/test-logs
override TANZU_DIR := $(BUILD_OUTPUT)/tanzu
override TANZU_PACKAGE_DIR := $(BUILD_OUTPUT)/tanzu/package
override TANZU_REPO_DIR := $(BUILD_OUTPUT)/tanzu/repo
# ----------------------------------------------------------------------------------------------------------------------
# Set the location of various build tools
# ----------------------------------------------------------------------------------------------------------------------
TOOLS_DIRECTORY = $(CURRDIR)/build/tools
TOOLS_BIN = $(TOOLS_DIRECTORY)/bin
TOOLS_MANIFESTS = $(TOOLS_DIRECTORY)/manifests
OPERATOR_SDK_HOME = $(TOOLS_DIRECTORY)/sdk/$(UNAME_S)-$(UNAME_M)
OPERATOR_SDK = $(OPERATOR_SDK_HOME)/operator-sdk
# ----------------------------------------------------------------------------------------------------------------------
# The ttl.sh images used in integration tests
# ----------------------------------------------------------------------------------------------------------------------
TTL_REGISTRY := ttl.sh
TTL_TIMEOUT := 1h
TTL_UUID_FILE := $(BUILD_OUTPUT)/ttl-uuid.txt
TTL_UUID := $(shell if [ -f $(TTL_UUID_FILE) ]; then cat $(TTL_UUID_FILE); else uuidgen | tr A-Z a-z > $(TTL_UUID_FILE) && cat $(TTL_UUID_FILE); fi)
TTL_OPERATOR_IMAGE := $(TTL_REGISTRY)/coherence/$(TTL_UUID)/$(OPERATOR_IMAGE_NAME):$(TTL_TIMEOUT)
TTL_PACKAGE_IMAGE := $(TTL_REGISTRY)/coherence/$(TTL_UUID)/$(OPERATOR_IMAGE_NAME)-package:$(TTL_TIMEOUT)
TTL_REPO_IMAGE := $(TTL_REGISTRY)/coherence/$(TTL_UUID)/$(OPERATOR_IMAGE_NAME)-repo:$(TTL_TIMEOUT)
TTL_APPLICATION_IMAGE := $(TTL_REGISTRY)/coherence/$(TTL_UUID)/operator-test:$(TTL_TIMEOUT)
TTL_COMPATIBILITY_IMAGE := $(TTL_REGISTRY)/coherence/$(TTL_UUID)/operator-test-compatibility:$(TTL_TIMEOUT)
TTL_APPLICATION_IMAGE_CLIENT := $(TTL_REGISTRY)/coherence/$(TTL_UUID)/operator-test-client:$(TTL_TIMEOUT)
TTL_APPLICATION_IMAGE_HELIDON := $(TTL_REGISTRY)/coherence/$(TTL_UUID)/operator-test-helidon:$(TTL_TIMEOUT)
TTL_APPLICATION_IMAGE_SPRING := $(TTL_REGISTRY)/coherence/$(TTL_UUID)/operator-test-spring:$(TTL_TIMEOUT)
TTL_APPLICATION_IMAGE_SPRING_FAT := $(TTL_REGISTRY)/coherence/$(TTL_UUID)/operator-test-spring-fat:$(TTL_TIMEOUT)
TTL_APPLICATION_IMAGE_SPRING_CNBP := $(TTL_REGISTRY)/coherence/$(TTL_UUID)/operator-test-spring-cnbp:$(TTL_TIMEOUT)
# ----------------------------------------------------------------------------------------------------------------------
# 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
# ----------------------------------------------------------------------------------------------------------------------
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
# ----------------------------------------------------------------------------------------------------------------------
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
# ----------------------------------------------------------------------------------------------------------------------
# Capture the Git commit to add to the build information that is then embedded in the Go binary
# ----------------------------------------------------------------------------------------------------------------------
GITCOMMIT ?= $(shell git rev-list -1 HEAD)
GITREPO := https://github.com/oracle/coherence-operator.git
SOURCE_DATE_EPOCH := $(shell git show -s --format=format:%ct HEAD)
DATE_FMT := "%Y-%m-%dT%H:%M:%SZ"
BUILD_DATE := $(shell date -u -d "@$SOURCE_DATE_EPOCH" "+${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "+${DATE_FMT}" 2>/dev/null || date -u "+${DATE_FMT}")
BUILD_USER := $(shell whoami)
LDFLAGS = -X main.Version=$(VERSION) -X main.Commit=$(GITCOMMIT) -X main.Date=$(BUILD_DATE) -X main.Author=$(BUILD_USER)
GOS = $(shell find . -type f -name "*.go" ! -name "*_test.go")
HELM_FILES = $(shell find helm-charts/coherence-operator -type f)
API_GO_FILES = $(shell find . -type f -name "*.go" ! -name "*_test.go" ! -name "zz*.go")
CRDV1_FILES = $(shell find ./config/crd -type f)
JAVA_FILES = $(shell find ./java -type f)
TEST_SSL_SECRET := coherence-ssl-secret
# ----------------------------------------------------------------------------------------------------------------------
# Prometheus Operator settings (used in integration tests)
# ----------------------------------------------------------------------------------------------------------------------
# The version of kube-prometheus to use (main = latest main branch from https://github.com/prometheus-operator/kube-prometheus)
PROMETHEUS_VERSION ?= main
PROMETHEUS_HOME = $(TOOLS_DIRECTORY)/prometheus/$(PROMETHEUS_VERSION)
PROMETHEUS_NAMESPACE ?= monitoring
PROMETHEUS_ADAPTER_VERSION ?= 2.5.0
GRAFANA_DASHBOARDS ?= dashboards/grafana/
# ----------------------------------------------------------------------------------------------------------------------
# MetalLB load balancer settings
# ----------------------------------------------------------------------------------------------------------------------
METALLB_VERSION ?= v0.12.1
# ----------------------------------------------------------------------------------------------------------------------
# Istio settings
# ----------------------------------------------------------------------------------------------------------------------
# The version of Istio to install, leave empty for the latest
ISTIO_VERSION ?=
# ----------------------------------------------------------------------------------------------------------------------
# Tanzu settings
# ----------------------------------------------------------------------------------------------------------------------
# The version of Tanzu to install, leave empty for the latest
TANZU_VERSION ?=
TANZU =
# ======================================================================================================================
# Makefile targets start here
# ======================================================================================================================
# ----------------------------------------------------------------------------------------------------------------------
# Display the Makefile help - this is a list of the targets with a description.
# This target MUST be the first target in the Makefile so that it is run when running make with no arguments
# ----------------------------------------------------------------------------------------------------------------------
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
ttl-uuid:
echo "TTL UUID: $(TTL_UUID)"
# ======================================================================================================================
# Build targets
# ======================================================================================================================
##@ Build
.PHONY: all
all: build-all-images helm-chart ## Build all the Coherence Operator artefacts and images
# ----------------------------------------------------------------------------------------------------------------------
# Configure the build properties
# ----------------------------------------------------------------------------------------------------------------------
$(BUILD_PROPS):
# Ensures that build output directories exist
@echo "Creating build directories"
@mkdir -p $(BUILD_OUTPUT)
@mkdir -p $(BUILD_BIN)
@mkdir -p $(BUILD_DEPLOY)
@mkdir -p $(BUILD_HELM)
@mkdir -p $(BUILD_MANIFESTS)
@mkdir -p $(BUILD_TARGETS)
@mkdir -p $(TEST_LOGS_DIR)
@mkdir -p $(TOOLS_BIN)
@mkdir -p $(TOOLS_MANIFESTS)
# create build.properties
rm -f $(BUILD_PROPS)
printf "COHERENCE_IMAGE=$(COHERENCE_IMAGE)\n\
COHERENCE_IMAGE_REGISTRY=$(COHERENCE_IMAGE_REGISTRY)\n\
COHERENCE_IMAGE_NAME=$(COHERENCE_IMAGE_NAME)\n\
COHERENCE_IMAGE_TAG=$(COHERENCE_IMAGE_TAG)\n\
OPERATOR_IMAGE_REGISTRY=$(OPERATOR_IMAGE_REGISTRY)\n\
RELEASE_IMAGE_PREFIX=$(RELEASE_IMAGE_PREFIX)\n\
OPERATOR_IMAGE_NAME=$(OPERATOR_IMAGE_NAME)\n\
OPERATOR_IMAGE=$(OPERATOR_IMAGE)\n\
VERSION=$(VERSION)\n\
OPERATOR_PACKAGE_IMAGE=$(OPERATOR_PACKAGE_IMAGE)\n" > $(BUILD_PROPS)
# ----------------------------------------------------------------------------------------------------------------------
# Clean-up all of the build artifacts
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: clean
clean: ## Cleans the build
-rm -rf $(BUILD_OUTPUT) || true
-rm -rf $(BUILD_BIN) || true
-rm -rf bundle || true
rm pkg/data/zz_generated_*.go || true
./mvnw -f java clean $(MAVEN_BUILD_OPTS)
./mvnw -f examples clean $(MAVEN_BUILD_OPTS)
# ----------------------------------------------------------------------------------------------------------------------
# Clean-up all of the locally downloaded build tools
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: clean-tools
clean-tools: ## Cleans the locally downloaded build tools (i.e. need a new tool version)
-rm -rf $(TOOLS_BIN) || true
# ----------------------------------------------------------------------------------------------------------------------
# Builds the Operator
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-operator
build-operator: $(BUILD_TARGETS)/build-operator ## Build the Coherence Operator image
$(BUILD_TARGETS)/build-operator: $(BUILD_BIN)/runner $(BUILD_TARGETS)/java $(BUILD_TARGETS)/cli
docker build --platform linux/amd64 --no-cache --build-arg version=$(VERSION) \
--build-arg BASE_IMAGE=$(OPERATOR_BASE_IMAGE) \
--build-arg coherence_image=$(COHERENCE_IMAGE) \
--build-arg operator_image=$(OPERATOR_IMAGE) \
--build-arg target=amd64 \
. -t $(OPERATOR_IMAGE)-amd64
docker build --platform linux/arm64 --no-cache --build-arg version=$(VERSION) \
--build-arg BASE_IMAGE=$(OPERATOR_BASE_IMAGE) \
--build-arg coherence_image=$(COHERENCE_IMAGE) \
--build-arg operator_image=$(OPERATOR_IMAGE) \
--build-arg target=arm64 \
. -t $(OPERATOR_IMAGE)-arm64
docker tag $(OPERATOR_IMAGE)-$(IMAGE_ARCH) $(OPERATOR_IMAGE)
touch $(BUILD_TARGETS)/build-operator
.PHONY: build-operator-with-tools
build-operator-with-tools: $(BUILD_BIN)/runner $(BUILD_TARGETS)/java ## Build the Coherence Operator image on OL-8 with debug tools
mkdir -p $(BUILD_OUTPUT)/images || true
cat Dockerfile debug/Tools.Dockerfile > $(BUILD_OUTPUT)/images/Dockerfile
docker build --no-cache --build-arg version=$(VERSION) \
--build-arg BASE_IMAGE=$(OPERATOR_OL_BASE_IMAGE) \
--build-arg coherence_image=$(COHERENCE_IMAGE) \
--build-arg operator_image=$(OPERATOR_IMAGE) \
--build-arg target=amd64 \
-f $(BUILD_OUTPUT)/images/Dockerfile \
. -t $(OPERATOR_IMAGE)
.PHONY: build-operator-debug
build-operator-debug: $(BUILD_BIN)/linux/amd64/runner-debug $(BUILD_TARGETS)/java ## Build the Coherence Operator image with the Delve debugger
docker build --no-cache --build-arg version=$(VERSION) \
--build-arg BASE_IMAGE=$(OPERATOR_IMAGE_DELVE) \
--build-arg coherence_image=$(COHERENCE_IMAGE) \
--build-arg operator_image=$(OPERATOR_IMAGE) \
--build-arg target=amd64 \
-f debug/Dockerfile \
. -t $(OPERATOR_IMAGE_DEBUG)
build-delve-image: ## Build the Coherence Operator Delve debugger base image
docker build -f debug/Base.Dockerfile -t $(OPERATOR_IMAGE_DELVE) debug
$(BUILD_BIN)/linux/amd64/runner-debug: $(BUILD_PROPS) $(GOS) $(BUILD_TARGETS)/generate $(BUILD_TARGETS)/manifests
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -gcflags "-N -l" -ldflags "$(LDFLAGS)" -a -o $(BUILD_BIN)/linux/amd64/runner-debug ./runner
chmod +x $(BUILD_BIN)/linux/amd64/runner-debug
# ----------------------------------------------------------------------------------------------------------------------
# Build the Operator images without the test images
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-operator-images
build-operator-images: $(BUILD_TARGETS)/build-operator ## Build all operator images
# ----------------------------------------------------------------------------------------------------------------------
# Build the Operator Test images
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-test-images
build-test-images: $(BUILD_TARGETS)/java build-client-image build-basic-test-image ## Build all of the test images
./mvnw -B -f java/operator-test-helidon package jib:dockerBuild -DskipTests -Djib.to.image=$(TEST_APPLICATION_IMAGE_HELIDON) $(MAVEN_BUILD_OPTS)
./mvnw -B -f java/operator-test-spring package jib:dockerBuild -DskipTests -Djib.to.image=$(TEST_APPLICATION_IMAGE_SPRING) $(MAVEN_BUILD_OPTS)
./mvnw -B -f java/operator-test-spring package spring-boot:build-image -DskipTests -Dcnbp-image-name=$(TEST_APPLICATION_IMAGE_SPRING_CNBP) $(MAVEN_BUILD_OPTS)
docker build -f java/operator-test-spring/target/FatJar.Dockerfile -t $(TEST_APPLICATION_IMAGE_SPRING_FAT) java/operator-test-spring/target
rm -rf java/operator-test-spring/target/spring || true && mkdir java/operator-test-spring/target/spring
cp java/operator-test-spring/target/operator-test-spring-$(MVN_VERSION).jar java/operator-test-spring/target/spring/operator-test-spring-$(MVN_VERSION).jar
cd java/operator-test-spring/target/spring && jar -xvf operator-test-spring-$(MVN_VERSION).jar && rm -f operator-test-spring-$(MVN_VERSION).jar
docker build -f java/operator-test-spring/target/Dir.Dockerfile -t $(TEST_APPLICATION_IMAGE_SPRING) java/operator-test-spring/target
# ----------------------------------------------------------------------------------------------------------------------
# Build the basic Operator Test image
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-basic-test-image
build-basic-test-image: $(BUILD_TARGETS)/java ## Build the basic Operator test image
./mvnw -B -f java/operator-test clean package jib:dockerBuild -DskipTests -Djib.to.image=$(TEST_APPLICATION_IMAGE) $(MAVEN_BUILD_OPTS) -Dcoherence.version=$(COHERENCE_IMAGE_TAG)
.PHONY: build-client-image
build-client-image: ## Build the test client image
./mvnw -B -f java/operator-test-client package jib:dockerBuild -DskipTests -Djib.to.image=$(TEST_APPLICATION_IMAGE_CLIENT) $(MAVEN_BUILD_OPTS)
# ----------------------------------------------------------------------------------------------------------------------
# Build all of the Docker images
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-all-images
build-all-images: $(BUILD_TARGETS)/build-operator build-test-images build-compatibility-image ## Build all images (including tests)
# ----------------------------------------------------------------------------------------------------------------------
# Ensure Operator SDK is at the correct version
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: ensure-sdk
ensure-sdk:
@echo "Ensuring Operator SDK is present at version $(OPERATOR_SDK_VERSION)"
$(SCRIPTS_DIR)/ensure-sdk.sh $(OPERATOR_SDK_VERSION) $(OPERATOR_SDK_HOME)
# ----------------------------------------------------------------------------------------------------------------------
# Internal make step that builds the Operator runner artifacts utility
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-runner
build-runner: $(BUILD_BIN)/runner ## Build the Coherence Operator runner binary
$(BUILD_BIN)/runner: $(BUILD_PROPS) $(GOS) $(BUILD_TARGETS)/generate $(BUILD_TARGETS)/manifests
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -trimpath -ldflags "$(LDFLAGS)" -o $(BUILD_BIN)/runner ./runner
mkdir -p $(BUILD_BIN_AMD64) || true
cp -f $(BUILD_BIN)/runner $(BUILD_BIN_AMD64)/runner
mkdir -p $(BUILD_BIN_ARM64)/linux || true
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go build -trimpath -ldflags "$(LDFLAGS)" -a -o $(BUILD_BIN_ARM64)/runner ./runner
# ----------------------------------------------------------------------------------------------------------------------
# Build the Java artifacts
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-mvn
build-mvn: $(BUILD_TARGETS)/java ## Build the Java artefacts
$(BUILD_TARGETS)/java: $(JAVA_FILES)
./mvnw -B -f java clean install -DskipTests $(MAVEN_BUILD_OPTS)
touch $(BUILD_TARGETS)/java
# ---------------------------------------------------------------------------
# Build the Coherence operator Helm chart and package it into a tar.gz
# ---------------------------------------------------------------------------
.PHONY: helm-chart
helm-chart: $(BUILD_PROPS) $(BUILD_HELM)/coherence-operator-$(VERSION).tgz ## Build the Coherence Operator Helm chart
$(BUILD_HELM)/coherence-operator-$(VERSION).tgz: $(BUILD_PROPS) $(HELM_FILES) $(BUILD_TARGETS)/generate $(BUILD_TARGETS)/manifests $(TOOLS_BIN)/kustomize
# Copy the Helm chart from the source location to the distribution folder
-mkdir -p $(BUILD_HELM)
cp -R ./helm-charts/coherence-operator $(BUILD_HELM)
$(call replaceprop,$(BUILD_HELM)/coherence-operator/Chart.yaml $(BUILD_HELM)/coherence-operator/values.yaml $(BUILD_HELM)/coherence-operator/templates/deployment.yaml)
# Package the chart into a .tr.gz - we don't use helm package as the version might not be SEMVER
helm lint $(BUILD_HELM)/coherence-operator
tar -C $(BUILD_HELM)/coherence-operator -czf $(BUILD_HELM)/coherence-operator-$(VERSION).tgz .
# ---------------------------------------------------------------------------
# Do a search and replace of properties in selected files in the Helm charts.
# This is done because the Helm charts can be large and processing every file
# makes the build slower.
# ---------------------------------------------------------------------------
define replaceprop
for i in $(1); do \
filename="$${i}"; \
echo "Replacing properties in file $${filename}"; \
if [ -f $${filename} ]; then \
temp_file=$(BUILD_OUTPUT)/temp.out; \
awk -F'=' 'NR==FNR {a[$$1]=$$2;next} {for (i in a) {x = sprintf("\\$${%s}", i); gsub(x, a[i])}}1' $(BUILD_PROPS) $${filename} > $${temp_file}; \
mv $${temp_file} $${filename}; \
fi \
done
endef
# ======================================================================================================================
# General development related targets
# ======================================================================================================================
##@ Development
# ----------------------------------------------------------------------------------------------------------------------
# Generate manifests e.g. CRD, RBAC etc.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: manifests
manifests: $(BUILD_TARGETS)/manifests ## Generate the CustomResourceDefinition and other yaml manifests.
$(BUILD_TARGETS)/manifests: $(BUILD_PROPS) config/crd/bases/coherence.oracle.com_coherence.yaml docs/about/04_coherence_spec.adoc $(BUILD_MANIFESTS_PKG)
touch $(BUILD_TARGETS)/manifests
config/crd/bases/coherence.oracle.com_coherence.yaml: $(TOOLS_BIN)/kustomize $(API_GO_FILES) $(TOOLS_BIN)/controller-gen
$(CONTROLLER_GEN) "crd:crdVersions={v1}" \
rbac:roleName=manager-role paths="{./api/...,./controllers/...}" \
output:crd:dir=config/crd/bases
cp -R config/crd/ config/crd-small
$(CONTROLLER_GEN) "crd:crdVersions={v1},maxDescLen=0" \
rbac:roleName=manager-role paths="{./api/...,./controllers/...}" \
output:crd:dir=config/crd-small/bases
cd config/crd && $(KUSTOMIZE) edit add label "app.kubernetes.io/version:$(VERSION)" -f
$(KUSTOMIZE) build config/crd -o $(BUILD_ASSETS)/
cd config/crd-small && $(KUSTOMIZE) edit add label "app.kubernetes.io/version:$(VERSION)" -f
# ----------------------------------------------------------------------------------------------------------------------
# Generate the config.json file used by the Operator for default configuration values
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: generate-config
generate-config: $(BUILD_PROPS) $(BUILD_OUTPUT)/config.json
$(BUILD_OUTPUT)/config.json:
@echo "Generating Operator config"
@printf "{\n \
\"coherence-image\": \"$(COHERENCE_IMAGE)\",\n \
\"operator-image\": \"$(OPERATOR_RELEASE_IMAGE)\"\n}\n" > $(BUILD_OUTPUT)/config.json
cp $(BUILD_OUTPUT)/config.json $(BUILD_ASSETS)/config.json
# ----------------------------------------------------------------------------------------------------------------------
# Generate code, configuration and docs.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: generate
generate: $(BUILD_TARGETS)/generate ## Run Kubebuilder code and configuration generation
$(BUILD_TARGETS)/generate: $(BUILD_PROPS) $(BUILD_OUTPUT)/config.json api/v1/zz_generated.deepcopy.go
touch $(BUILD_TARGETS)/generate
api/v1/zz_generated.deepcopy.go: $(API_GO_FILES) $(TOOLS_BIN)/controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./api/..."
# ----------------------------------------------------------------------------------------------------------------------
# Generate API docs
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: api-doc-gen
api-doc-gen: docs/about/04_coherence_spec.adoc ## Generate API documentation
docs/about/04_coherence_spec.adoc: export KUBERNETES_DOC_VERSION := $(KUBERNETES_DOC_VERSION)
docs/about/04_coherence_spec.adoc: $(API_GO_FILES) utils/docgen/main.go
@echo "Generating CRD Doc"
go run ./utils/docgen/ \
api/v1/coherenceresourcespec_types.go \
api/v1/coherence_types.go \
api/v1/coherenceresource_types.go \
> docs/about/04_coherence_spec.adoc
# ----------------------------------------------------------------------------------------------------------------------
# Generate the keys and certs used in tests.
# ----------------------------------------------------------------------------------------------------------------------
$(BUILD_OUTPUT)/certs:
@echo "Generating test keys and certs"
$(SCRIPTS_DIR)/keys.sh
# ----------------------------------------------------------------------------------------------------------------------
# Executes the code review targets.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: code-review
code-review: export MAVEN_USER := $(MAVEN_USER)
code-review: export MAVEN_PASSWORD := $(MAVEN_PASSWORD)
code-review: $(BUILD_TARGETS)/generate golangci copyright ## Full code review and Checkstyle test
./mvnw -B -f java validate -DskipTests -P checkstyle $(MAVEN_BUILD_OPTS)
# ----------------------------------------------------------------------------------------------------------------------
# Executes golangci-lint to perform various code review checks on the source.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: golangci
golangci: $(TOOLS_BIN)/golangci-lint ## Go code review
$(TOOLS_BIN)/golangci-lint run -v --timeout=5m --exclude='G402:' --exclude='G101:' --exclude='G114:' --skip-dirs=.*/fakes --skip-files=zz_.*,generated/*,pkg/data/assets... ./api/... ./controllers/... ./pkg/... ./runner/...
$(TOOLS_BIN)/golangci-lint run -v --timeout=5m --exclude='G107:' --exclude='G101:' --exclude='G112:' --exclude='SA4005:' --exclude='should not use dot imports' ./test/... ./pkg/fakes/...
# ----------------------------------------------------------------------------------------------------------------------
# Performs a copyright check.
# To add exclusions add the file or folder pattern using the -X parameter.
# Add directories to be scanned at the end of the parameter list.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: copyright
copyright: ## Check copyright headers
@java -cp hack/glassfish-copyright-maven-plugin-2.1.jar \
org.glassfish.copyright.Copyright -C hack/copyright.txt \
-X .adoc \
-X bin/ \
-X build/ \
-X clientset/ \
-X dashboards/ \
-X /Dockerfile \
-X .Dockerfile \
-X docs/ \
-X examples/.mvn/ \
-X examples/helm/chart/templates/NOTES.txt \
-X .factories \
-X hack/copyright.txt \
-X hack/install-cli.sh \
-X hack/intellij-codestyle.xml \
-X hack/istio- \
-X hack/sdk/ \
-X go.mod \
-X go.sum \
-X .gradle/ \
-X gradle/ \
-X gradlew \
-X gradlew.bat \
-X HEADER.txt \
-X helm-charts/coherence-operator/templates/NOTES.txt \
-X .iml \
-X java/certs/ \
-X java/src/copyright/EXCLUDE.txt \
-X Jenkinsfile \
-X .jar \
-X jib-cache/ \
-X .jks \
-X .json \
-X LICENSE.txt \
-X Makefile \
-X .md \
-X meta/ \
-X .mvn/ \
-X mvnw \
-X mvnw.cmd \
-X .png \
-X PROJECT \
-X .sh \
-X tanzu/package/package.yml \
-X tanzu/package/values.yml \
-X temp/ \
-X temp/olm/ \
-X /test-report.xml \
-X THIRD_PARTY_LICENSES.txt \
-X tools.go \
-X .tpl \
-X .txt \
-X .yaml \
-X pkg/data/assets/ \
-X zz_generated.
# ----------------------------------------------------------------------------------------------------------------------
# Run the Operator locally.
#
# To exit out of the local Operator you can use ctrl-c or ctrl-z but
# sometimes this leaves orphaned processes on the local machine so
# ensure these are killed run "make debug-stop"
# ----------------------------------------------------------------------------------------------------------------------
run: export COHERENCE_IMAGE := $(COHERENCE_IMAGE)
run: create-namespace ## run the Operator locally
go run -ldflags "$(LDFLAGS)" ./runner/main.go operator --skip-service-suspend=true --coherence-dev-mode=true \
--cert-type=self-signed --webhook-service=host.docker.internal \
2>&1 | tee $(TEST_LOGS_DIR)/operator-debug.out
# ----------------------------------------------------------------------------------------------------------------------
# Run the Operator locally after deleting and recreating the test namespace.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: run-clean
run-clean: reset-namespace run ## run the Operator locally after resetting the namespace
# ----------------------------------------------------------------------------------------------------------------------
# Run the Operator in locally debug mode,
# Running this task will start the Operator and pause it until a Delve
# is attached.
#
# To exit out of the local Operator you can use ctrl-c or ctrl-z but
# sometimes this leaves orphaned processes on the local machine so
# ensure these are killed run "make debug-stop"
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: run-debug
run-debug: export COHERENCE_IMAGE := $(COHERENCE_IMAGE)
run-debug: export OPERATOR_IMAGE := $(OPERATOR_IMAGE)
run-debug: create-namespace ## run the Operator locally with Delve debugger
dlv debug ./runner --headless --listen=:2345 --api-version=2 --accept-multiclient \
-- --skip-service-suspend=true --coherence-dev-mode=true \
--cert-type=self-signed --webhook-service=host.docker.internal
# ----------------------------------------------------------------------------------------------------------------------
# Run the Operator locally in debug mode after deleting and recreating
# the test namespace.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: run-debug-clean
run-debug-clean: reset-namespace run-debug ## run the Operator locally with Delve debugger after resetting the namespace
# ----------------------------------------------------------------------------------------------------------------------
# Kill any locally running Operator
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: stop
stop: ## kill any locally running operator process
$(SCRIPTS_DIR)/kill-local.sh
# ======================================================================================================================
# Targets related to Operator Lifecycle Manager and the Operator SDK
# ======================================================================================================================
##@ Operator Lifecycle Manager
# ----------------------------------------------------------------------------------------------------------------------
# Generate bundle manifests and metadata, then validate generated files.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: bundle
bundle: $(BUILD_PROPS) ensure-sdk $(TOOLS_BIN)/kustomize $(BUILD_TARGETS)/manifests ## Generate OLM bundle manifests and metadata, then validate generated files.
$(OPERATOR_SDK) generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_IMAGE)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
$(OPERATOR_SDK) bundle validate ./bundle
$(OPERATOR_SDK) bundle validate ./bundle --select-optional suite=operatorframework --optional-values=k8s-version=1.22
$(OPERATOR_SDK) bundle validate ./bundle --select-optional name=community --optional-values=image-path=bundle.Dockerfile
# ----------------------------------------------------------------------------------------------------------------------
# Build the bundle image.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: bundle-build
bundle-build: ## Build the OLM image
docker build --no-cache -f bundle.Dockerfile -t $(BUNDLE_IMG) .
.PHONY: bundle-push
bundle-push: ## Push the OLM bundle image.
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
.PHONY: opm
OPM = ./bin/opm
opm: ## Download opm locally if necessary.
ifeq (,$(wildcard $(OPM)))
ifeq (,$(shell which opm 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPM)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm --header $(GH_AUTH) ;\
chmod +x $(OPM) ;\
}
else
OPM = $(shell which opm)
endif
endif
# 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).
# These images MUST exist in a registry and be pull-able.
BUNDLE_IMGS ?= $(BUNDLE_IMG)
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
ifneq ($(origin CATALOG_BASE_IMG), undefined)
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'.
# 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-build
catalog-build: opm ## Build an OLM catalog image.
$(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 an OLM catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)
# ======================================================================================================================
# Targets to run various tests
# ======================================================================================================================
##@ Test
# ----------------------------------------------------------------------------------------------------------------------
# Executes the Go unit tests that do not require a k8s cluster
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: test-operator
test-operator: export CGO_ENABLED = 0
test-operator: export COHERENCE_IMAGE := $(COHERENCE_IMAGE)
test-operator: export OPERATOR_IMAGE := $(OPERATOR_IMAGE)
test-operator: $(BUILD_PROPS) $(BUILD_TARGETS)/manifests $(BUILD_TARGETS)/generate gotestsum ## Run the Operator unit tests
@echo "Running operator tests"
$(GOTESTSUM) --format standard-verbose --junitfile $(TEST_LOGS_DIR)/operator-test.xml \
-- $(GO_TEST_FLAGS) -v ./api/... ./controllers/... ./pkg/...
# ----------------------------------------------------------------------------------------------------------------------
# Build and test the Java artifacts
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: test-mvn
test-mvn: $(BUILD_OUTPUT)/certs $(BUILD_TARGETS)/java ## Run the Java artefact tests
./mvnw -B -f java verify -Dtest.certs.location=$(BUILD_OUTPUT)/certs $(MAVEN_BUILD_OPTS)
# ----------------------------------------------------------------------------------------------------------------------
# Run all unit tests (both Go and Java)
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: test-all
test-all: test-mvn test-operator ## Run all unit tests
ENVTEST_K8S_VERSION = 1.31.0
ENVTEST_VERSION ?= release-0.19
.PHONY: envtest
envtest: $(TOOLS_BIN)/setup-envtest ## Download setup-envtest locally if necessary.
envtest-delete:
$(TOOLS_BIN)/setup-envtest --bin-dir $(TOOLS_BIN) cleanup latest-on-disk
rm -rf $(TOOLS_BIN)/k8s || true
$(TOOLS_BIN)/setup-envtest:
test -s $(TOOLS_BIN)/setup-envtest || GOBIN=$(TOOLS_BIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION)
ls -al $(TOOLS_BIN)
k8stools: $(TOOLS_BIN)/k8s
$(TOOLS_BIN)/k8s: $(TOOLS_BIN)/setup-envtest
mkdir -p $(TOOLS_BIN)/k8s || true
$(TOOLS_BIN)/setup-envtest --bin-dir $(TOOLS_BIN) use $(ENVTEST_K8S_VERSION)
# ----------------------------------------------------------------------------------------------------------------------
# Executes the Go end-to-end tests that require a k8s cluster using
# a LOCAL operator instance (i.e. the operator is not deployed to k8s).
# These tests will use whichever k8s cluster the local environment
# is pointing to.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: e2e-local-test
e2e-local-test: export CGO_ENABLED = 0
e2e-local-test: export OPERATOR_NAMESPACE := $(OPERATOR_NAMESPACE)
e2e-local-test: export CLUSTER_NAMESPACE := $(CLUSTER_NAMESPACE)
e2e-local-test: export OPERATOR_NAMESPACE_CLIENT := $(OPERATOR_NAMESPACE_CLIENT)
e2e-local-test: export BUILD_OUTPUT := $(BUILD_OUTPUT)
e2e-local-test: export TEST_APPLICATION_IMAGE := $(TEST_APPLICATION_IMAGE)
e2e-local-test: export TEST_APPLICATION_IMAGE_CLIENT := $(TEST_APPLICATION_IMAGE_CLIENT)
e2e-local-test: export TEST_APPLICATION_IMAGE_HELIDON := $(TEST_APPLICATION_IMAGE_HELIDON)
e2e-local-test: export TEST_APPLICATION_IMAGE_SPRING := $(TEST_APPLICATION_IMAGE_SPRING)
e2e-local-test: export TEST_APPLICATION_IMAGE_SPRING_FAT := $(TEST_APPLICATION_IMAGE_SPRING_FAT)
e2e-local-test: export TEST_APPLICATION_IMAGE_SPRING_CNBP := $(TEST_APPLICATION_IMAGE_SPRING_CNBP)
e2e-local-test: export TEST_COHERENCE_IMAGE := $(TEST_COHERENCE_IMAGE)
e2e-local-test: export IMAGE_PULL_SECRETS := $(IMAGE_PULL_SECRETS)
e2e-local-test: export COH_SKIP_SITE := true
e2e-local-test: export TEST_IMAGE_PULL_POLICY := $(IMAGE_PULL_POLICY)
e2e-local-test: export TEST_STORAGE_CLASS := $(TEST_STORAGE_CLASS)
e2e-local-test: export GO_TEST_FLAGS_E2E := $(strip $(GO_TEST_FLAGS_E2E))
e2e-local-test: export TEST_ASSET_KUBECTL := $(TEST_ASSET_KUBECTL)
e2e-local-test: export LOCAL_STORAGE_RESTART := $(LOCAL_STORAGE_RESTART)
e2e-local-test: export VERSION := $(VERSION)
e2e-local-test: export MVN_VERSION := $(MVN_VERSION)
e2e-local-test: export OPERATOR_IMAGE := $(OPERATOR_IMAGE)
e2e-local-test: export COHERENCE_IMAGE := $(COHERENCE_IMAGE)
e2e-local-test: $(BUILD_TARGETS)/build-operator reset-namespace create-ssl-secrets install-crds gotestsum undeploy ## Run the Operator end-to-end 'local' functional tests using a local Operator instance
$(GOTESTSUM) --format standard-verbose --junitfile $(TEST_LOGS_DIR)/operator-e2e-local-test.xml \
-- $(GO_TEST_FLAGS_E2E) ./test/e2e/local/...
# ----------------------------------------------------------------------------------------------------------------------
# Executes the Go end-to-end tests that require a k8s cluster using
# a DEPLOYED operator instance (i.e. the operator Docker image is
# deployed to k8s). These tests will use whichever k8s cluster the
# local environment is pointing to.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: e2e-test
e2e-test: export MF = $(MAKEFLAGS)
e2e-test: prepare-e2e-test ## Run the Operator end-to-end 'remote' functional tests using an Operator deployed in k8s
$(MAKE) run-e2e-test $${MF} \
; rc=$$? \
; $(MAKE) undeploy $${MF} \
; $(MAKE) delete-namespace $${MF} \
; exit $$rc
.PHONY: prepare-e2e-test
prepare-e2e-test: $(BUILD_TARGETS)/build-operator reset-namespace create-ssl-secrets install-crds deploy-and-wait
.PHONY: run-e2e-test
run-e2e-test: export CGO_ENABLED = 0
run-e2e-test: export TEST_SSL_SECRET := $(TEST_SSL_SECRET)
run-e2e-test: export OPERATOR_NAMESPACE := $(OPERATOR_NAMESPACE)
run-e2e-test: export CLUSTER_NAMESPACE := $(CLUSTER_NAMESPACE)
run-e2e-test: export OPERATOR_NAMESPACE_CLIENT := $(OPERATOR_NAMESPACE_CLIENT)
run-e2e-test: export BUILD_OUTPUT := $(BUILD_OUTPUT)
run-e2e-test: export TEST_COHERENCE_IMAGE := $(TEST_COHERENCE_IMAGE)
run-e2e-test: export TEST_IMAGE_PULL_POLICY := $(IMAGE_PULL_POLICY)
run-e2e-test: export TEST_STORAGE_CLASS := $(TEST_STORAGE_CLASS)
run-e2e-test: export TEST_ASSET_KUBECTL := $(TEST_ASSET_KUBECTL)
run-e2e-test: export VERSION := $(VERSION)
run-e2e-test: export OPERATOR_IMAGE := $(OPERATOR_IMAGE)
run-e2e-test: export COHERENCE_IMAGE := $(COHERENCE_IMAGE)
run-e2e-test: export TEST_APPLICATION_IMAGE := $(TEST_APPLICATION_IMAGE)
run-e2e-test: export TEST_APPLICATION_IMAGE_CLIENT := $(TEST_APPLICATION_IMAGE_CLIENT)
run-e2e-test: export TEST_APPLICATION_IMAGE_HELIDON := $(TEST_APPLICATION_IMAGE_HELIDON)
run-e2e-test: export TEST_APPLICATION_IMAGE_SPRING := $(TEST_APPLICATION_IMAGE_SPRING)
run-e2e-test: export TEST_APPLICATION_IMAGE_SPRING_FAT := $(TEST_APPLICATION_IMAGE_SPRING_FAT)
run-e2e-test: export TEST_APPLICATION_IMAGE_SPRING_CNBP := $(TEST_APPLICATION_IMAGE_SPRING_CNBP)
run-e2e-test: gotestsum ## Run the Operator 'remote' end-to-end functional tests using an ALREADY DEPLOYED Operator
$(GOTESTSUM) --format standard-verbose --junitfile $(TEST_LOGS_DIR)/operator-e2e-test.xml \
-- $(GO_TEST_FLAGS_E2E) ./test/e2e/remote/...
# ----------------------------------------------------------------------------------------------------------------------
# Executes the Go end-to-end tests that require a K3d cluster using
# a LOCAL operator instance (i.e. the operator is not deployed to k8s).
# These tests will use whichever K3d cluster the local environment
# is pointing to.
# ----------------------------------------------------------------------------------------------------------------------