Skip to content

Commit 721a0c4

Browse files
modified memcached operator according to run bundle integration (#86)
1 parent 173e51e commit 721a0c4

11 files changed

+444
-263
lines changed

docs/tutorial.md

+58-3
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,14 @@ You can run the operator in a couple of ways. You can run it locally where the
542542
operator runs on your development machine and talks to the cluster. Or it can
543543
build images of your operator and run it directly in the cluster.
544544

545+
546+
There are three ways to run the operator:
547+
548+
* Running the operator in the cluster
549+
* Running locally outside the cluster
550+
* Managed by the [Operator Lifecycle Manager (OLM)](https://sdk.operatorframework.io/docs/olm-integration/tutorial-bundle/#enabling-olm) in [bundle](https://sdk.operatorframework.io/docs/olm-integration/quickstart-bundle/) format
551+
552+
545553
In this section we will:
546554

547555
* install the CRD
@@ -566,17 +574,17 @@ conveniently build your and push your operator's image to registry. In our
566574
example, we are using `quay.io`, but any docker registry should work.
567575

568576
```
569-
make docker-build docker-push IMG=quay.io/YOURUSER/memcached-quarkus-operator:0.0.1
577+
make docker-build docker-push IMG=quay.io/YOURUSER/memcached-quarkus-operator:v0.0.1
570578
```
571579

572580
This will build the docker image
573-
`quay.io/YOURUSER/memcached-quarkus-operator:0.0.1` and push it to the registry.
581+
`quay.io/YOURUSER/memcached-quarkus-operator:v0.0.1` and push it to the registry.
574582

575583
You can verify it is in your docker registry:
576584

577585
```
578586
$ docker images | grep memcached
579-
quay.io/YOURUSER/memcached-quarkus-operator 0.0.1 c84d2616bc1b 29 seconds ago 236MB
587+
quay.io/YOURUSER/memcached-quarkus-operator v0.0.1 c84d2616bc1b 29 seconds ago 236MB
580588
```
581589

582590
2. Install the CRD
@@ -783,3 +791,50 @@ pod/memcached-sample-6c765df685-mfqnz 1/1 Running 0
783791

784792
If you modify the size field of the `memcached-sample.yaml` and re-apply it. The
785793
operator will trigger a reconcile and adjust the sample pods to the size given.
794+
795+
### Deploy your Operator with OLM
796+
First, install [OLM](https://sdk.operatorframework.io/docs/olm-integration/tutorial-bundle/#enabling-olm):
797+
798+
```
799+
operator-sdk olm install
800+
```
801+
802+
Bundle your operator, then build and push the bundle image. The [bundle](https://github.com/operator-framework/operator-registry/blob/v1.23.0/docs/design/operator-bundle.md#operator-bundle) target generates a bundle in the `bundle` directory containing manifests and metadata defining your operator. `bundle-build` and `bundle-push` build and push a bundle image defined by `bundle.Dockerfile`.
803+
804+
Before running below command export environment variables as shown below.
805+
806+
```
807+
$ export USERNAME=<container-registry-username>
808+
$ export VERSION=0.0.1
809+
$ export IMG=docker.io/$USERNAME/memcached-operator:v$VERSION // location where your operator image is hosted
810+
$ export BUNDLE_IMG=docker.io/$USERNAME/memcached-operator-bundle:v$VERSION // location where your bundle will be hosted
811+
```
812+
813+
```
814+
make bundle bundle-build bundle-push
815+
```
816+
817+
Finally, run your bundle. If your bundle image is hosted in a registry that is private and/or has a custom CA, these [configuration steps](https://sdk.operatorframework.io/docs/olm-integration/cli-overview/#private-bundle-and-catalog-image-registries) must be completed.
818+
819+
820+
```
821+
operator-sdk run bundle <some-registry>/memcached-operator-bundle:v0.0.1
822+
```
823+
824+
The result of the above command is as below:
825+
826+
```
827+
INFO[0009] Successfully created registry pod: docker-io-013859989-memcached-quarkus-operator-bundle-v0-1-1
828+
INFO[0009] Created CatalogSource: memcached-quarkus-operator-catalog
829+
INFO[0009] OperatorGroup "operator-sdk-og" created
830+
INFO[0009] Created Subscription: memcached-quarkus-operator-v0-1-1-sub
831+
INFO[0013] Approved InstallPlan install-6n8vm for the Subscription: memcached-quarkus-operator-v0-1-1-sub
832+
INFO[0013] Waiting for ClusterServiceVersion "default/memcached-quarkus-operator.v0.1.1" to reach 'Succeeded' phase
833+
INFO[0013] Waiting for ClusterServiceVersion "default/memcached-quarkus-operator.v0.1.1" to appear
834+
INFO[0020] Found ClusterServiceVersion "default/memcached-quarkus-operator.v0.1.1" phase: Pending
835+
INFO[0021] Found ClusterServiceVersion "default/memcached-quarkus-operator.v0.1.1" phase: Installing
836+
INFO[0051] Found ClusterServiceVersion "default/memcached-quarkus-operator.v0.1.1" phase: Succeeded
837+
INFO[0051] OLM has successfully installed "memcached-quarkus-operator.v0.1.1"
838+
```
839+
840+
Check out the [docs](https://sdk.operatorframework.io/docs/olm-integration/tutorial-bundle/) for a deep dive into operator-sdk's OLM integration.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
VERSION ?= 0.0.1
3+
IMAGE_TAG_BASE ?= example.com/memcached-quarkus-operator
4+
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
5+
6+
# Image URL to use all building/pushing image targets
7+
IMG ?= controller:latest
8+
9+
all: docker-build
10+
11+
##@ General
12+
13+
# The help target prints out all targets with their descriptions organized
14+
# beneath their categories. The categories are represented by '##@' and the
15+
# target descriptions by '##'. The awk commands is responsible for reading the
16+
# entire set of makefiles included in this invocation, looking for lines of the
17+
# file as xyz: ## something, and then pretty-format the target and help. Then,
18+
# if there's a line with ##@ something, that gets pretty-printed as a category.
19+
# More info on the usage of ANSI control characters for terminal formatting:
20+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
21+
# More info on the awk command:
22+
# http://linuxcommand.org/lc3_adv_awk.php
23+
24+
help: ## Display this help.
25+
@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)
26+
27+
##@ Build
28+
29+
docker-build: ## Build docker image with the manager.
30+
mvn package -Dquarkus.container-image.build=true -Dquarkus.container-image.image=${IMG}
31+
32+
docker-push: ## Push docker image with the manager.
33+
mvn package -Dquarkus.container-image.push=true -Dquarkus.container-image.image=${IMG}
34+
35+
##@ Deployment
36+
37+
install: ## Install CRDs into the K8s cluster specified in ~/.kube/config.
38+
@$(foreach file, $(wildcard target/kubernetes/*-v1.yml), kubectl apply -f $(file);)
39+
40+
uninstall: ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
41+
@$(foreach file, $(wildcard target/kubernetes/*-v1.yml), kubectl delete -f $(file);)
42+
43+
deploy: ## Deploy controller to the K8s cluster specified in ~/.kube/config.
44+
kubectl apply -f target/kubernetes/kubernetes.yml
45+
46+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
47+
kubectl delete -f target/kubernetes/kubernetes.yml
48+
49+
##@Bundle
50+
.PHONY: bundle
51+
bundle: ## Generate bundle manifests and metadata, then validate generated files.
52+
## marker
53+
cat target/kubernetes/memcacheds.cache.example.com-v1.yml target/kubernetes/kubernetes.yml | operator-sdk generate bundle -q --overwrite --version 0.1.1 --default-channel=stable --channels=stable --package=memcached-quarkus-operator
54+
operator-sdk bundle validate ./bundle
55+
56+
.PHONY: bundle-build
57+
bundle-build: ## Build the bundle image.
58+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
59+
60+
.PHONY: bundle-push
61+
bundle-push: ## Push the bundle image.
62+
docker push $(BUNDLE_IMG)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM scratch
2+
3+
# Core bundle labels.
4+
LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1
5+
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
6+
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
7+
LABEL operators.operatorframework.io.bundle.package.v1=memcached-quarkus-operator
8+
LABEL operators.operatorframework.io.bundle.channels.v1=stable
9+
LABEL operators.operatorframework.io.bundle.channel.default.v1=stable
10+
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.21.0+git
11+
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
12+
LABEL operators.operatorframework.io.metrics.project_layout=quarkus.javaoperatorsdk.io/v1-alpha
13+
14+
# Copy files to locations specified by labels.
15+
COPY bundle/manifests /manifests/
16+
COPY bundle/metadata /metadata/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
creationTimestamp: null
5+
name: memcacheds.cache.example.com
6+
spec:
7+
group: cache.example.com
8+
names:
9+
kind: Memcached
10+
plural: memcacheds
11+
singular: memcached
12+
scope: Namespaced
13+
versions:
14+
- name: v1
15+
schema:
16+
openAPIV3Schema:
17+
properties:
18+
spec:
19+
properties:
20+
size:
21+
type: integer
22+
type: object
23+
status:
24+
properties:
25+
nodes:
26+
items:
27+
type: string
28+
type: array
29+
type: object
30+
type: object
31+
served: true
32+
storage: true
33+
subresources:
34+
status: {}
35+
status:
36+
acceptedNames:
37+
kind: ""
38+
plural: ""
39+
conditions: null
40+
storedVersions: null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: RoleBinding
3+
metadata:
4+
creationTimestamp: null
5+
name: memcached-quarkus-operator-operator-view
6+
roleRef:
7+
apiGroup: rbac.authorization.k8s.io
8+
kind: ClusterRole
9+
name: view
10+
subjects:
11+
- kind: ServiceAccount
12+
name: memcached-quarkus-operator-operator
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
annotations:
5+
app.quarkus.io/build-timestamp: 2022-06-03 - 17:56:59 +0000
6+
prometheus.io/path: /q/metrics
7+
prometheus.io/port: "8080"
8+
prometheus.io/scheme: http
9+
prometheus.io/scrape: "true"
10+
creationTimestamp: null
11+
labels:
12+
app.kubernetes.io/name: memcached-quarkus-operator-operator
13+
app.kubernetes.io/version: 0.0.1-SNAPSHOT
14+
name: memcached-quarkus-operator-operator
15+
spec:
16+
ports:
17+
- name: http
18+
port: 80
19+
targetPort: 8080
20+
selector:
21+
app.kubernetes.io/name: memcached-quarkus-operator-operator
22+
app.kubernetes.io/version: 0.0.1-SNAPSHOT
23+
type: ClusterIP
24+
status:
25+
loadBalancer: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
apiVersion: operators.coreos.com/v1alpha1
2+
kind: ClusterServiceVersion
3+
metadata:
4+
annotations:
5+
alm-examples: '[]'
6+
capabilities: Basic Install
7+
operators.operatorframework.io/builder: operator-sdk-v1.21.0+git
8+
operators.operatorframework.io/project_layout: quarkus.javaoperatorsdk.io/v1-alpha
9+
name: memcached-quarkus-operator.v0.1.1
10+
namespace: placeholder
11+
spec:
12+
apiservicedefinitions: {}
13+
customresourcedefinitions:
14+
owned:
15+
- kind: Memcached
16+
name: memcacheds.cache.example.com
17+
version: v1
18+
description: Memcached Quarkus Operator description. TODO.
19+
displayName: Memcached Quarkus Operator
20+
icon:
21+
- base64data: ""
22+
mediatype: ""
23+
install:
24+
spec:
25+
clusterPermissions:
26+
- rules:
27+
- apiGroups:
28+
- cache.example.com
29+
resources:
30+
- memcacheds
31+
- memcacheds/status
32+
- memcacheds/finalizers
33+
verbs:
34+
- get
35+
- list
36+
- watch
37+
- create
38+
- delete
39+
- patch
40+
- update
41+
- apiGroups:
42+
- apiextensions.k8s.io
43+
resources:
44+
- customresourcedefinitions
45+
verbs:
46+
- get
47+
- list
48+
serviceAccountName: memcached-quarkus-operator-operator
49+
deployments:
50+
- label:
51+
app.kubernetes.io/name: memcached-quarkus-operator-operator
52+
app.kubernetes.io/version: 0.0.1-SNAPSHOT
53+
name: memcached-quarkus-operator-operator
54+
spec:
55+
replicas: 1
56+
selector:
57+
matchLabels:
58+
app.kubernetes.io/name: memcached-quarkus-operator-operator
59+
app.kubernetes.io/version: 0.0.1-SNAPSHOT
60+
strategy: {}
61+
template:
62+
metadata:
63+
annotations:
64+
app.quarkus.io/build-timestamp: 2022-06-03 - 17:56:59 +0000
65+
prometheus.io/path: /q/metrics
66+
prometheus.io/port: "8080"
67+
prometheus.io/scheme: http
68+
prometheus.io/scrape: "true"
69+
labels:
70+
app.kubernetes.io/name: memcached-quarkus-operator-operator
71+
app.kubernetes.io/version: 0.0.1-SNAPSHOT
72+
spec:
73+
containers:
74+
- env:
75+
- name: KUBERNETES_NAMESPACE
76+
valueFrom:
77+
fieldRef:
78+
fieldPath: metadata.namespace
79+
image: quay.io/lpandhar/memcached-quarkus-operator:v0.1.1
80+
imagePullPolicy: Always
81+
livenessProbe:
82+
failureThreshold: 3
83+
httpGet:
84+
path: /q/health/live
85+
port: 8080
86+
scheme: HTTP
87+
periodSeconds: 30
88+
successThreshold: 1
89+
timeoutSeconds: 10
90+
name: memcached-quarkus-operator-operator
91+
ports:
92+
- containerPort: 8080
93+
name: http
94+
protocol: TCP
95+
readinessProbe:
96+
failureThreshold: 3
97+
httpGet:
98+
path: /q/health/ready
99+
port: 8080
100+
scheme: HTTP
101+
periodSeconds: 30
102+
successThreshold: 1
103+
timeoutSeconds: 10
104+
resources: {}
105+
serviceAccountName: memcached-quarkus-operator-operator
106+
strategy: deployment
107+
installModes:
108+
- supported: false
109+
type: OwnNamespace
110+
- supported: false
111+
type: SingleNamespace
112+
- supported: false
113+
type: MultiNamespace
114+
- supported: true
115+
type: AllNamespaces
116+
keywords:
117+
- memcached-quarkus-operator
118+
links:
119+
- name: Memcached Quarkus Operator
120+
url: https://memcached-quarkus-operator.domain
121+
maintainers:
122+
123+
name: Maintainer Name
124+
maturity: alpha
125+
provider:
126+
name: Provider Name
127+
url: https://your.domain
128+
version: 0.1.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
annotations:
2+
# Core bundle annotations.
3+
operators.operatorframework.io.bundle.mediatype.v1: registry+v1
4+
operators.operatorframework.io.bundle.manifests.v1: manifests/
5+
operators.operatorframework.io.bundle.metadata.v1: metadata/
6+
operators.operatorframework.io.bundle.package.v1: memcached-quarkus-operator
7+
operators.operatorframework.io.bundle.channels.v1: stable
8+
operators.operatorframework.io.bundle.channel.default.v1: stable
9+
operators.operatorframework.io.metrics.builder: operator-sdk-v1.21.0+git
10+
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
11+
operators.operatorframework.io.metrics.project_layout: quarkus.javaoperatorsdk.io/v1-alpha

0 commit comments

Comments
 (0)