-
Notifications
You must be signed in to change notification settings - Fork 319
Expand file tree
/
Copy patholm.mk
More file actions
159 lines (133 loc) · 6.4 KB
/
Copy patholm.mk
File metadata and controls
159 lines (133 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
SHELL = /bin/sh
PLATFORM := $(shell uname | tr A-Z a-z)
ARCHITECTURE := $(shell uname -m)
ifeq ($(ARCHITECTURE),x86_64)
ARCHITECTURE=amd64
endif
ifeq ($(ARCHITECTURE),aarch64)
ARCHITECTURE=arm64
endif
.DEFAULT_GOAL := all
.PHONY: help
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%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
all::crd ## Default goal. Generates bundle manifests
all::rbac
all::deployment
all::olm-manifests
all::olm-release-config
.PHONY: all crd rbac deployment olm-manifests olm-release-config clean
OLM_DIR = $(CURDIR)/olm/manifests
$(OLM_DIR) :
mkdir -pv $@
crd: $(OLM_DIR) ## Generate CRD manifest
kustomize build config/crd > $(OLM_DIR)/rabbitmq.com_rabbitmqcluster.yaml
rbac: ## Extract RBAC rules to a temporary file
mkdir -p tmp/
yq '{"rules": .rules}' config/rbac/role.yaml > tmp/role-rules.yaml
QUAY_IO_OPERATOR_IMAGE ?= quay.io/rabbitmqoperator/cluster-operator:latest
deployment: ## Extract deployment spec. Customise using QUAY_IO_OPERATOR_IMAGE
mkdir -p tmp/
kustomize build config/installation/ | \
ytt -f- -f config/ytt/overlay-manager-image.yaml \
--data-value operator_image=$(QUAY_IO_OPERATOR_IMAGE) \
-f olm/templates/cluster-operator-namespace-scope-overlay.yml \
> tmp/cluster-operator.yml
yq 'select(.kind == "Deployment") | {"spec": .spec}' tmp/cluster-operator.yml > tmp/spec.yaml
BUNDLE_CREATED_AT ?= $(shell date +'%Y-%m-%dT%H:%M:%S')
BUNDLE_VERSION ?= 0.0.0
olm-manifests: $(OLM_DIR) ## Render bundle manifests. Customise version using BUNDLE_VERSION and BUNDLE_CREATED_AT
ytt -f $(CURDIR)/olm/templates/cluster-service-version-generator-openshift.yml \
--data-values-file $(CURDIR)/tmp/role-rules.yaml \
--data-values-file $(CURDIR)/tmp/spec.yaml \
--data-value name="rabbitmq-cluster-operator" \
--data-value createdAt="$(BUNDLE_CREATED_AT)" \
--data-value image="$(QUAY_IO_OPERATOR_IMAGE)" \
--data-value version="$(BUNDLE_VERSION)" \
--data-value replaces="$(BUNDLE_REPLACES)" \
> $(OLM_DIR)/rabbitmq-cluster-operator.clusterserviceversion.yaml
olm-release-config: $(OLM_DIR) ## Render release config manifests. Customise version using BUNDLE_VERSION and BUNDLE_CREATED_AT
ytt -f $(CURDIR)/olm/templates/release-config-template.yaml \
--data-value replaces="$(BUNDLE_REPLACES)" \
--data-values-file $(CURDIR)/olm/values-release.yaml \
> $(CURDIR)/olm/release-config.yaml
clean:
rm -f -v $(CURDIR)/olm/manifests/*.y*ml
###########
## Build ##
###########
CONTAINER ?= docker
REGISTRY ?= quay.io
IMAGE ?= rabbitmqoperator/rabbitmq-for-kubernetes-olm-cluster-operator:latest
BUNDLE_IMAGE = $(REGISTRY)/$(IMAGE)
.PHONY: docker-build docker-push
docker-build: ## Build bundle container. Customise using REGISTRY and IMAGE
$(CONTAINER) build -t $(BUNDLE_IMAGE) -f $(CURDIR)/olm/bundle.Dockerfile $(CURDIR)/olm
docker-push: ## Push bundle container. Customise using REGISTRY and IMAGE
$(CONTAINER) push $(BUNDLE_IMAGE)
#############
## Catalog ##
#############
# This is used in tests
CATALOG_DIR = $(CURDIR)/olm/catalog
$(CATALOG_DIR):
mkdir -p $@
.PHONY: catalog-*
catalog-replace-bundle: $(CATALOG_DIR) ## Generate catalog manifest. Customise using BUNDLE_IMAGE and BUNDLE_VERSION
ytt -f $(CURDIR)/olm/templates/catalog-template.yaml \
--data-value name="rabbitmq-cluster-operator" \
--data-value image="$(BUNDLE_IMAGE)" \
--data-value version="$(BUNDLE_VERSION)" \
> $(CATALOG_DIR)/catalog.yaml
CATALOG_IMAGE ?= rabbitmqoperator/test-catalog:latest
catalog-build: ## Build catalog image. Customise using REGISTRY and CATALOG_IMAGE
$(CONTAINER) build -t $(REGISTRY)/$(CATALOG_IMAGE) --label "quay.expires-after=48h" -f $(CURDIR)/olm/catalog.Dockerfile ./olm
catalog-push: ## Push catalog image. Customise using REGISTRY and CATALOG_IMAGE
$(CONTAINER) push $(REGISTRY)/$(CATALOG_IMAGE)
catalog-deploy: ## Deploy a catalog source to an existing k8s
kubectl apply -f $(CURDIR)/olm/assets/operator-group.yaml
ytt -f $(CURDIR)/olm/assets/catalog-source.yaml \
-f $(CURDIR)/olm/assets/catalog-source-overlay.yml \
--data-value image="$(REGISTRY)/$(CATALOG_IMAGE)" \
--data-value secret_name="$(DOCKER_REGISTRY_SECRET)" | kubectl apply -f-
kubectl apply -f $(CURDIR)/olm/assets/subscription.yaml
catalog-undeploy: ## Delete all catalog assets from k8s
kubectl delete -f $(CURDIR)/olm/assets/subscription.yaml --ignore-not-found
kubectl delete -f $(CURDIR)/olm/manifests/ --ignore-not-found
kubectl delete -f $(CURDIR)/olm/assets/operator-group.yaml --ignore-not-found
ytt -f $(CURDIR)/olm/assets/catalog-source.yaml \
-f $(CURDIR)/olm/assets/catalog-source-overlay.yml \
--data-value image="$(REGISTRY)/$(CATALOG_IMAGE)" \
--data-value secret_name="$(DOCKER_REGISTRY_SECRET)" | kubectl delete -f- --ignore-not-found
catalog-clean: ## Delete manifest files for catalog
rm -v -f $(CURDIR)/olm/catalog/*.y*ml
.PHONY: catalog-pull-secret
catalog-pull-secret: ## Create a docker registry secret and export it to ns-1 namespace
kubectl create namespace secrets --dry-run=client -o yaml | kubectl apply -f -
kubectl create namespace ns-1 --dry-run=client -o yaml | kubectl apply -f -
kubectl create secret docker-registry $(DOCKER_REGISTRY_SECRET) \
--docker-server=$(DOCKER_REGISTRY_SERVER) \
--docker-username=$(DOCKER_REGISTRY_USERNAME) \
--docker-password=$(DOCKER_REGISTRY_PASSWORD) \
--namespace secrets \
--dry-run=client -o yaml | kubectl apply -f -
echo "apiVersion: secretgen.carvel.dev/v1alpha1" > tmp/secret-export.yaml
echo "kind: SecretExport" >> tmp/secret-export.yaml
echo "metadata:" >> tmp/secret-export.yaml
echo " name: $(DOCKER_REGISTRY_SECRET)" >> tmp/secret-export.yaml
echo " namespace: secrets" >> tmp/secret-export.yaml
echo "spec:" >> tmp/secret-export.yaml
echo " toNamespace: ns-1" >> tmp/secret-export.yaml
echo "---" >> tmp/secret-export.yaml
echo "apiVersion: secretgen.carvel.dev/v1alpha1" >> tmp/secret-export.yaml
echo "kind: SecretImport" >> tmp/secret-export.yaml
echo "metadata:" >> tmp/secret-export.yaml
echo " name: $(DOCKER_REGISTRY_SECRET)" >> tmp/secret-export.yaml
echo " namespace: ns-1" >> tmp/secret-export.yaml
echo "spec:" >> tmp/secret-export.yaml
echo " fromNamespace: secrets" >> tmp/secret-export.yaml
kubectl apply -f tmp/secret-export.yaml
catalog-all::catalog-replace-bundle
catalog-all::catalog-build
catalog-all::catalog-push
catalog-all::catalog-deploy