-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
149 lines (128 loc) · 7.21 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
SHELL := bash
.SHELLFLAGS = -ec
WTO_IMG ?= quay.io/wto/web-terminal-operator:next
BUNDLE_IMG ?= quay.io/wto/web-terminal-operator-metadata:next
INDEX_IMG ?= quay.io/wto/web-terminal-operator-index:next
GET_DIGEST_WITH ?= skopeo
DOCKER ?= docker
.ONESHELL:
ifndef VERBOSE
MAKEFLAGS += --silent
endif
include build/makefiles/controller.mk
include build/makefiles/version.mk
all: help
_print_vars:
echo "Current env vars:"
echo " WTO_IMG=$(WTO_IMG)"
echo " BUNDLE_IMG=$(BUNDLE_IMG)"
echo " INDEX_IMG=$(INDEX_IMG)"
### build: build the terminal bundle and index and push them to a docker registry
build: _print_vars _check_imgs_env _check_skopeo_installed
build/scripts/build_index_image.sh \
--bundle-image $(BUNDLE_IMG) \
--index-image $(INDEX_IMG) \
--container-tool $(DOCKER)
### export: export the bundles stored in the index to the exported-manifests folder
export: _print_vars _check_imgs_env
rm -rf ./generated/exported-manifests
# Export the bundles with the name web-terminal inside of $(INDEX_IMG)
# This command basic exports the index back into the old format
opm index export -c $(DOCKER) -f ./generated/exported-manifests -i $(INDEX_IMG) -o web-terminal
### register_catalogsource: creates the catalogsource to make the operator be available on the marketplace. Image referenced by INDEX_IMG must be pushed and publicly available
register_catalogsource: _print_vars _check_imgs_env _check_skopeo_installed
ifeq ($(GET_DIGEST_WITH),skopeo)
INDEX_DIGEST=$$(skopeo inspect docker://$(INDEX_IMG) | jq -r '.Digest')
INDEX_IMG=$(INDEX_IMG)
INDEX_IMG_DIGEST="$${INDEX_IMG%:*}@$${INDEX_DIGEST}"
else ifeq ($(GET_DIGEST_WITH),$(filter $(GET_DIGEST_WITH),podman docker))
$(GET_DIGEST_WITH) pull $(INDEX_IMG)
INDEX_IMG_DIGEST=$$($(GET_DIGEST_WITH) inspect $(INDEX_IMG) | jq ".[].RepoDigests[0]" -r)
else
echo "unsupported GET_DIGEST_WITH is configured"
exit 1
endif
# replace references of catalogsource img with your image
sed -i.bak -e "s|quay.io/wto/web-terminal-operator-index:next|$${INDEX_IMG_DIGEST}|g" ./catalog-source.yaml
echo ">>>>>>>catalogsource content:>>>>>>>"
cat ./catalog-source.yaml
echo ">>>>>>>end of content:>>>>>>>"
# use ';' to make sure we undo changes to catalog-source.yaml even if command fails.
oc apply -f ./catalog-source.yaml ; \
mv ./catalog-source.yaml.bak ./catalog-source.yaml
oc apply -f ./imageContentSourcePolicy.yaml
### unregister_catalogsource: unregister the catalogsource and delete the imageContentSourcePolicy
unregister_catalogsource:
oc delete catalogsource custom-web-terminal-catalog -n openshift-marketplace --ignore-not-found
oc delete imagecontentsourcepolicy web-terminal-brew-registry-mirror --ignore-not-found
### change the default controller image used in the ClusterServiceVersion file to a custom image specified by the WTO_IMG environment variable
_select_controller_image:
sed -i.bak \
-e "s|containerImage: .*:[^']*|containerImage: $${WTO_IMG}|g" \
-e "s|image: .*:[^']*|image: $${WTO_IMG}|g" \
./manifests/web-terminal.clusterserviceversion.yaml
rm ./manifests/web-terminal.clusterserviceversion.yaml.bak
### reset the controller image used in the ClusterServiceVersion file to the default image
_reset_controller_image:
sed -i.bak \
-e "s|containerImage: .*:[^']*|containerImage: quay.io/wto/web-terminal-operator:next|g" \
-e "s|image: .*:[^']*|image: quay.io/wto/web-terminal-operator:next|g" \
./manifests/web-terminal.clusterserviceversion.yaml
rm ./manifests/web-terminal.clusterserviceversion.yaml.bak
### Build the controller using the registry and tag from the WTO_IMG environment variable, change the reference for the controller image
### used in the ClusterServiceVersion to the WTO_IMG, build and push the bundle and index to a registry, reset the ClusterServiceVersion to its original state
build_custom_iib_image: build_controller_image _select_controller_image build _reset_controller_image
### build_install: build the catalog and create catalogsource and operator subscription on the cluster
build_install: _print_vars _select_controller_image build _reset_controller_image install
### install: creates catalog source along with operator subscription on the cluster
install: _print_vars register_catalogsource
oc apply -f ./operator-subscription.yaml
### uninstall: uninstalls the Web Terminal Operator Subscription and related ClusterServiceVersion
uninstall:
# 1. Ensure that all DevWorkspace Custom Resources are removed to avoid issues with finalizers
# make sure depending objects are clean up as well
kubectl delete devworkspaces.workspace.devfile.io --all-namespaces --all --wait
kubectl delete workspaceroutings.controller.devfile.io --all-namespaces --all --wait
kubectl delete components.controller.devfile.io --all-namespaces --all --wait
# 2. Uninstall the Operator
kubectl delete subscriptions.operators.coreos.com web-terminal -n openshift-operators --ignore-not-found
$(eval WTO_CSV := $(shell kubectl get csv -o=json | jq -r '[.items[] | select (.metadata.name | contains("web-terminal.v1"))][0].metadata.name'))
kubectl delete csv ${WTO_CSV} -n openshift-operators
# 3. Remove CRDs
kubectl delete customresourcedefinitions.apiextensions.k8s.io workspaceroutings.controller.devfile.io
kubectl delete customresourcedefinitions.apiextensions.k8s.io components.controller.devfile.io
kubectl delete customresourcedefinitions.apiextensions.k8s.io devworkspaces.workspace.devfile.io
# 4. Remove DevWorkspace Webhook Server Deployment itself
kubectl delete deployment/devworkspace-webhook-server -n openshift-operators
# 5. Remove lingering service, secrets, and configmaps
kubectl delete all --selector app.kubernetes.io/part-of=devworkspace-operator,app.kubernetes.io/name=devworkspace-webhook-server
kubectl delete serviceaccounts devworkspace-webhook-server -n openshift-operators
kubectl delete configmap devworkspace-controller -n openshift-operators
kubectl delete clusterrole devworkspace-webhook-server
kubectl delete clusterrolebinding devworkspace-webhook-server
# 6. Remove mutating/validating webhooks configuration
kubectl delete mutatingwebhookconfigurations controller.devfile.io
kubectl delete validatingwebhookconfigurations controller.devfile.io
_check_imgs_env:
ifndef BUNDLE_IMG
$(error "BUNDLE_IMG not set")
endif
ifndef INDEX_IMG
$(error "INDEX_IMG not set")
endif
_check_skopeo_installed:
ifeq ($(shell command -v skopeo 2> /dev/null),)
$(error "skopeo is required for building and deploying bundle, but is not installed")
endif
.PHONY: help
### help: print this message
help: Makefile
echo 'Available rules:'
sed -n 's/^### / /p' $(MAKEFILE_LIST) | awk 'BEGIN { FS=":" } { printf "%-34s -%s\n", $$1, $$2 }'
echo ''
echo 'Supported environment variables:'
echo ' WTO_IMG - The name of the controller image. Set to $(WTO_IMG)'
echo ' BUNDLE_IMG - The name of the olm registry bundle image. Set to $(BUNDLE_IMG)'
echo ' INDEX_IMG - The name of the olm registry index image. Set to $(INDEX_IMG)'
echo ' DOCKER - Container build tool to use for building containers (e.g. podman, docker). Set to $(DOCKER)'
echo ' GET_DIGEST_WITH - The tool name for obtaining an image didgest. Supported tools: skopeo, podman, docker'