Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

Commit 3f4a7af

Browse files
gazarenkovrm3l
andauthored
add options for olm deploy and fix developer.md (#383)
* add options for olm deploy Signed-off-by: gazarenkov <gazarenkov@gmail.com> * Update docs/developer.md Co-authored-by: Armel Soro <armel@rm3l.org> * Update docs/developer.md Co-authored-by: Armel Soro <armel@rm3l.org> * Update docs/developer.md Co-authored-by: Armel Soro <armel@rm3l.org> * fix deploy-openshift Signed-off-by: gazarenkov <gazarenkov@gmail.com> --------- Signed-off-by: gazarenkov <gazarenkov@gmail.com> Co-authored-by: Armel Soro <armel@rm3l.org>
1 parent d15d018 commit 3f4a7af

File tree

4 files changed

+116
-53
lines changed

4 files changed

+116
-53
lines changed

Makefile

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,25 +363,53 @@ release-build: bundle image-build bundle-build catalog-build ## Build operator,
363363
.PHONY:
364364
release-push: image-push bundle-push catalog-push ## Push operator, bundle + catalog images
365365

366+
# It has to be the same namespace as ./config/default/kustomization.yaml -> namespace
367+
OPERATOR_NAMESPACE ?= backstage-system
368+
OLM_NAMESPACE ?= olm
369+
OPENSHIFT_OLM_NAMESPACE = openshift-marketplace
370+
366371
.PHONY: deploy-olm
367372
deploy-olm: ## Deploy the operator with OLM
368-
kubectl apply -f config/samples/catalog-operator-group.yaml
369-
sed "s/{{VERSION}}/$(subst /,\/,$(VERSION))/g" config/samples/catalog-subscription-template.yaml | sed "s/{{DEFAULT_OLM_NAMESPACE}}/$(subst /,\/,$(DEFAULT_OLM_NAMESPACE))/g" | kubectl apply -f -
373+
kubectl -n ${OPERATOR_NAMESPACE} apply -f config/samples/catalog-operator-group.yaml
374+
sed "s/{{VERSION}}/$(subst /,\/,$(VERSION))/g" config/samples/catalog-subscription-template.yaml | sed "s/{{OLM_NAMESPACE}}/$(subst /,\/,$(OLM_NAMESPACE))/g" | kubectl -n ${OPERATOR_NAMESPACE} apply -f -
375+
376+
.PHONY: deploy-olm-openshift
377+
deploy-olm-openshift: ## Deploy the operator with OLM
378+
kubectl -n ${OPERATOR_NAMESPACE} apply -f config/samples/catalog-operator-group.yaml
379+
sed "s/{{VERSION}}/$(subst /,\/,$(VERSION))/g" config/samples/catalog-subscription-template.yaml | sed "s/{{OLM_NAMESPACE}}/$(subst /,\/,$(OPENSHIFT_OLM_NAMESPACE))/g" | kubectl -n ${OPERATOR_NAMESPACE} apply -f -
380+
370381

371382
.PHONY: undeploy-olm
372383
undeploy-olm: ## Un-deploy the operator with OLM
373-
-kubectl delete subscriptions.operators.coreos.com backstage-operator
374-
-kubectl delete operatorgroup backstage-operator-group
375-
-kubectl delete clusterserviceversion backstage-operator.$(VERSION)
384+
-kubectl -n ${OPERATOR_NAMESPACE} delete subscriptions.operators.coreos.com backstage-operator
385+
-kubectl -n ${OPERATOR_NAMESPACE} delete operatorgroup backstage-operator-group
386+
-kubectl -n ${OPERATOR_NAMESPACE} delete clusterserviceversion backstage-operator.v$(VERSION)
376387

377-
DEFAULT_OLM_NAMESPACE ?= openshift-marketplace
378388
.PHONY: catalog-update
379389
catalog-update: ## Update catalog source in the default namespace for catalogsource
380-
-kubectl delete catalogsource backstage-operator -n $(DEFAULT_OLM_NAMESPACE)
381-
sed "s/{{CATALOG_IMG}}/$(subst /,\/,$(CATALOG_IMG))/g" config/samples/catalog-source-template.yaml | kubectl apply -n $(DEFAULT_OLM_NAMESPACE) -f -
390+
-kubectl delete catalogsource backstage-operator -n $(OLM_NAMESPACE)
391+
sed "s/{{CATALOG_IMG}}/$(subst /,\/,$(CATALOG_IMG))/g" config/samples/catalog-source-template.yaml | kubectl apply -n $(OLM_NAMESPACE) -f -
392+
393+
.PHONY: catalog-update
394+
catalog-update-openshift: ## Update catalog source in the default namespace for catalogsource
395+
-kubectl delete catalogsource backstage-operator -n $(OLM_NAMESPACE)
396+
sed "s/{{CATALOG_IMG}}/$(subst /,\/,$(CATALOG_IMG))/g" config/samples/catalog-source-template.yaml | kubectl apply -n $(OPENSHIFT_OLM_NAMESPACE) -f -
382397

398+
399+
# Deploy on Openshift cluster using OLM (by default installed on Openshift)
383400
.PHONY: deploy-openshift
384-
deploy-openshift: release-build release-push catalog-update ## Deploy the operator on openshift cluster
401+
deploy-openshift: release-build release-push catalog-update-openshift create-operator-namespace deploy-olm-openshift ## Deploy the operator on openshift cluster
402+
403+
.PHONY: install-olm
404+
install-olm: operator-sdk
405+
$(OPSDK) olm install
406+
407+
.PHONY: create-operator-namespace
408+
create-operator-namespace:
409+
-kubectl create namespace ${OPERATOR_NAMESPACE}
410+
411+
.PHONY: deploy-k8s-olm
412+
deploy-k8s-olm: release-build release-push catalog-update create-operator-namespace deploy-olm ## Deploy the operator on openshift cluster
385413

386414
# After this time, Ginkgo will emit progress reports, so we can get visibility into long-running tests.
387415
POLL_PROGRESS_INTERVAL := 120s

config/samples/catalog-subscription-template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ spec:
77
installPlanApproval: Automatic
88
name: backstage-operator
99
source: backstage-operator
10-
sourceNamespace: openshift-marketplace
10+
sourceNamespace: {{OLM_NAMESPACE}}
1111
startingCSV: backstage-operator.v{{VERSION}}

docs/developer.md

Lines changed: 76 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,150 @@
1-
# DEVELOPER GUIDE --- WIP
1+
# Developer Guide
22

33
## Contributing
44
// TODO(user): Add detailed information on how you would like others to contribute to this project
55

6+
67
### How it works
78
This project aims to follow the Kubernetes [Operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/).
89

910
It uses [Controllers](https://kubernetes.io/docs/concepts/architecture/controller/)
1011
which provides a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster.
1112

12-
1313
## Local development
1414

1515
### Prerequisites
1616

1717
* **kubectl**. See [Instaling kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl).
18-
* **minikube**. See [Instaling minkube](https://kubernetes.io/docs/tasks/tools/#minikube).
18+
* Available local or remote Kubernetes cluster with cluster admin privileges. For instance **minikube**. See [Instaling minkube](https://kubernetes.io/docs/tasks/tools/#minikube).
1919
* A copy of the Backstage Operator sources:
2020
```sh
2121
git clone https://github.com/janus-idp/operator
2222
```
2323

2424
### Local Tests
2525

26-
To run both unit tests (since 0.0.2) and Kubernetes integration tests ([envtest](https://book.kubebuilder.io/reference/envtest.html)):
26+
To run:
27+
* all the unit tests
28+
* part of [Integration Tests](../integration_tests/README.md) which does not require a real cluster.
2729

2830
```sh
2931
make test
3032
```
3133

32-
### Test on the local cluster
34+
It only takes a few seconds to run, but covers quite a lot of functionality. For early regression detection, it is recommended to run it as often as possible during development.
3335

34-
You’ll need a Kubernetes cluster to run against.
35-
You can use [minikube](https://kubernetes.io/docs/tasks/tools/#minikube) or [kind](https://kubernetes.io/docs/tasks/tools/#kind) to get a local cluster for testing, or run against a remote cluster.
36+
### Test on the cluster
3637

37-
**Note:** Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster `kubectl cluster-info` shows).
38+
For testing, you will need a Kubernetes cluster, either remote (with sufficient admin rights) or local, such as [minikube](https://kubernetes.io/docs/tasks/tools/#minikube) or [kind](https://kubernetes.io/docs/tasks/tools/#kind)
3839

3940
- Build and push your image to the location specified by `IMG`:
4041
```sh
4142
make image-build image-push IMG=<your-registry>/backstage-operator:tag
4243
```
4344

44-
- Install the CRDs into the local cluster (minikube is installed and running):
45+
- Install the Custom Resource Definitions into the local cluster (minikube is installed and running):
4546
```sh
4647
make install
4748
```
49+
**IMPORTANT:** If you are editing the CRDs, make sure you reinstall it before deploying.
4850

49-
- You can run your controller standalone (this will run in the foreground, so switch to a new terminal if you want to leave it running)
50-
This way you can see controllers log just in your terminal window which is quite convenient for debugging:
51+
- To delete the CRDs from the cluster:
5152
```sh
52-
make run
53+
make uninstall
5354
```
5455

55-
- Or deploy the controller to the cluster with the image specified by `IMG`:
56+
### Run the controller standalone
57+
58+
You can run your controller standalone (this will run in the foreground, so switch to a new terminal if you want to leave it running)
59+
This way you can see controllers log just in your terminal window which is quite convenient for debugging.
5660
```sh
57-
make deploy [IMG=<your-registry>/backstage-operator:tag]
61+
make [install] run
5862
```
5963

60-
- To generate deployment manifest, use:
64+
You can use it for manual and automated ([such as](../integration_tests/README.md) `USE_EXISTING_CLUSTER=true make integration-test`) tests efficiently, but, note, RBAC is not working with this kind of deployment.
65+
66+
### Deploy operator to the real cluster
67+
68+
For development, most probably, you will need to specify the image you build and push:
6169
```sh
62-
make deployment-manifest [IMG=<your-registry>/backstage-operator:tag]
70+
make deploy [IMG=<your-registry>/backstage-operator[:tag]]
6371
```
64-
it will create the file rhdh-operator-${VERSION}.yaml on the project root and you will be able to share it to make it possible to deploy operator with:
72+
73+
To undeploy the controller from the cluster:
6574
```sh
66-
kubectl apply -f <path-or-url-to-deployment-script>
75+
make undeploy
6776
```
6877
69-
### Uninstall CRDs
70-
To delete the CRDs from the cluster:
78+
- To generate deployment manifest, use:
7179
```sh
72-
make uninstall
80+
make deployment-manifest [IMG=<your-registry>/backstage-operator:tag]
7381
```
74-
### Undeploy controller
75-
UnDeploy the controller from the cluster:
82+
it will create the file rhdh-operator-${VERSION}.yaml on the project root and you will be able to share it to make it possible to deploy operator with:
7683
```sh
77-
make undeploy
84+
kubectl apply -f <path-or-url-to-deployment-script>
7885
```
79-
### Build and Deploy with OLM:
80-
1. To build operator, bundle and catalog images:
86+
87+
### Deploy with Operator Lifecycle Manager (valid for v0.3.0+):
88+
89+
#### OLM
90+
91+
Make sure your cluster supports **OLM**. For instance [Openshift](https://www.redhat.com/en/technologies/cloud-computing/openshift) supports it out of the box.
92+
If needed install it using:
93+
8194
```sh
82-
make release-build
95+
make install-olm
8396
```
84-
2. To push operator, bundle and catalog images to the registry:
97+
98+
#### Build and push images
99+
100+
There are a bunch of commands to build and push to the registry necessary images.
101+
For development purpose, most probably, you will need to specify the image you build and push with IMAGE_TAG_BASE env variable:
102+
103+
* `[IMAGE_TAG_BASE=<your-registry>/backstage-operator] make image-build` builds operator manager image (**backstage-operator**)
104+
* `[IMAGE_TAG_BASE=<your-registry>/backstage-operator] make image-push` pushes operator manager image to **your-registry**
105+
* `[IMAGE_TAG_BASE=<your-registry>/backstage-operator] make bundle-build` builds operator manager image (**backstage-operator-bundle**)
106+
* `[IMAGE_TAG_BASE=<your-registry>/backstage-operator] make bundle-push` pushes bundle image to **your-registry**
107+
* `[IMAGE_TAG_BASE=<your-registry>/backstage-operator] make catalog-build` builds catalog image (**backstage-operator-catalog**)
108+
* `[IMAGE_TAG_BASE=<your-registry>/backstage-operator] make catalog-push` pushes catalog image to **your-registry**
109+
110+
You can do it all together using:
85111
```sh
86-
make release-push
112+
[IMAGE_TAG_BASE=<your-registry>/backstage-operator] make release-build release-push
87113
```
88-
3. To deploy or update catalog source:
114+
115+
#### Deploy or update the Catalog Source
116+
89117
```sh
90-
make catalog-update
118+
[OLM_NAMESPACE=<olm-namespace>] [IMAGE_TAG_BASE=<your-registry>/backstage-operator] make catalog-update
91119
```
92-
4. To deloy the operator with OLM
120+
You can point the namespace where OLM installed. By default, in a vanilla Kubernetes, OLM os deployed on 'olm' namespace. In Openshift you have to explicitly point it to **openshift-marketplace** namespace.
121+
122+
#### Deploy the Operator with OLM
123+
Default namespace to deploy the Operator is called **backstage-system** , this name fits one defined in [kustomization.yaml](../config/default/kustomization.yaml). So, if you consider changing it you have to change it in this file and define **OPERATOR_NAMESPACE** environment variable.
124+
Following command creates OperatorGroup and Subscription on Operator namespace
93125
```sh
94-
make deploy-olm
126+
[OPERATOR_NAMESPACE=<operator-namespace>] make deploy-olm
95127
```
96-
5. To undeploy the operator with OLM
128+
To undeploy the Operator
97129
```sh
98130
make undeploy-olm
99131
```
100132
101-
6. To deploy the operator to Openshift with OLM
133+
#### Convenient commands to build and deploy operator with OLM
134+
135+
**NOTE:** OLM has to be installed as a prerequisite
136+
137+
* To build and deploy the operator to vanilla Kubernetes with OLM
102138
```sh
103-
make deploy-openshift [IMAGE_TAG_BASE=<your-registry>/backstage-operator]
139+
[IMAGE_TAG_BASE=<your-registry>/backstage-operator] make deploy-k8s-olm
104140
```
105141
106-
### Modifying the API definitions
107-
If you are editing the API definitions, make sure you:
108-
- run `make install` before deploying the operator with `make deploy`
109-
- regenerate the manifests and bundle if you plan to deploy the operator with OLM using:
142+
* To build and deploy the operator to Openshift with OLM
110143
```sh
111-
make manifests bundle
144+
[IMAGE_TAG_BASE=<your-registry>/backstage-operator] make deploy-openshift
112145
```
146+
147+
113148
**NOTE:** Run `make help` for more information on all potential `make` targets
114149
115150
More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)

integration_tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
How to run Integration Tests
2+
**How to run Integration Tests**
33

44
- For development (controller will reconsile internally)
55
- As a part of the whole testing suite just:
@@ -27,7 +27,7 @@ For example to run specific test(s) you can use something like:
2727

2828
`make integration-test ARGS='--focus "my favorite test"'`
2929

30-
NOTE:
30+
**NOTE:**
3131

3232
Some tests are Openshift specific only and skipped in a local envtest and bare k8s cluster.
3333

0 commit comments

Comments
 (0)