forked from oracle/coherence-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
1413 lines (1258 loc) · 71.8 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, 2020, 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.
# ----------------------------------------------------------------------------------------------------------------------
# The version of the Operator being build - this should be a valid SemVer format
VERSION ?= 3.1.1
# The operator version to use to run certification tests against
CERTIFICATION_VERSION ?= $(VERSION)
# A SPACE delimited list of previous Operator versions that are used to run the compatibility tests.
COMPATIBLE_VERSIONS = 3.0.0
# Capture the Git commit to add to the build information
GITCOMMIT ?= $(shell git rev-list -1 HEAD)
GITREPO := https://github.com/oracle/coherence-operator.git
BUILD_DATE := $(shell date -u | tr ' ' '.')
BUILD_INFO := "$(VERSION)|$(GITCOMMIT)|$(BUILD_DATE)"
CURRDIR := $(shell pwd)
ARCH ?= amd64
OS ?= linux
UNAME_S := $(shell uname -s)
GOPROXY ?= https://proxy.golang.org
# Set the location of the Operator SDK executable
UNAME_S = $(shell uname -s)
UNAME_M = $(shell uname -m)
OPERATOR_SDK_VERSION := v1.0.0
OPERATOR_SDK = $(CURRDIR)/hack/sdk/$(UNAME_S)-$(UNAME_M)/operator-sdk
# The Coherence image to use for deployments that do not specify an image
COHERENCE_IMAGE ?= oraclecoherence/coherence-ce:20.06.1
# 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)
# Operator image names
RELEASE_IMAGE_PREFIX ?= ghcr.io/oracle/
OPERATOR_IMAGE_REPO := $(RELEASE_IMAGE_PREFIX)coherence-operator
OPERATOR_IMAGE := $(OPERATOR_IMAGE_REPO):$(VERSION)
UTILS_IMAGE ?= $(OPERATOR_IMAGE_REPO):$(VERSION)-utils
# The Operator images to push
OPERATOR_RELEASE_REPO ?= $(OPERATOR_IMAGE_REPO)
OPERATOR_RELEASE_IMAGE := $(OPERATOR_RELEASE_REPO):$(VERSION)
UTILS_RELEASE_IMAGE := $(OPERATOR_RELEASE_REPO):$(VERSION)-utils
BUNDLE_RELEASE_IMAGE := $(OPERATOR_RELEASE_REPO):$(VERSION)-bundle
# The test application images used in integration tests
TEST_APPLICATION_IMAGE := $(RELEASE_IMAGE_PREFIX)operator-test:$(VERSION)
TEST_APPLICATION_IMAGE_SPRING := $(RELEASE_IMAGE_PREFIX)operator-test:$(VERSION)-spring
TEST_APPLICATION_IMAGE_SPRING_FAT := $(RELEASE_IMAGE_PREFIX)operator-test:$(VERSION)-spring-fat
TEST_APPLICATION_IMAGE_SPRING_CNBP := $(RELEASE_IMAGE_PREFIX)operator-test:$(VERSION)-spring-cnbp
# Default bundle image tag
BUNDLE_IMG ?= $(OPERATOR_IMAGE_REPO):$(VERSION)-bundle
# Options for 'bundle-build'
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# Release build options
RELEASE_DRY_RUN ?= true
PRE_RELEASE ?= true
# 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
.PHONY: jk
jk:
echo "GO_TEST_FLAGS=$(GO_TEST_FLAGS)"
echo "GO_TEST_FLAGS_E2E=$(GO_TEST_FLAGS_E2E)"
# default as in test/e2e/helper/proj_helpers.go
OPERATOR_NAMESPACE ?= operator-test
# 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
# Prometheus Operator settings (used in integration tests)
PROMETHEUS_INCLUDE_GRAFANA ?= true
PROMETHEUS_OPERATOR_VERSION ?= 8.13.7
PROMETHEUS_ADAPTER_VERSION ?= 2.5.0
GRAFANA_DASHBOARDS ?= dashboards/grafana-legacy/
# Elasticsearch & Kibana settings (used in integration tests)
ELASTIC_VERSION ?= 7.6.2
KIBANA_INDEX_PATTERN := "6abb1220-3feb-11e9-a9a3-4b1c09db6e6a"
# restart local storage for persistence
LOCAL_STORAGE_RESTART ?= false
# Env variables used to create pull secrets
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
IMAGE_PULL_POLICY ?= IfNotPresent
# Env variable used by the kubectl test framework to locate the kubectl binary
TEST_ASSET_KUBECTL ?= $(shell which kubectl)
override BUILD_OUTPUT := ./build/_output
override BUILD_ASSETS := $(BUILD_OUTPUT)/assets
override BUILD_BIN := ./bin
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-$(VERSION).tar.gz
override BUILD_PROPS := $(BUILD_OUTPUT)/build.properties
override BUILD_TARGETS := $(BUILD_OUTPUT)/targets
override TEST_LOGS_DIR := $(BUILD_OUTPUT)/test-logs
# 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
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_INFO = $(VERSION)|$(GITCOMMIT)|$(BUILD_DATE)
LDFLAGS = -X main.Version=$(VERSION) -X main.Commit=$(GITCOMMIT) -X main.Date=$(BUILD_DATE)
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)
CRDV1BETA1_FILES = $(shell find ./config/crd-v1beta1 -type f)
CRD_V1 ?= $(shell kubectl api-versions | grep '^apiextensions.k8s.io/v1$$')
TEST_SSL_SECRET := coherence-ssl-secret
.PHONY: all
all: build-all-images
# ----------------------------------------------------------------------------------------------------------------------
# Configure the build properties
# ----------------------------------------------------------------------------------------------------------------------
$(BUILD_PROPS):
# Ensures that build output directories exist
@echo "Creating build directories"
@mkdir -p $(BUILD_OUTPUT)
@mkdir -p $(BUILD_ASSETS)
@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)
# create build.properties
rm -f $(BUILD_PROPS)
printf "COHERENCE_IMAGE=$(COHERENCE_IMAGE)\n\
UTILS_IMAGE=$(UTILS_IMAGE)\n\
OPERATOR_IMAGE=$(OPERATOR_IMAGE)\n\
VERSION=$(VERSION)\n" > $(BUILD_PROPS)
# ----------------------------------------------------------------------------------------------------------------------
# Builds the Operator
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-operator
build-operator: $(BUILD_TARGETS)/build-operator
# ----------------------------------------------------------------------------------------------------------------------
# Build the Operator Image
# ----------------------------------------------------------------------------------------------------------------------
# We copy the Dockerfile to $(BUILD_OUTPUT) only so that we can use it as a conditional build dependency in this Makefile
$(BUILD_TARGETS)/build-operator: $(BUILD_BIN)/manager $(BUILD_BIN)/runner
docker build --build-arg version=$(VERSION) \
--build-arg coherence_image=$(COHERENCE_IMAGE) \
--build-arg utils_image=$(UTILS_IMAGE) \
. -t $(OPERATOR_IMAGE)
touch $(BUILD_TARGETS)/build-operator
# ----------------------------------------------------------------------------------------------------------------------
# Build the operator linux binary
# ----------------------------------------------------------------------------------------------------------------------
$(BUILD_BIN)/manager: $(BUILD_PROPS) $(GOS) generate manifests
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags "$(LDFLAGS)" -a -o $(BUILD_BIN)/manager main.go
# ----------------------------------------------------------------------------------------------------------------------
# Ensure Operator SDK is at the correct version
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: ensure-sdk
ensure-sdk:
@echo "Ensuring Operator SDK is present"
./hack/ensure-sdk.sh $(OPERATOR_SDK_VERSION)
# ----------------------------------------------------------------------------------------------------------------------
# Internal make step that builds the Operator runner artifacts utility
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-runner
build-runner: $(BUILD_BIN)/runner
$(BUILD_BIN)/runner: $(BUILD_PROPS) $(GOS)
@echo "Building Operator Runner"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags "$(LDFLAGS)" -o $(BUILD_BIN)/runner ./runner
# ----------------------------------------------------------------------------------------------------------------------
# Internal make step that builds the Operator legacy converter
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: converter
converter: $(BUILD_BIN)/converter $(BUILD_BIN)/converter-linux-amd64 $(BUILD_BIN)/converter-darwin-amd64 $(BUILD_BIN)/converter-windows-amd64
$(BUILD_BIN)/converter: $(BUILD_PROPS) $(GOS)
CGO_ENABLED=0 GO111MODULE=on GOOS=$(OS) GOARCH=$(ARCH) go build -o $(BUILD_BIN)/converter ./converter
$(BUILD_BIN)/converter-linux-amd64: $(BUILD_PROPS) $(GOS)
CGO_ENABLED=0 GO111MODULE=on GOOS=linux GOARCH=amd64 go build -o $(BUILD_BIN)/converter-linux-amd64 ./converter
$(BUILD_BIN)/converter-darwin-amd64: $(BUILD_PROPS) $(GOS)
CGO_ENABLED=0 GO111MODULE=on GOOS=darwin GOARCH=amd64 go build -o $(BUILD_BIN)/converter-darwin-amd64 ./converter
$(BUILD_BIN)/converter-windows-amd64: $(BUILD_PROPS) $(GOS)
CGO_ENABLED=0 GO111MODULE=on GOOS=windows GOARCH=amd64 go build -o $(BUILD_BIN)/converter-windows-amd64 ./converter
# ----------------------------------------------------------------------------------------------------------------------
# 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 UTILS_IMAGE := $(UTILS_IMAGE)
test-operator: $(BUILD_PROPS) $(BUILD_TARGETS)/manifests $(BUILD_TARGETS)/generate gotestsum
@echo "Running operator tests"
$(GOTESTSUM) --format standard-verbose --junitfile $(TEST_LOGS_DIR)/operator-test.xml \
-- $(GO_TEST_FLAGS) -v ./api/... ./controllers/... ./pkg/...
# ----------------------------------------------------------------------------------------------------------------------
# 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 TEST_APPLICATION_IMAGE := $(TEST_APPLICATION_IMAGE)
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 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 OPERATOR_IMAGE := $(OPERATOR_IMAGE)
e2e-local-test: export COHERENCE_IMAGE := $(COHERENCE_IMAGE)
e2e-local-test: export UTILS_IMAGE := $(UTILS_IMAGE)
e2e-local-test: $(BUILD_TARGETS)/build-operator reset-namespace create-ssl-secrets install-crds gotestsum
$(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
$(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
.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 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 UTILS_IMAGE := $(UTILS_IMAGE)
run-e2e-test: export TEST_APPLICATION_IMAGE := $(TEST_APPLICATION_IMAGE)
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
$(GOTESTSUM) --format standard-verbose --junitfile $(TEST_LOGS_DIR)/operator-e2e-test.xml \
-- $(GO_TEST_FLAGS_E2E) ./test/e2e/remote/...
# ----------------------------------------------------------------------------------------------------------------------
# Run the end-to-end Helm chart tests.
# ----------------------------------------------------------------------------------------------------------------------
e2e-helm-test: export OPERATOR_IMAGE := $(OPERATOR_IMAGE)
e2e-helm-test: export UTILS_IMAGE := $(UTILS_IMAGE)
e2e-helm-test: $(BUILD_PROPS) $(BUILD_HELM)/coherence-operator-$(VERSION).tgz reset-namespace gotestsum
$(GOTESTSUM) --format standard-verbose --junitfile $(TEST_LOGS_DIR)/operator-e2e-helm-test.xml \
-- $(GO_TEST_FLAGS_E2E) ./test/e2e/helm/...
# ----------------------------------------------------------------------------------------------------------------------
# Executes the Go end-to-end tests that require Prometheus in the k8s cluster
# using a LOCAL operator instance (i.e. the operator is not deployed to k8s).
#
# This target DOES NOT install Prometheus, use the e2e-prometheus-test target
# to fully reset the test namespace.
#
# These tests will use whichever k8s cluster the local environment
# is pointing to.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: e2e-prometheus-test
e2e-prometheus-test: export MF = $(MAKEFLAGS)
e2e-prometheus-test: reset-namespace install-prometheus $(BUILD_TARGETS)/build-operator create-ssl-secrets install-crds deploy
$(MAKE) run-prometheus-test $${MF} \
; rc=$$? \
; $(MAKE) uninstall-prometheus $${MF} \
; $(MAKE) undeploy $${MF} \
; $(MAKE) delete-namespace $${MF} \
; exit $$rc
.PHONY: run-prometheus-test
run-prometheus-test: export CGO_ENABLED = 0
run-prometheus-test: export OPERATOR_NAMESPACE := $(OPERATOR_NAMESPACE)
run-prometheus-test: export TEST_APPLICATION_IMAGE := $(TEST_APPLICATION_IMAGE)
run-prometheus-test: export TEST_APPLICATION_IMAGE_SPRING := $(TEST_APPLICATION_IMAGE_SPRING)
run-prometheus-test: export TEST_APPLICATION_IMAGE_SPRING_FAT := $(TEST_APPLICATION_IMAGE_SPRING_FAT)
run-prometheus-test: export TEST_APPLICATION_IMAGE_SPRING_CNBP := $(TEST_APPLICATION_IMAGE_SPRING_CNBP)
run-prometheus-test: export TEST_COHERENCE_IMAGE := $(TEST_COHERENCE_IMAGE)
run-prometheus-test: export IMAGE_PULL_SECRETS := $(IMAGE_PULL_SECRETS)
run-prometheus-test: export TEST_IMAGE_PULL_POLICY := $(IMAGE_PULL_POLICY)
run-prometheus-test: export TEST_STORAGE_CLASS := $(TEST_STORAGE_CLASS)
run-prometheus-test: export GO_TEST_FLAGS_E2E := $(strip $(GO_TEST_FLAGS_E2E))
run-prometheus-test: export TEST_ASSET_KUBECTL := $(TEST_ASSET_KUBECTL)
run-prometheus-test: export LOCAL_STORAGE_RESTART := $(LOCAL_STORAGE_RESTART)
run-prometheus-test: export VERSION := $(VERSION)
run-prometheus-test: export OPERATOR_IMAGE := $(OPERATOR_IMAGE)
run-prometheus-test: export COHERENCE_IMAGE := $(COHERENCE_IMAGE)
run-prometheus-test: export UTILS_IMAGE := $(UTILS_IMAGE)
run-prometheus-test: gotestsum
$(GOTESTSUM) --format standard-verbose --junitfile $(TEST_LOGS_DIR)/operator-e2e-prometheus-test.xml \
-- $(GO_TEST_FLAGS_E2E) ./test/e2e/prometheus/...
# ----------------------------------------------------------------------------------------------------------------------
# Executes the Go end-to-end tests that require Elasticsearch in the k8s cluster
# using a LOCAL operator instance (i.e. the operator is not deployed to k8s).
#
# This target DOES NOT install Elasticsearch, use the e2e-elastic-test target
# to fully reset the test namespace.
#
# These tests will use whichever k8s cluster the local environment
# is pointing to.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: e2e-elastic-test
e2e-elastic-test: export MF = $(MAKEFLAGS)
e2e-elastic-test: reset-namespace install-elastic $(BUILD_TARGETS)/build-operator create-ssl-secrets install-crds deploy
$(MAKE) run-elastic-test $${MF} \
; rc=$$? \
; $(MAKE) uninstall-elastic $${MF} \
; $(MAKE) undeploy $${MF} \
; $(MAKE) delete-namespace $${MF} \
; exit $$rc
.PHONY: run-elastic-test
run-elastic-test: export CGO_ENABLED = 0
run-elastic-test: export OPERATOR_NAMESPACE := $(OPERATOR_NAMESPACE)
run-elastic-test: export TEST_APPLICATION_IMAGE := $(TEST_APPLICATION_IMAGE)
run-elastic-test: export TEST_APPLICATION_IMAGE_SPRING := $(TEST_APPLICATION_IMAGE_SPRING)
run-elastic-test: export TEST_APPLICATION_IMAGE_SPRING_FAT := $(TEST_APPLICATION_IMAGE_SPRING_FAT)
run-elastic-test: export TEST_APPLICATION_IMAGE_SPRING_CNBP := $(TEST_APPLICATION_IMAGE_SPRING_CNBP)
run-elastic-test: export TEST_COHERENCE_IMAGE := $(TEST_COHERENCE_IMAGE)
run-elastic-test: export IMAGE_PULL_SECRETS := $(IMAGE_PULL_SECRETS)
run-elastic-test: export TEST_IMAGE_PULL_POLICY := $(IMAGE_PULL_POLICY)
run-elastic-test: export TEST_STORAGE_CLASS := $(TEST_STORAGE_CLASS)
run-elastic-test: export GO_TEST_FLAGS_E2E := $(strip $(GO_TEST_FLAGS_E2E))
run-elastic-test: export TEST_ASSET_KUBECTL := $(TEST_ASSET_KUBECTL)
run-elastic-test: export LOCAL_STORAGE_RESTART := $(LOCAL_STORAGE_RESTART)
run-elastic-test: export VERSION := $(VERSION)
run-elastic-test: export OPERATOR_IMAGE := $(OPERATOR_IMAGE)
run-elastic-test: export COHERENCE_IMAGE := $(COHERENCE_IMAGE)
run-elastic-test: export UTILS_IMAGE := $(UTILS_IMAGE)
run-elastic-test: export KIBANA_INDEX_PATTERN := $(KIBANA_INDEX_PATTERN)
run-elastic-test: gotestsum
$(GOTESTSUM) --format standard-verbose --junitfile $(TEST_LOGS_DIR)/operator-e2e-elastic-test.xml \
-- $(GO_TEST_FLAGS_E2E) ./test/e2e/elastic/...
# ----------------------------------------------------------------------------------------------------------------------
# Executes the Go end-to-end Operator Compatibility tests.
# These tests will use whichever k8s cluster the local environment is pointing to.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: compatibility-test
compatibility-test: export CGO_ENABLED = 0
compatibility-test: export OPERATOR_NAMESPACE := $(OPERATOR_NAMESPACE)
compatibility-test: export TEST_APPLICATION_IMAGE := $(TEST_APPLICATION_IMAGE)
compatibility-test: export TEST_APPLICATION_IMAGE_SPRING := $(TEST_APPLICATION_IMAGE_SPRING)
compatibility-test: export TEST_APPLICATION_IMAGE_SPRING_FAT := $(TEST_APPLICATION_IMAGE_SPRING_FAT)
compatibility-test: export TEST_APPLICATION_IMAGE_SPRING_CNBP := $(TEST_APPLICATION_IMAGE_SPRING_CNBP)
compatibility-test: export TEST_COHERENCE_IMAGE := $(TEST_COHERENCE_IMAGE)
compatibility-test: export IMAGE_PULL_SECRETS := $(IMAGE_PULL_SECRETS)
compatibility-test: export TEST_SSL_SECRET := $(TEST_SSL_SECRET)
compatibility-test: export TEST_IMAGE_PULL_POLICY := $(IMAGE_PULL_POLICY)
compatibility-test: export TEST_STORAGE_CLASS := $(TEST_STORAGE_CLASS)
compatibility-test: export VERSION := $(VERSION)
compatibility-test: export COMPATIBLE_VERSIONS := $(COMPATIBLE_VERSIONS)
compatibility-test: export OPERATOR_IMAGE := $(OPERATOR_IMAGE)
compatibility-test: export COHERENCE_IMAGE := $(COHERENCE_IMAGE)
compatibility-test: export UTILS_IMAGE := $(UTILS_IMAGE)
compatibility-test: export GO_TEST_FLAGS_E2E := $(strip $(GO_TEST_FLAGS_E2E))
compatibility-test: $(BUILD_TARGETS)/build-operator clean-namespace reset-namespace create-ssl-secrets gotestsum
$(GOTESTSUM) --format standard-verbose --junitfile $(TEST_LOGS_DIR)/operator-e2e-compatibility-test.xml \
-- $(GO_TEST_FLAGS_E2E) ./test/compatibility/...
# ----------------------------------------------------------------------------------------------------------------------
# Executes the Go end-to-end Operator certification tests.
# These tests will use whichever k8s cluster the local environment is pointing to.
# Note that the namespace will be created if it does not exist.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: certification-test
certification-test: export MF = $(MAKEFLAGS)
certification-test: install-certification
$(MAKE) run-certification $${MF} \
; rc=$$? \
; $(MAKE) cleanup-certification $${MF} \
; exit $$rc
# ----------------------------------------------------------------------------------------------------------------------
# Install the Operator prior to running compatability tests.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: install-certification
install-certification: $(BUILD_TARGETS)/build-operator reset-namespace create-ssl-secrets deploy
# ----------------------------------------------------------------------------------------------------------------------
# Executes the Go end-to-end Operator certification tests.
# These tests will use whichever k8s cluster the local environment is pointing to.
# Note that the namespace will be created if it does not exist.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: run-certification
run-certification: export CGO_ENABLED = 0
run-certification: export OPERATOR_NAMESPACE := $(OPERATOR_NAMESPACE)
run-certification: export TEST_APPLICATION_IMAGE := $(TEST_APPLICATION_IMAGE)
run-certification: export TEST_APPLICATION_IMAGE_SPRING := $(TEST_APPLICATION_IMAGE_SPRING)
run-certification: export TEST_APPLICATION_IMAGE_SPRING_FAT := $(TEST_APPLICATION_IMAGE_SPRING_FAT)
run-certification: export TEST_APPLICATION_IMAGE_SPRING_CNBP := $(TEST_APPLICATION_IMAGE_SPRING_CNBP)
run-certification: export TEST_COHERENCE_IMAGE := $(TEST_COHERENCE_IMAGE)
run-certification: export IMAGE_PULL_SECRETS := $(IMAGE_PULL_SECRETS)
run-certification: export TEST_SSL_SECRET := $(TEST_SSL_SECRET)
run-certification: export TEST_IMAGE_PULL_POLICY := $(IMAGE_PULL_POLICY)
run-certification: export TEST_STORAGE_CLASS := $(TEST_STORAGE_CLASS)
run-certification: export VERSION := $(VERSION)
run-certification: export CERTIFICATION_VERSION := $(CERTIFICATION_VERSION)
run-certification: export OPERATOR_IMAGE_REPO := $(OPERATOR_IMAGE_REPO)
run-certification: export OPERATOR_IMAGE := $(OPERATOR_IMAGE)
run-certification: export COHERENCE_IMAGE := $(COHERENCE_IMAGE)
run-certification: export UTILS_IMAGE := $(UTILS_IMAGE)
run-certification: gotestsum
$(GOTESTSUM) --format standard-verbose --junitfile $(TEST_LOGS_DIR)/operator-e2e-certification-test.xml \
-- $(GO_TEST_FLAGS_E2E) ./test/certification/...
# ----------------------------------------------------------------------------------------------------------------------
# Clean up after to running compatability tests.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: cleanup-certification
cleanup-certification: undeploy uninstall-crds clean-namespace
# ---------------------------------------------------------------------------
# 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_HELM)/coherence-operator-$(VERSION).tgz: $(BUILD_PROPS) $(HELM_FILES) generate $(BUILD_TARGETS)/manifests $(GOBIN)/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,coherence-operator/Chart.yaml coherence-operator/values.yaml 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="$(BUILD_HELM)/$${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
# ----------------------------------------------------------------------------------------------------------------------
# Install CRDs into Kubernetes.
# This step will use whatever Kubeconfig the current environment is
# configured to use.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: install-crds
install-crds: prepare-deploy uninstall-crds
ifeq ("$(CRD_V1)","apiextensions.k8s.io/v1")
$(GOBIN)/kustomize build $(BUILD_DEPLOY)/crd | kubectl create -f -
else
$(GOBIN)/kustomize build $(BUILD_DEPLOY)/crd-v1beta1 | kubectl create -f --validate=false -
endif
# ----------------------------------------------------------------------------------------------------------------------
# Uninstall CRDs from Kubernetes.
# This step will use whatever Kubeconfig the current environment is
# configured to use.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: uninstall-crds
uninstall-crds: prepare-deploy
ifeq ("$(CRD_V1)","apiextensions.k8s.io/v1")
$(GOBIN)/kustomize build $(BUILD_DEPLOY)/crd | kubectl delete -f - || true
else
$(GOBIN)/kustomize build $(BUILD_DEPLOY)/crd-v1beta1 | kubectl delete -f - || true
endif
# ----------------------------------------------------------------------------------------------------------------------
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: deploy
deploy: prepare-deploy
ifneq (,$(WATCH_NAMESPACE))
cd $(BUILD_DEPLOY)/manager && $(GOBIN)/kustomize edit add configmap env-vars --from-literal WATCH_NAMESPACE=$(WATCH_NAMESPACE)
endif
kubectl -n $(OPERATOR_NAMESPACE) create secret generic coherence-webhook-server-cert || true
$(GOBIN)/kustomize build $(BUILD_DEPLOY)/default | kubectl apply -f -
.PHONY: prepare-deploy
prepare-deploy: manifests $(BUILD_TARGETS)/build-operator $(GOBIN)/kustomize
$(call prepare_deploy,$(OPERATOR_IMAGE),$(OPERATOR_NAMESPACE))
# ----------------------------------------------------------------------------------------------------------------------
# Prepare the deployment manifests - this is called by a number of other targets.
# Parameter #1 is the Operator Image Name
# Parameter #2 is the name of the namespace to deploy into
# ----------------------------------------------------------------------------------------------------------------------
define prepare_deploy
-rm -r $(BUILD_DEPLOY)
mkdir -p $(BUILD_DEPLOY)
cp -R config $(BUILD_OUTPUT)
cd $(BUILD_DEPLOY)/manager && $(GOBIN)/kustomize edit add configmap env-vars --from-literal COHERENCE_IMAGE=$(COHERENCE_IMAGE)
cd $(BUILD_DEPLOY)/manager && $(GOBIN)/kustomize edit add configmap env-vars --from-literal UTILS_IMAGE=$(UTILS_IMAGE)
cd $(BUILD_DEPLOY)/manager && $(GOBIN)/kustomize edit set image controller=$(1)
cd $(BUILD_DEPLOY)/default && $(GOBIN)/kustomize edit set namespace $(2)
endef
# ----------------------------------------------------------------------------------------------------------------------
# Un-deploy controller from the configured Kubernetes cluster in ~/.kube/config
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: undeploy
undeploy: $(BUILD_PROPS) $(BUILD_TARGETS)/manifests $(GOBIN)/kustomize
$(call prepare_deploy,$(OPERATOR_IMAGE),$(OPERATOR_NAMESPACE))
$(GOBIN)/kustomize build $(BUILD_DEPLOY)/default | kubectl delete -f -
kubectl -n $(OPERATOR_NAMESPACE) delete secret coherence-webhook-server-cert || true
# ----------------------------------------------------------------------------------------------------------------------
# Tail the deployed operator logs.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: tail-logs
tail-logs: export POD=$(shell kubectl -n $(OPERATOR_NAMESPACE) get pod -l component=coherence-operator -o name)
tail-logs:
kubectl -n $(OPERATOR_NAMESPACE) logs $(POD) -c manager -f
# ----------------------------------------------------------------------------------------------------------------------
# Generate manifests e.g. CRD, RBAC etc.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: manifests
manifests: $(BUILD_TARGETS)/manifests $(BUILD_MANIFESTS_PKG)
$(BUILD_MANIFESTS_PKG):
rm -rf $(BUILD_MANIFESTS) || true
mkdir -p $(BUILD_MANIFESTS)
cp -R config/default/ $(BUILD_MANIFESTS)/default
cp -R config/manager/ $(BUILD_MANIFESTS)/manager
cp -R config/rbac/ $(BUILD_MANIFESTS)/rbac
tar -C $(BUILD_OUTPUT) -czf $(BUILD_MANIFESTS_PKG) manifests/
$(BUILD_TARGETS)/manifests: $(BUILD_PROPS) config/crd/bases/coherence.oracle.com_coherences.yaml config/crd-v1beta1/bases/coherence.oracle.com_coherences.yaml docs/about/04_coherence_spec.adoc
touch $(BUILD_TARGETS)/manifests
config/crd/bases/coherence.oracle.com_coherences.yaml: $(API_GO_FILES) $(GOBIN)/controller-gen
$(GOBIN)/controller-gen "crd:trivialVersions=true,crdVersions={v1}" \
rbac:roleName=manager-role paths="{./api/...,./controllers/...}" \
output:crd:artifacts:config=config/crd/bases
config/crd-v1beta1/bases/coherence.oracle.com_coherences.yaml: $(API_GO_FILES) $(GOBIN)/controller-gen
@echo "Generating CRD v1beta1"
$(GOBIN)/controller-gen "crd:trivialVersions=true,crdVersions={v1beta1}" \
rbac:roleName=manager-role paths="{./api/...,./controllers/...}" \
output:crd:artifacts:config=config/crd-v1beta1/bases
# ----------------------------------------------------------------------------------------------------------------------
# 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 \
\"utils-image\": \"$(UTILS_RELEASE_IMAGE)\"\n}\n" > $(BUILD_OUTPUT)/config.json
# ----------------------------------------------------------------------------------------------------------------------
# Generate code, configuration and docs.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: generate
generate: $(BUILD_TARGETS)/generate
$(BUILD_TARGETS)/generate: $(BUILD_PROPS) $(BUILD_OUTPUT)/config.json api/v1/zz_generated.deepcopy.go pkg/data/zz_generated_assets.go
touch $(BUILD_TARGETS)/generate
api/v1/zz_generated.deepcopy.go: $(API_GO_FILES) $(GOBIN)/controller-gen
$(GOBIN)/controller-gen object:headerFile="./hack/boilerplate.go.txt" paths="./api/..."
pkg/data/zz_generated_assets.go: $(BUILD_OUTPUT)/config.json $(CRDV1_FILES) $(CRDV1BETA1_FILES) $(GOBIN)/kustomize
echo "Embedding configuration and CRD files"
cp $(BUILD_OUTPUT)/config.json $(BUILD_ASSETS)/config.json
echo "Embedding v1 CRD files"
$(GOBIN)/kustomize build config/crd > $(BUILD_ASSETS)/crd_v1.yaml
echo "Embedding v1beat1 CRD files"
$(GOBIN)/kustomize build config/crd-v1beta1 > $(BUILD_ASSETS)/crd_v1beta1.yaml
go get -u github.com/shurcooL/vfsgen
go run ./pkg/generate/assets_generate.go
# ----------------------------------------------------------------------------------------------------------------------
# find or download controller-gen
# ----------------------------------------------------------------------------------------------------------------------
$(GOBIN)/controller-gen:
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
# ----------------------------------------------------------------------------------------------------------------------
# find or download kustomize
# ----------------------------------------------------------------------------------------------------------------------
$(GOBIN)/kustomize:
@{ \
set -e ;\
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
# ----------------------------------------------------------------------------------------------------------------------
# find or download gotestsum
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: gotestsum
gotestsum:
ifeq (, $(shell which gotestsum))
@{ \
set -e ;\
GOTESTSUM_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$GOTESTSUM_GEN_TMP_DIR ;\
go mod init tmp ;\
go get gotest.tools/[email protected] ;\
rm -rf $$GOTESTSUM_GEN_TMP_DIR ;\
}
GOTESTSUM=$(GOBIN)/gotestsum
else
GOTESTSUM=$(shell which gotestsum)
endif
# ----------------------------------------------------------------------------------------------------------------------
# find or download yq
# ----------------------------------------------------------------------------------------------------------------------
$(GOBIN)/yq:
@{ \
set -e ;\
YQ_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$YQ_GEN_TMP_DIR ;\
go mod init tmp ;\
go get github.com/mikefarah/yq/v3 ;\
rm -rf $$YQ_GEN_TMP_DIR ;\
}
YQ=$(GOBIN)/yq
# ----------------------------------------------------------------------------------------------------------------------
# Generate bundle manifests and metadata, then validate generated files.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: bundle
bundle: $(BUILD_PROPS) $(GOBIN)/kustomize $(BUILD_TARGETS)/manifests
$(OPERATOR_SDK) generate kustomize manifests -q
cd config/manager && $(GOBIN)/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
# ----------------------------------------------------------------------------------------------------------------------
# Build the bundle image.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: bundle-build
bundle-build:
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
# ----------------------------------------------------------------------------------------------------------------------
# Generate API docs
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: api-doc-gen
api-doc-gen: docs/about/04_coherence_spec.adoc
docs/about/04_coherence_spec.adoc: $(API_GO_FILES)
@echo "Generating CRD Doc"
go run ./docgen/ \
api/v1/coherenceresourcespec_types.go \
api/v1/coherence_types.go \
api/v1/coherenceresource_types.go \
> docs/about/04_coherence_spec.adoc
# ----------------------------------------------------------------------------------------------------------------------
# Clean-up all of the build artifacts
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: clean
clean:
-rm -rf build/_output
-rm -f bin/*
rm pkg/data/zz_generated_assets.go || true
mvn $(USE_MAVEN_SETTINGS) -f java clean
mvn $(USE_MAVEN_SETTINGS) -f examples clean
# ----------------------------------------------------------------------------------------------------------------------
# Generate the keys and certs used in tests.
# ----------------------------------------------------------------------------------------------------------------------
$(BUILD_OUTPUT)/certs:
@echo "Generating test keys and certs"
./hack/keys.sh
# ----------------------------------------------------------------------------------------------------------------------
# Delete and re-create the test namespace
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: reset-namespace
reset-namespace: export KUBECONFIG_PATH := $(KUBECONFIG_PATH)
reset-namespace: export DOCKER_SERVER := $(DOCKER_SERVER)
reset-namespace: export DOCKER_USERNAME := $(DOCKER_USERNAME)
reset-namespace: export DOCKER_PASSWORD := $(DOCKER_PASSWORD)
reset-namespace: export OCR_DOCKER_USERNAME := $(OCR_DOCKER_USERNAME)
reset-namespace: export OCR_DOCKER_PASSWORD := $(OCR_DOCKER_PASSWORD)
reset-namespace: delete-namespace
ifeq ($(CREATE_OPERATOR_NAMESPACE),true)
@echo "Creating test namespace $(OPERATOR_NAMESPACE)"
kubectl create namespace $(OPERATOR_NAMESPACE)
endif
ifneq ($(DOCKER_SERVER),)
@echo "Creating pull secrets for $(DOCKER_SERVER)"
kubectl create secret docker-registry coherence-k8s-operator-development-secret \
--namespace $(OPERATOR_NAMESPACE) \
--docker-server "$(DOCKER_SERVER)" \
--docker-username "$(DOCKER_USERNAME)" \
--docker-password "$(DOCKER_PASSWORD)" \
--docker-email="[email protected]"
endif
ifneq ("$(or $(OCR_DOCKER_USERNAME),$(OCR_DOCKER_PASSWORD))","")
@echo "Creating pull secrets for container-registry.oracle.com"
kubectl create secret docker-registry ocr-k8s-operator-development-secret \
--namespace $(OPERATOR_NAMESPACE) \
--docker-server container-registry.oracle.com \
--docker-username "$(OCR_DOCKER_USERNAME)" \
--docker-password "$(OCR_DOCKER_PASSWORD)" \
--docker-email "[email protected]"
endif
# ----------------------------------------------------------------------------------------------------------------------
# Delete the test namespace
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: delete-namespace
delete-namespace: clean-namespace
ifeq ($(CREATE_OPERATOR_NAMESPACE),true)
@echo "Deleting test namespace $(OPERATOR_NAMESPACE)"
kubectl delete namespace $(OPERATOR_NAMESPACE) --force --grace-period=0 && echo "deleted namespace" || true
endif
kubectl delete clusterrole operator-test-coherence-operator --force --grace-period=0 && echo "deleted namespace" || true
kubectl delete clusterrolebinding operator-test-coherence-operator --force --grace-period=0 && echo "deleted namespace" || true
# ----------------------------------------------------------------------------------------------------------------------
# Delete all resource from the test namespace
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: clean-namespace
clean-namespace: delete-coherence-clusters
for i in $$(kubectl -n $(OPERATOR_NAMESPACE) get all -o name); do \
echo "Deleting $${i} from test namespace $(OPERATOR_NAMESPACE)" \
kubectl -n $(OPERATOR_NAMESPACE) delete $${i}; \
done
# ----------------------------------------------------------------------------------------------------------------------
# Create the k8s secret to use in SSL/TLS testing.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: create-ssl-secrets
create-ssl-secrets: $(BUILD_OUTPUT)/certs
@echo "Deleting SSL secret $(TEST_SSL_SECRET)"
kubectl --namespace $(OPERATOR_NAMESPACE) delete secret $(TEST_SSL_SECRET) && echo "secret deleted" || true
@echo "Creating SSL secret $(TEST_SSL_SECRET)"
kubectl create secret generic $(TEST_SSL_SECRET) \
--namespace $(OPERATOR_NAMESPACE) \
--from-file=keystore.jks=build/_output/certs/icarus.jks \
--from-file=storepass.txt=build/_output/certs/storepassword.txt \
--from-file=keypass.txt=build/_output/certs/keypassword.txt \
--from-file=truststore.jks=build/_output/certs/truststore-guardians.jks \
--from-file=trustpass.txt=build/_output/certs/trustpassword.txt \
--from-file=operator.key=build/_output/certs/icarus.key \
--from-file=operator.crt=build/_output/certs/icarus.crt \
--from-file=operator-ca.crt=build/_output/certs/guardians-ca.crt
# ----------------------------------------------------------------------------------------------------------------------
# Build the Java artifacts
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-mvn
build-mvn:
mvn $(USE_MAVEN_SETTINGS) -B -f java package -DskipTests
# ----------------------------------------------------------------------------------------------------------------------
# Build and test the Java artifacts
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: test-mvn
test-mvn: build-mvn
mvn $(USE_MAVEN_SETTINGS) -B -f java verify
# ----------------------------------------------------------------------------------------------------------------------
# Build the examples
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-examples
build-examples:
mvn $(USE_MAVEN_SETTINGS) -B -f ./examples package -DskipTests -P docker
# ----------------------------------------------------------------------------------------------------------------------
# Build and test the examples
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: test-examples
test-examples: build-examples
mvn $(USE_MAVEN_SETTINGS) -B -f ./examples verify
# ----------------------------------------------------------------------------------------------------------------------
# Run all unit tests (both Go and Java)
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: test-all
test-all: test-mvn test-operator
# ----------------------------------------------------------------------------------------------------------------------
# Push the Operator Docker image
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: push-operator-image
push-operator-image: $(BUILD_TARGETS)/build-operator
ifeq ($(OPERATOR_RELEASE_IMAGE), $(OPERATOR_IMAGE))
@echo "Pushing $(OPERATOR_IMAGE)"
docker push $(OPERATOR_IMAGE)
else
@echo "Tagging $(OPERATOR_IMAGE) as $(OPERATOR_RELEASE_IMAGE)"
docker tag $(OPERATOR_IMAGE) $(OPERATOR_RELEASE_IMAGE)
@echo "Pushing $(OPERATOR_RELEASE_IMAGE)"
docker push $(OPERATOR_RELEASE_IMAGE)
endif
# ----------------------------------------------------------------------------------------------------------------------
# Build the Operator Utils Docker image
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-utils-image
build-utils-image: build-mvn $(BUILD_BIN)/runner
cp $(BUILD_BIN)/runner java/coherence-utils/target/docker/runner
docker build -t $(UTILS_IMAGE) java/coherence-utils/target/docker
# ----------------------------------------------------------------------------------------------------------------------
# Push the Operator Utils Docker image
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: push-utils-image
push-utils-image:
ifeq ($(UTILS_RELEASE_IMAGE), $(UTILS_IMAGE))
@echo "Pushing $(UTILS_IMAGE)"
docker push $(UTILS_IMAGE)
else
@echo "Tagging $(UTILS_IMAGE) as $(UTILS_RELEASE_IMAGE)"
docker tag $(UTILS_IMAGE) $(UTILS_RELEASE_IMAGE)
@echo "Pushing $(UTILS_RELEASE_IMAGE)"
docker push $(UTILS_RELEASE_IMAGE)
endif
# ----------------------------------------------------------------------------------------------------------------------
# Build the Operator Test images
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-test-images
build-test-images: build-mvn
mvn $(USE_MAVEN_SETTINGS) -B -f java/operator-test package jib:dockerBuild -DskipTests -Djib.to.image=$(TEST_APPLICATION_IMAGE)
mvn $(USE_MAVEN_SETTINGS) -B -f java/operator-test-spring package jib:dockerBuild -DskipTests -Djib.to.image=$(TEST_APPLICATION_IMAGE_SPRING)
mvn $(USE_MAVEN_SETTINGS) -B -f java/operator-test-spring package spring-boot:build-image -DskipTests -Dcnbp-image-name=$(TEST_APPLICATION_IMAGE_SPRING_CNBP)
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-$(VERSION).jar java/operator-test-spring/target/spring/operator-test-spring-$(VERSION).jar
cd java/operator-test-spring/target/spring && jar -xvf operator-test-spring-$(VERSION).jar && rm -f operator-test-spring-$(VERSION).jar
docker build -f java/operator-test-spring/target/Dir.Dockerfile -t $(TEST_APPLICATION_IMAGE_SPRING) java/operator-test-spring/target
# ----------------------------------------------------------------------------------------------------------------------
# Push the Operator JIB Test Docker images
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: push-test-images
push-test-images:
docker push $(TEST_APPLICATION_IMAGE)
docker push $(TEST_APPLICATION_IMAGE_SPRING)
docker push $(TEST_APPLICATION_IMAGE_SPRING_FAT)
docker push $(TEST_APPLICATION_IMAGE_SPRING_CNBP)
# ----------------------------------------------------------------------------------------------------------------------
# Build all of the Docker images
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-all-images
build-all-images: $(BUILD_TARGETS)/build-operator build-utils-image build-test-images
# ----------------------------------------------------------------------------------------------------------------------
# Push all of the Docker images
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: push-all-images
push-all-images: push-operator-image push-utils-image push-test-images
# ----------------------------------------------------------------------------------------------------------------------
# Push all of the Docker images that are released
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: push-release-images
push-release-images: push-operator-image push-utils-image
# ----------------------------------------------------------------------------------------------------------------------
# Run the Operator locally.
#