forked from kabanero-io/kabanero-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·274 lines (225 loc) · 13.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
# The Docker image in format repository:tag. Repository may contain a remote reference.
# Override in order to customize
IMAGE ?= kabanero-operator:latest
REGISTRY_IMAGE ?= kabanero-operator-registry:latest
WEBHOOK_IMAGE ?= kabanero-operator-admission-webhook:latest
COLLECTION_CTRLR_IMAGE ?= kabanero-operator-collection-controller:latest
STACK_CTRLR_IMAGE ?= kabanero-operator-stack-controller:latest
# For integration testing
# INTERNAL_REGISTRY: the public facing registry url. Set TRUE to enable and find the default address, or manually set to address itself
# INTERNAL_REGISTRY_SVC: the internal service image pull address. If not set, set to the default
INTERNAL_REGISTRY ?=
INTERNAL_REGISTRY_SVC ?=
ifdef INTERNAL_REGISTRY
ifeq ($(INTERNAL_REGISTRY),TRUE)
INTERNAL_REGISTRY := $(shell kubectl get route default-route -n openshift-image-registry --template='{{ .spec.host }}')
ifndef INTERNAL_REGISTRY_SVC
INTERNAL_REGISTRY_SVC=image-registry.openshift-image-registry.svc:5000
endif
# Public registry references
IMAGE=${INTERNAL_REGISTRY}/kabanero/kabanero-operator:latest
REGISTRY_IMAGE=${INTERNAL_REGISTRY}/openshift-marketplace/kabanero-operator-registry:latest
WEBHOOK_IMAGE=${INTERNAL_REGISTRY}/kabanero/kabanero-operator-admission-webhook:latest
COLLECTION_CTRLR_IMAGE=${INTERNAL_REGISTRY}/kabanero/kabanero-operator-collection-controller:latest
STACK_CTRLR_IMAGE=${INTERNAL_REGISTRY}/kabanero/kabanero-operator-stack-controller:latest
# Internal service registry references
IMAGE_SVC=${INTERNAL_REGISTRY_SVC}/kabanero/kabanero-operator:latest
REGISTRY_IMAGE_SVC=${INTERNAL_REGISTRY_SVC}/openshift-marketplace/kabanero-operator-registry:latest
WEBHOOK_IMAGE_SVC=${INTERNAL_REGISTRY_SVC}/kabanero/kabanero-operator-admission-webhook:latest
COLLECTION_CTRLR_IMAGE_SVC=${INTERNAL_REGISTRY_SVC}/kabanero/kabanero-operator-collection-controller:latest
STACK_CTRLR_IMAGE_SVC=${INTERNAL_REGISTRY_SVC}/kabanero/kabanero-operator-stack-controller:latest
endif
endif
# Computed repository name (no tag) including repository host/path reference
REPOSITORY=$(firstword $(subst :, ,${IMAGE}))
REGISTRY_REPOSITORY=$(firstword $(subst :, ,${REGISTRY_IMAGE}))
WEBHOOK_REPOSITORY=$(firstword $(subst :, ,${WEBHOOK_IMAGE}))
COLLECTION_CTRLR_REPOSITORY=$(firstword $(subst :, ,${COLLECTION_CTRLR_IMAGE}))
STACK_CTRLR_REPOSITORY=$(firstword $(subst :, ,${STACK_CTRLR_IMAGE}))
# Current release (used for CSV management)
CURRENT_RELEASE=0.7.0
# OS detection
ifeq ($(OS),Windows_NT)
detected_OS := windows
else
detected_OS := $(shell uname)
ifeq ($(detected_OS),Darwin)
detected_OS := macos
endif
endif
.PHONY: build deploy deploy-olm build-image push-image int-test-install int-test-collections int-test-uninstall int-test-lifecycle
build: generate
GO111MODULE=on go install ./cmd/manager
GO111MODULE=on go install ./cmd/manager/collection
GO111MODULE=on go install ./cmd/manager/stack
GO111MODULE=on go install ./cmd/admission-webhook
build-image: generate
# These commands were taken from operator-sdk 0.8.1. The sdk did not let us
# pass the ldflags option. The advice from operator-sdk was to run the
# commands separately here.
# operator-sdk build ${IMAGE}
GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/_output/bin/kabanero-operator -gcflags "all=-trimpath=$(GOPATH)" -asmflags "all=-trimpath=$(GOPATH)" -ldflags "-X main.GitTag=$(TRAVIS_TAG) -X main.GitCommit=$(TRAVIS_COMMIT) -X main.GitRepoSlug=$(TRAVIS_REPO_SLUG) -X main.BuildDate=`date -u +%Y%m%d.%H%M%S`" github.com/kabanero-io/kabanero-operator/cmd/manager
GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/_output/bin/kabanero-operator-collection-controller -gcflags "all=-trimpath=$(GOPATH)" -asmflags "all=-trimpath=$(GOPATH)" -ldflags "-X main.GitTag=$(TRAVIS_TAG) -X main.GitCommit=$(TRAVIS_COMMIT) -X main.GitRepoSlug=$(TRAVIS_REPO_SLUG) -X main.BuildDate=`date -u +%Y%m%d.%H%M%S`" github.com/kabanero-io/kabanero-operator/cmd/manager/collection
GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/_output/bin/kabanero-operator-stack-controller -gcflags "all=-trimpath=$(GOPATH)" -asmflags "all=-trimpath=$(GOPATH)" -ldflags "-X main.GitTag=$(TRAVIS_TAG) -X main.GitCommit=$(TRAVIS_COMMIT) -X main.GitRepoSlug=$(TRAVIS_REPO_SLUG) -X main.BuildDate=`date -u +%Y%m%d.%H%M%S`" github.com/kabanero-io/kabanero-operator/cmd/manager/stack
GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/_output/bin/admission-webhook -gcflags "all=-trimpath=$(GOPATH)" -asmflags "all=-trimpath=$(GOPATH)" -ldflags "-X main.GitTag=$(TRAVIS_TAG) -X main.GitCommit=$(TRAVIS_COMMIT) -X main.GitRepoSlug=$(TRAVIS_REPO_SLUG) -X main.BuildDate=`date -u +%Y%m%d.%H%M%S`" github.com/kabanero-io/kabanero-operator/cmd/admission-webhook
docker build -f build/Dockerfile -t ${IMAGE} .
# Build the Kananero collection controller image.
docker build -f build/Dockerfile-collection-controller -t ${COLLECTION_CTRLR_IMAGE} .
# Build the Kananero stack controller image.
docker build -f build/Dockerfile-stack-controller -t ${STACK_CTRLR_IMAGE} .
# Build the admission webhook.
docker build -f build/Dockerfile-webhook -t ${WEBHOOK_IMAGE} .
# Build an OLM private registry for Kabanero
mkdir -p build/registry
cp LICENSE build/registry/LICENSE
cp -R registry/manifests build/registry/
cp registry/Dockerfile build/registry/Dockerfile
cp deploy/crds/kabanero.io_kabaneros_crd.yaml deploy/crds/kabanero.io_collections_crd.yaml deploy/crds/kabanero.io_stacks_crd.yaml build/registry/manifests/kabanero-operator/$(CURRENT_RELEASE)/
ifdef INTERNAL_REGISTRY
sed -e "s!kabanero/kabanero-operator:.*!${IMAGE_SVC}!" registry/manifests/kabanero-operator/$(CURRENT_RELEASE)/kabanero-operator.v$(CURRENT_RELEASE).clusterserviceversion.yaml > build/registry/manifests/kabanero-operator/$(CURRENT_RELEASE)/kabanero-operator.v$(CURRENT_RELEASE).clusterserviceversion.yaml
else
sed -e "s!kabanero/kabanero-operator:.*!${IMAGE}!" registry/manifests/kabanero-operator/$(CURRENT_RELEASE)/kabanero-operator.v$(CURRENT_RELEASE).clusterserviceversion.yaml > build/registry/manifests/kabanero-operator/$(CURRENT_RELEASE)/kabanero-operator.v$(CURRENT_RELEASE).clusterserviceversion.yaml
endif
docker build -t ${REGISTRY_IMAGE} -f build/registry/Dockerfile build/registry/
# If we're doing a Travis build, need to build a second image because the CSV
# in the registry image has to point to the tagged operator image.
ifdef TRAVIS_TAG
sed -e "s!kabanero/kabanero-operator:.*!${REPOSITORY}:${TRAVIS_TAG}!" registry/manifests/kabanero-operator/$(CURRENT_RELEASE)/kabanero-operator.v$(CURRENT_RELEASE).clusterserviceversion.yaml > build/registry/manifests/kabanero-operator/$(CURRENT_RELEASE)/kabanero-operator.v$(CURRENT_RELEASE).clusterserviceversion.yaml
docker build -t ${REGISTRY_REPOSITORY}:${TRAVIS_TAG} -f build/registry/Dockerfile build/registry/
endif
ifdef TRAVIS_BRANCH
sed -e "s!kabanero/kabanero-operator:.*!${REPOSITORY}:${TRAVIS_BRANCH}!" registry/manifests/kabanero-operator/$(CURRENT_RELEASE)/kabanero-operator.v$(CURRENT_RELEASE).clusterserviceversion.yaml > build/registry/manifests/kabanero-operator/$(CURRENT_RELEASE)/kabanero-operator.v$(CURRENT_RELEASE).clusterserviceversion.yaml
docker build -t ${REGISTRY_REPOSITORY}:${TRAVIS_BRANCH} -f build/registry/Dockerfile build/registry/
endif
rm -R build/registry
push-image:
ifneq "$(IMAGE)" "kabanero-operator:latest"
# Default push. Make sure the namespace is there in case using local registry
kubectl create namespace kabanero || true
docker push $(IMAGE)
docker push $(COLLECTION_CTRLR_IMAGE)
docker push $(STACK_CTRLR_IMAGE)
docker push $(REGISTRY_IMAGE)
docker push $(WEBHOOK_IMAGE)
ifdef TRAVIS_TAG
# This is a Travis tag build. Pushing using Docker tag TRAVIS_TAG
docker tag $(IMAGE) $(REPOSITORY):$(TRAVIS_TAG)
docker push $(REPOSITORY):$(TRAVIS_TAG)
docker tag $(WEBHOOK_IMAGE) $(WEBHOOK_REPOSITORY):$(TRAVIS_TAG)
docker push $(WEBHOOK_REPOSITORY):$(TRAVIS_TAG)
docker push $(REGISTRY_REPOSITORY):$(TRAVIS_TAG)
docker tag $(COLLECTION_CTRLR_IMAGE) $(COLLECTION_CTRLR_REPOSITORY):$(TRAVIS_TAG)
docker push $(COLLECTION_CTRLR_REPOSITORY):$(TRAVIS_TAG)
docker tag $(STACK_CTRLR_IMAGE) $(STACK_CTRLR_REPOSITORY):$(TRAVIS_TAG)
docker push $(STACK_CTRLR_REPOSITORY):$(TRAVIS_TAG)
endif
ifdef TRAVIS_BRANCH
# This is a Travis branch build. Pushing using Docker tag TRAVIS_BRANCH
docker tag $(IMAGE) $(REPOSITORY):$(TRAVIS_BRANCH)
docker push $(REPOSITORY):$(TRAVIS_BRANCH)
docker tag $(WEBHOOK_IMAGE) $(WEBHOOK_REPOSITORY):$(TRAVIS_BRANCH)
docker push $(WEBHOOK_REPOSITORY):$(TRAVIS_BRANCH)
docker push $(REGISTRY_REPOSITORY):$(TRAVIS_BRANCH)
docker tag $(COLLECTION_CTRLR_IMAGE) $(COLLECTION_CTRLR_REPOSITORY):$(TRAVIS_BRANCH)
docker push $(COLLECTION_CTRLR_REPOSITORY):$(TRAVIS_BRANCH)
docker tag $(STACK_CTRLR_IMAGE) $(STACK_CTRLR_REPOSITORY):$(TRAVIS_BRANCH)
docker push $(STACK_CTRLR_REPOSITORY):$(TRAVIS_BRANCH)
endif
endif
test:
GO111MODULE=on go test ./cmd/... ./pkg/...
format:
GO111MODULE=on go fmt ./cmd/... ./pkg/...
generate:
GO111MODULE=on operator-sdk generate k8s
# GO111MODULE=on operator-sdk generate openapi
GO111MODULE=on operator-sdk generate crds
GO111MODULE=on go generate ./pkg/assets
install:
kubectl config set-context $$(kubectl config current-context) --namespace=kabanero
kubectl apply -f deploy/crds/kabanero.io_kabaneros_crd.yaml
kubectl apply -f deploy/crds/kabanero.io_collections_crd.yaml
kubectl apply -f deploy/crds/kabanero.io_stacks_crd.yaml
deploy:
kubectl create namespace kabanero || true
ifneq "$(IMAGE)" "kabanero-operator:latest"
# By default there is no image pull policy for local image. However, for other images
# substitute current image name, and update the pull policy to always pull images.
sed -i.bak -e 's!imagePullPolicy: Never!imagePullPolicy: Always!' deploy/operator.yaml
sed -i.bak -e 's!image: kabanero-operator:latest!image: ${IMAGE}!' deploy/operator.yaml
endif
rm deploy/operator.yaml.bak || true
kubectl config set-context $$(kubectl config current-context) --namespace=kabanero
kubectl apply -f deploy/
deploy-olm:
kubectl create namespace kabanero || true
kubectl apply -f deploy/olm/
# Update deployment to correct image
ifdef INTERNAL_REGISTRY
sed -e "s!image: KABANERO_REGISTRY_IMAGE!image: ${REGISTRY_IMAGE_SVC}!" deploy/olm/01-catalog-source.yaml | kubectl apply -f -
else
sed -e "s!image: KABANERO_REGISTRY_IMAGE!image: ${REGISTRY_IMAGE}!" deploy/olm/01-catalog-source.yaml | kubectl apply -f -
endif
check: format build test
# Requires https://github.com/mitchellh/golicense
# Note that the tool currently fails when a license is not found. Since
# this is currently the case for several dependencies, the file must be
# inspected manually, and we append || true to the command.
dependency-report:
ifndef GITHUB_TOKEN
$(error GITHUB_TOKEN must be set to a PAT to run the license check)
endif
mkdir -p build/bin
curl -L https://github.com/mitchellh/golicense/releases/download/v0.2.0/golicense_0.2.0_$(detected_OS)_x86_64.tar.gz | tar -C build/bin -xzf - golicense
build/bin/golicense -plain ./license-rules.json build/_output/bin/admission-webhook build/_output/bin/kabanero-operator build/_output/bin/kabanero-operator-collection-controller build/_output/bin/kabanero-operator-stack-controller > 3RD_PARTY || true
rm build/bin/golicense
# Integration Tests
# Requires kube login context an existing cluster
# Requires internal registry with default route
# Requires jq
# Install Test
int-test-install: creds build-image push-image int-install int-config
creds:
tests/00-credentials.sh
int-install:
# Update deployment to correct image
ifdef INTERNAL_REGISTRY
sed -e "s!image: kabanero/kabanero-operator-registry:.*!image: ${REGISTRY_IMAGE_SVC}!" deploy/kabanero-subscriptions.yaml > /tmp/kabanero-subscriptions.yaml
else
sed -e "s!image: kabanero/kabanero-operator-registry:.*!image: ${REGISTRY_IMAGE}!" deploy/kabanero-subscriptions.yaml > /tmp/kabanero-subscriptions.yaml
endif
KABANERO_SUBSCRIPTIONS_YAML=/tmp/kabanero-subscriptions.yaml KABANERO_CUSTOMRESOURCES_YAML=deploy/kabanero-customresources.yaml deploy/install.sh
int-config:
# Update config to correct image
# Update config to correct image
ifdef INTERNAL_REGISTRY
sed -e "s!image: kabanero/kabanero-operator-admission-webhook:.*!image: ${WEBHOOK_IMAGE_SVC}!; s!image: kabanero/kabanero-operator-collection-controller:.*!image: ${COLLECTION_CTRLR_IMAGE_SVC}!; s!image: kabanero/kabanero-operator-stack-controller:.*!image: ${STACK_CTRLR_IMAGE_SVC}!" config/samples/full.yaml | kubectl -n kabanero apply -f -
else
sed -e "s!image: kabanero/kabanero-operator-admission-webhook:.*!image: ${WEBHOOK_IMAGE}!; s!image: kabanero/kabanero-operator-collection-controller:.*!image: ${COLLECTION_CTRLR_IMAGE}!; s!image: kabanero/kabanero-operator-stack-controller:.*!image: ${STACK_CTRLR_IMAGE}!" config/samples/full.yaml | kubectl -n kabanero apply -f -
endif
# Uninstall Test
int-test-uninstall: creds int-uninstall
int-uninstall:
KABANERO_SUBSCRIPTIONS_YAML=deploy/kabanero-subscriptions.yaml KABANERO_CUSTOMRESOURCES_YAML=deploy/kabanero-customresources.yaml deploy/uninstall.sh
# Stacks: Can be run in parallel ( -j ). Test manual pipeline run of stacks.
int-test-stacks: int-test-java-microprofile int-test-java-spring-boot2 int-test-nodejs int-test-nodejs-express int-test-java-openliberty
int-test-java-microprofile:
tests/10-java-microprofile.sh
int-test-java-spring-boot2:
tests/11-java-spring-boot2.sh
int-test-nodejs:
tests/12-nodejs.sh
int-test-nodejs-express:
tests/13-nodejs-express.sh
int-test-java-openliberty:
tests/14-java-openliberty.sh
# Lifecycle: Lifecycle of Kabanero, Stack and owned objects
int-test-lifecycle: int-test-delete-pipeline int-test-delete-stack int-test-update-index int-test-deactivate-stack
int-test-delete-pipeline:
tests/20-delete-pipeline.sh
int-test-delete-stack:
tests/21-delete-stack.sh
int-test-update-index:
tests/22-update-index.sh
int-test-deactivate-stack:
tests/23-deactivate-stack.sh