Skip to content

Commit 0ee403b

Browse files
committed
olm: refactor to bundle generation
We are using a "generator" template and applying values on top, instead of using overlays to modify specific parts of the generator file. The Makefile is a new approach to script the commands, instead of using Python in the original OLM dedicated git repo. The future idea is to fold the OLM manifests repo into this one, for the specific bits of topology operator.
1 parent 9b0199a commit 0ee403b

16 files changed

+812
-2
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ testbin/
1010
bin/
1111
tmp/
1212
*.iml
13+
## OLM
14+
olm/bundle/crds
15+
olm/bundle/manifests
16+
olm/catalog/cool-catalog/

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ just-integration-tests: $(KUBEBUILDER_ASSETS)
104104
.PHONY: local-tests
105105
local-tests: unit-tests integration-tests ## Run all local tests (unit & integration)
106106

107+
SYSTEM_TEST_NS ?= rabbitmq-system
107108
.PHONY: system-tests
108109
system-tests: ## Run E2E tests using current context in ~/.kube/config. Expects cluster operator and topology operator to be installed in the cluster
109-
NAMESPACE="rabbitmq-system" $(GINKGO) --randomize-all -r $(GINKGO_EXTRA) system_tests/
110+
NAMESPACE="$(SYSTEM_TEST_NS)" $(GINKGO) --randomize-all -r $(GINKGO_EXTRA) system_tests/
110111

111112

112113
###################

config/webhook/service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v1
22
kind: Service
33
metadata:
4-
name: webhook-service
4+
name: messaging-topology-operator-webhook
55
namespace: system
66
spec:
77
ports:

olm/Makefile

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
SHELL = /bin/sh
2+
PLATFORM := $(shell uname | tr A-Z a-z)
3+
ARCHITECTURE := $(shell uname -m)
4+
ifeq ($(ARCHITECTURE),x86_64)
5+
ARCHITECTURE=amd64
6+
endif
7+
8+
ifeq ($(ARCHITECTURE),aarch64)
9+
ARCHITECTURE=arm64
10+
endif
11+
12+
REPO_ROOT := $(shell git rev-parse --show-toplevel)
13+
14+
.DEFAULT_GOAL := all
15+
16+
.PHONY: help
17+
help: ## Display this help.
18+
@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)
19+
20+
######################
21+
## Bundle manifests ##
22+
######################
23+
24+
.PHONY: all crds rbac deployment webhooks olm-manifests clean
25+
26+
OLM_MANIFEST_DIR = $(REPO_ROOT)/olm/bundle/manifests
27+
$(OLM_MANIFEST_DIR) :
28+
mkdir -pv $@
29+
30+
TMP_DIR := $(REPO_ROOT)/tmp
31+
$(TMP_DIR) :
32+
mkdir -pv $@
33+
34+
$(TMP_DIR)/_all_manifests.yaml: $(TMP_DIR)
35+
kustomize build $(REPO_ROOT)/config/installation/ > $(TMP_DIR)/_all_manifests.yaml
36+
37+
crds: $(TMP_DIR)/_all_manifests.yaml $(TMP_DIR)
38+
yq 'select(.kind == "CustomResourceDefinition")' -s '"rabbitmq.com_" + .spec.names.singular' $(TMP_DIR)/_all_manifests.yaml
39+
mv -v $(CURDIR)/rabbitmq.com_*.y*ml $(REPO_ROOT)/olm/bundle/manifests/
40+
41+
rbac: $(OLM_TMP_DIR) ## Extract RBAC rules to a temporary file
42+
yq '{"rules": .rules}' $(REPO_ROOT)/config/rbac/role.yaml > $(TMP_DIR)/role-rules.yaml
43+
44+
QUAY_IO_OPERATOR_IMAGE ?= quay.io/rabbitmqoperator/messaging-topology-operator:latest
45+
deployment: $(TMP_DIR)/_all_manifests.yaml $(TMP_DIR) ## Extract Deployment spec. Customise using QUAY_IO_OPERATOR_IMAGE
46+
kustomize build $(REPO_ROOT)/config/installation/ | \
47+
ytt -f- -f $(REPO_ROOT)/config/ytt_overlays/change_deployment_image.yml \
48+
--data-value operator_image=$(QUAY_IO_OPERATOR_IMAGE) \
49+
-f $(REPO_ROOT)/olm/bundle/templates/topology-operator-namespace-scope-overlay.yml \
50+
> $(TMP_DIR)/topology-operator.yml
51+
yq 'select(.kind =="Deployment") | {"spec": .spec}' $(TMP_DIR)/topology-operator.yml > $(TMP_DIR)/spec.yaml
52+
53+
webhooks: $(TMP_DIR)/_all_manifests.yaml $(TMP_DIR) ## Extract Web-hook manifests into a temporary file
54+
yq 'select(.kind =="ValidatingWebhookConfiguration") | {"webhooks": .webhooks}' $(TMP_DIR)/_all_manifests.yaml \
55+
> $(TMP_DIR)/_webhooks.yaml
56+
57+
BUNDLE_CREATED_AT ?= $(shell date +'%Y-%m-%dT%H:%M:%S')
58+
BUNDLE_VERSION ?= 0.0.0
59+
olm-manifests: $(OLM_MANIFEST_DIR) ## Render bundle manifests. Customise version using BUNDLE_VERSION and BUNDLE_CREATED_AT
60+
ytt -f $(REPO_ROOT)/olm/bundle/templates/topology-service-version-generator-openshift.yml \
61+
--data-values-file $(TMP_DIR)/role-rules.yaml \
62+
--data-values-file $(TMP_DIR)/spec.yaml \
63+
--data-values-file $(TMP_DIR)/_webhooks.yaml \
64+
--data-value name="rabbitmq-messaging-topology-operator" \
65+
--data-value createdAt="$(BUNDLE_CREATED_AT)" \
66+
--data-value image="$(QUAY_IO_OPERATOR_IMAGE)" \
67+
--data-value version="$(BUNDLE_VERSION)" \
68+
--data-value replaces="$(BUNDLE_REPLACES)" \
69+
> $(OLM_MANIFEST_DIR)/rabbitmq-messaging-topology-operator.clusterserviceversion.yaml
70+
71+
all::crds ## Default goal. Generates bundle manifests
72+
all::rbac
73+
all::deployment
74+
all::webhooks
75+
all::olm-manifests
76+
77+
clean:
78+
rm -f -v $(REPO_ROOT)/olm/bundle/manifests/*.y*ml
79+
rm -f -v $(REPO_ROOT)/olm/bundle/crds/*.y*ml
80+
81+
###########
82+
## Build ##
83+
###########
84+
85+
CONTAINER ?= docker
86+
REGISTRY ?= quay.io
87+
IMAGE ?= rabbitmqoperator/rabbitmq-for-kubernetes-olm-messaging-topology-operator:latest
88+
BUNDLE_IMAGE = $(REGISTRY)/$(IMAGE)
89+
90+
.PHONY: docker-build docker-push
91+
docker-build: ## Build bundle container. Customise using REGISTRY and IMAGE
92+
$(CONTAINER) build -t $(BUNDLE_IMAGE) -f $(REPO_ROOT)/olm/bundle/bundle.Dockerfile $(REPO_ROOT)/olm/bundle
93+
94+
docker-push: ## Push bundle container. Customise using REGISTRY and IMAGE
95+
$(CONTAINER) push $(BUNDLE_IMAGE)
96+
97+
#############
98+
## Catalog ##
99+
#############
100+
# This is used in tests
101+
102+
CATALOG_DIR = $(REPO_ROOT)/olm/catalog/cool-catalog/rabbitmq-messaging-topology-operator
103+
$(CATALOG_DIR):
104+
mkdir -p $@
105+
106+
CO_CATALOG_DIR = $(REPO_ROOT)/olm/catalog/cool-catalog/rabbitmq-cluster-operator
107+
$(CO_CATALOG_DIR) :
108+
mkdir -p $@
109+
110+
# Cluster Operator related variables
111+
# Cluster Op is required here because it's a dependency of the top-op
112+
CO_BUNDLE_NAME ?= rabbitmq-cluster-operator
113+
CO_BUNDLE_VERSION ?= 2.15.0
114+
CO_BUNDLE_IMAGE ?= quay.io/rabbitmqoperator/rabbitmq-for-kubernetes-olm-cluster-operator:$(CO_BUNDLE_VERSION)
115+
.PHONY: catalog-*
116+
catalog-replace-bundle: $(CATALOG_DIR) ## Generate catalog manifest. Customise using BUNDLE_IMAGE and BUNDLE_VERSION
117+
ytt -f $(REPO_ROOT)/olm/catalog/templates/catalog-template.yaml \
118+
--data-value name="rabbitmq-messaging-topology-operator" \
119+
--data-value image="$(BUNDLE_IMAGE)" \
120+
--data-value version="$(BUNDLE_VERSION)" \
121+
> $(CATALOG_DIR)/catalog.yaml
122+
ytt -f $(REPO_ROOT)/olm/catalog/templates/catalog-co-template.yaml \
123+
--data-value cluster_operator_name="$(CO_BUNDLE_NAME)" \
124+
--data-value cluster_operator_version="$(CO_BUNDLE_VERSION)" \
125+
--data-value cluster_operator_image="$(CO_BUNDLE_IMAGE)" \
126+
> $(CO_CATALOG_DIR)/catalog.yaml
127+
128+
CATALOG_IMAGE ?= rabbitmqoperator/test-catalog:latest-topology
129+
catalog-build: ## Build catalog image. Customise using REGISTRY and CATALOG_IMAGE
130+
$(CONTAINER) build -t $(REGISTRY)/$(CATALOG_IMAGE) --label "quay.expires-after=48h" -f $(REPO_ROOT)/olm/catalog/cool-catalog.Dockerfile $(REPO_ROOT)/olm/catalog
131+
132+
catalog-push: ## Push catalog image. Customise using REGISTRY and CATALOG_IMAGE
133+
$(CONTAINER) push $(REGISTRY)/$(CATALOG_IMAGE)
134+
135+
catalog-deploy: ## Deploy a catalog source to an existing k8s
136+
kubectl apply -f $(REPO_ROOT)/olm/assets/operator-group.yaml
137+
ytt -f $(REPO_ROOT)/olm/assets/catalog-source.yaml --data-value image="$(REGISTRY)/$(CATALOG_IMAGE)" | kubectl apply -f-
138+
kubectl apply -f $(REPO_ROOT)/olm/assets/subscription.yaml
139+
140+
catalog-undeploy: ## Delete all catalog assets from k8s
141+
kubectl delete -f $(REPO_ROOT)/olm/assets/subscription.yaml --ignore-not-found
142+
kubectl delete -f $(REPO_ROOT)/olm/bundle/manifests/ --ignore-not-found
143+
kubectl delete -f $(REPO_ROOT)/olm/assets/operator-group.yaml --ignore-not-found
144+
ytt -f $(REPO_ROOT)/olm/assets/catalog-source.yaml --data-value image="$(REGISTRY)/$(CATALOG_IMAGE)" | kubectl delete -f- --ignore-not-found
145+
146+
catalog-clean: ## Delete manifest files for catalog
147+
rm -v -f $(REPO_ROOT)/olm/catalog/cool-catalog/*.y*ml
148+
149+
catalog-all::catalog-replace-bundle
150+
catalog-all::catalog-build
151+
catalog-all::catalog-push
152+
catalog-all::catalog-deploy

olm/assets/catalog-source.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#@ load("@ytt:data", "data")
2+
3+
---
4+
apiVersion: operators.coreos.com/v1alpha1
5+
kind: CatalogSource
6+
metadata:
7+
name: cool-catalog
8+
#! Subscriptions cannot install operators provided by CatalogSources
9+
#! that are not in the same namespace unless the CatalogSource is
10+
#! created in the olm namespace.
11+
#! https://olm.operatorframework.io/docs/troubleshooting/subscription/#a-subscription-in-namespace-x-cant-install-operators-from-a-catalogsource-in-namespace-y
12+
namespace: ns-1
13+
spec:
14+
sourceType: grpc
15+
image: #@ data.values.image
16+
displayName: Test catalog
17+
publisher: RabbitMQ Topology Operator Test
18+
updateStrategy:
19+
registryPoll:
20+
interval: 10m

olm/assets/operator-group.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: ns-1
6+
spec: {}
7+
---
8+
apiVersion: operators.coreos.com/v1alpha2
9+
kind: OperatorGroup
10+
metadata:
11+
name: my-group
12+
#! Subscriptions cannot install operators provided by CatalogSources
13+
#! that are not in the same namespace unless the CatalogSource is
14+
#! created in the olm namespace.
15+
#! https://olm.operatorframework.io/docs/troubleshooting/subscription/#a-subscription-in-namespace-x-cant-install-operators-from-a-catalogsource-in-namespace-y
16+
namespace: ns-1
17+
spec:
18+
targetNamespaces:
19+
- ns-1

olm/assets/subscription.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
apiVersion: operators.coreos.com/v1alpha1
3+
kind: Subscription
4+
metadata:
5+
name: sub-to-rmq-messaging-topology-operator
6+
#! Subscriptions cannot install operators provided by CatalogSources
7+
#! that are not in the same namespace unless the CatalogSource is
8+
#! created in the olm namespace.
9+
#! https://olm.operatorframework.io/docs/troubleshooting/subscription/#a-subscription-in-namespace-x-cant-install-operators-from-a-catalogsource-in-namespace-y
10+
namespace: ns-1
11+
spec:
12+
channel: preview
13+
name: rabbitmq-messaging-topology-operator
14+
source: cool-catalog
15+
sourceNamespace: ns-1
16+
installPlanApproval: Automatic

olm/bundle/bundle.Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM scratch
2+
3+
LABEL operators.operatorframework.io.bundle.mediatype.v1=plain
4+
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
5+
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
6+
LABEL operators.operatorframework.io.bundle.package.v1=rabbitmq-messaging-topology-operator
7+
LABEL operators.operatorframework.io.bundle.channels.v1=stable
8+
LABEL operators.operatorframework.io.bundle.channel.default.v1=stable
9+
10+
COPY manifests /manifests/
11+
COPY metadata /metadata/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
annotations:
2+
operators.operatorframework.io.bundle.channel.default.v1: stable
3+
operators.operatorframework.io.bundle.channels.v1: stable
4+
operators.operatorframework.io.bundle.manifests.v1: manifests/
5+
operators.operatorframework.io.bundle.mediatype.v1: registry+v1
6+
operators.operatorframework.io.bundle.metadata.v1: metadata/
7+
operators.operatorframework.io.bundle.package.v1: rabbitmq-messaging-topology-operator
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
dependencies:
3+
- type: olm.package
4+
value:
5+
packageName: rabbitmq-cluster-operator
6+
version: ">2.0.0"
7+
- type: olm.gvk
8+
value:
9+
group: rabbitmq.com
10+
kind: RabbitmqCluster
11+
version: v1beta1

0 commit comments

Comments
 (0)