From 26e16e508756c8dd55c1285edfe0c424945c6146 Mon Sep 17 00:00:00 2001 From: laxmikantbpandhare Date: Fri, 3 Jun 2022 11:16:48 -0700 Subject: [PATCH 1/4] modified memcached operator according to run bundle integration and working on updating tutorial --- docs/tutorial.md | 6 +- .../memcached-quarkus-operator/Makefile | 62 +++++++ .../bundle.Dockerfile | 16 ++ .../cache.example.com_memcacheds.yaml | 40 ++++ ...c.authorization.k8s.io_v1_rolebinding.yaml | 12 ++ ...-quarkus-operator-operator_v1_service.yaml | 25 +++ ...uarkus-operator.clusterserviceversion.yaml | 128 +++++++++++++ .../bundle/metadata/annotations.yaml | 11 ++ .../memcached-quarkus-operator.iml | 172 ------------------ .../memcached-quarkus-operator/pom.xml | 14 +- .../java/com/example/MemcachedReconciler.java | 166 ++++++++--------- 11 files changed, 389 insertions(+), 263 deletions(-) create mode 100644 testdata/quarkus/memcached-quarkus-operator/Makefile create mode 100644 testdata/quarkus/memcached-quarkus-operator/bundle.Dockerfile create mode 100644 testdata/quarkus/memcached-quarkus-operator/bundle/manifests/cache.example.com_memcacheds.yaml create mode 100644 testdata/quarkus/memcached-quarkus-operator/bundle/manifests/memcached-quarkus-operator-operator-view_rbac.authorization.k8s.io_v1_rolebinding.yaml create mode 100644 testdata/quarkus/memcached-quarkus-operator/bundle/manifests/memcached-quarkus-operator-operator_v1_service.yaml create mode 100644 testdata/quarkus/memcached-quarkus-operator/bundle/manifests/memcached-quarkus-operator.clusterserviceversion.yaml create mode 100644 testdata/quarkus/memcached-quarkus-operator/bundle/metadata/annotations.yaml delete mode 100644 testdata/quarkus/memcached-quarkus-operator/memcached-quarkus-operator.iml diff --git a/docs/tutorial.md b/docs/tutorial.md index 99a20d5..3ca5538 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -566,17 +566,17 @@ conveniently build your and push your operator's image to registry. In our example, we are using `quay.io`, but any docker registry should work. ``` -make docker-build docker-push IMG=quay.io/YOURUSER/memcached-quarkus-operator:0.0.1 +make docker-build docker-push IMG=quay.io/YOURUSER/memcached-quarkus-operator:v0.0.1 ``` This will build the docker image -`quay.io/YOURUSER/memcached-quarkus-operator:0.0.1` and push it to the registry. +`quay.io/YOURUSER/memcached-quarkus-operator:v0.0.1` and push it to the registry. You can verify it is in your docker registry: ``` $ docker images | grep memcached -quay.io/YOURUSER/memcached-quarkus-operator 0.0.1 c84d2616bc1b 29 seconds ago 236MB +quay.io/YOURUSER/memcached-quarkus-operator v0.0.1 c84d2616bc1b 29 seconds ago 236MB ``` 2. Install the CRD diff --git a/testdata/quarkus/memcached-quarkus-operator/Makefile b/testdata/quarkus/memcached-quarkus-operator/Makefile new file mode 100644 index 0000000..a609154 --- /dev/null +++ b/testdata/quarkus/memcached-quarkus-operator/Makefile @@ -0,0 +1,62 @@ + +VERSION ?= 0.0.1 +IMAGE_TAG_BASE ?= example.com/memcached-quarkus-operator +BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION) + +# Image URL to use all building/pushing image targets +IMG ?= controller:latest + +all: docker-build + +##@ General + +# The help target prints out all targets with their descriptions organized +# beneath their categories. The categories are represented by '##@' and the +# target descriptions by '##'. The awk commands is responsible for reading the +# entire set of makefiles included in this invocation, looking for lines of the +# file as xyz: ## something, and then pretty-format the target and help. Then, +# if there's a line with ##@ something, that gets pretty-printed as a category. +# More info on the usage of ANSI control characters for terminal formatting: +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters +# More info on the awk command: +# http://linuxcommand.org/lc3_adv_awk.php + +help: ## Display this help. + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\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) + +##@ Build + +docker-build: ## Build docker image with the manager. + mvn package -Dquarkus.container-image.build=true -Dquarkus.container-image.image=${IMG} + +docker-push: ## Push docker image with the manager. + mvn package -Dquarkus.container-image.push=true -Dquarkus.container-image.image=${IMG} + +##@ Deployment + +install: ## Install CRDs into the K8s cluster specified in ~/.kube/config. + @$(foreach file, $(wildcard target/kubernetes/*-v1.yml), kubectl apply -f $(file);) + +uninstall: ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. + @$(foreach file, $(wildcard target/kubernetes/*-v1.yml), kubectl delete -f $(file);) + +deploy: ## Deploy controller to the K8s cluster specified in ~/.kube/config. + kubectl apply -f target/kubernetes/kubernetes.yml + +undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. + kubectl delete -f target/kubernetes/kubernetes.yml + +##@Bundle +.PHONY: bundle +bundle: ## Generate bundle manifests and metadata, then validate generated files. +## marker + 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 + operator-sdk bundle validate ./bundle + +.PHONY: bundle-build +bundle-build: ## Build the bundle image. + docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . + +.PHONY: bundle-push +bundle-push: ## Push the bundle image. + docker push $(BUNDLE_IMG) diff --git a/testdata/quarkus/memcached-quarkus-operator/bundle.Dockerfile b/testdata/quarkus/memcached-quarkus-operator/bundle.Dockerfile new file mode 100644 index 0000000..69309e0 --- /dev/null +++ b/testdata/quarkus/memcached-quarkus-operator/bundle.Dockerfile @@ -0,0 +1,16 @@ +FROM scratch + +# Core bundle labels. +LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 +LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ +LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ +LABEL operators.operatorframework.io.bundle.package.v1=memcached-quarkus-operator +LABEL operators.operatorframework.io.bundle.channels.v1=stable +LABEL operators.operatorframework.io.bundle.channel.default.v1=stable +LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.21.0+git +LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1 +LABEL operators.operatorframework.io.metrics.project_layout=quarkus.javaoperatorsdk.io/v1-alpha + +# Copy files to locations specified by labels. +COPY bundle/manifests /manifests/ +COPY bundle/metadata /metadata/ diff --git a/testdata/quarkus/memcached-quarkus-operator/bundle/manifests/cache.example.com_memcacheds.yaml b/testdata/quarkus/memcached-quarkus-operator/bundle/manifests/cache.example.com_memcacheds.yaml new file mode 100644 index 0000000..aa1d92f --- /dev/null +++ b/testdata/quarkus/memcached-quarkus-operator/bundle/manifests/cache.example.com_memcacheds.yaml @@ -0,0 +1,40 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + creationTimestamp: null + name: memcacheds.cache.example.com +spec: + group: cache.example.com + names: + kind: Memcached + plural: memcacheds + singular: memcached + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + properties: + spec: + properties: + size: + type: integer + type: object + status: + properties: + nodes: + items: + type: string + type: array + type: object + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: null + storedVersions: null diff --git a/testdata/quarkus/memcached-quarkus-operator/bundle/manifests/memcached-quarkus-operator-operator-view_rbac.authorization.k8s.io_v1_rolebinding.yaml b/testdata/quarkus/memcached-quarkus-operator/bundle/manifests/memcached-quarkus-operator-operator-view_rbac.authorization.k8s.io_v1_rolebinding.yaml new file mode 100644 index 0000000..6e4b9c9 --- /dev/null +++ b/testdata/quarkus/memcached-quarkus-operator/bundle/manifests/memcached-quarkus-operator-operator-view_rbac.authorization.k8s.io_v1_rolebinding.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + creationTimestamp: null + name: memcached-quarkus-operator-operator-view +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: view +subjects: +- kind: ServiceAccount + name: memcached-quarkus-operator-operator diff --git a/testdata/quarkus/memcached-quarkus-operator/bundle/manifests/memcached-quarkus-operator-operator_v1_service.yaml b/testdata/quarkus/memcached-quarkus-operator/bundle/manifests/memcached-quarkus-operator-operator_v1_service.yaml new file mode 100644 index 0000000..b117ad8 --- /dev/null +++ b/testdata/quarkus/memcached-quarkus-operator/bundle/manifests/memcached-quarkus-operator-operator_v1_service.yaml @@ -0,0 +1,25 @@ +apiVersion: v1 +kind: Service +metadata: + annotations: + app.quarkus.io/build-timestamp: 2022-06-03 - 17:56:59 +0000 + prometheus.io/path: /q/metrics + prometheus.io/port: "8080" + prometheus.io/scheme: http + prometheus.io/scrape: "true" + creationTimestamp: null + labels: + app.kubernetes.io/name: memcached-quarkus-operator-operator + app.kubernetes.io/version: 0.0.1-SNAPSHOT + name: memcached-quarkus-operator-operator +spec: + ports: + - name: http + port: 80 + targetPort: 8080 + selector: + app.kubernetes.io/name: memcached-quarkus-operator-operator + app.kubernetes.io/version: 0.0.1-SNAPSHOT + type: ClusterIP +status: + loadBalancer: {} diff --git a/testdata/quarkus/memcached-quarkus-operator/bundle/manifests/memcached-quarkus-operator.clusterserviceversion.yaml b/testdata/quarkus/memcached-quarkus-operator/bundle/manifests/memcached-quarkus-operator.clusterserviceversion.yaml new file mode 100644 index 0000000..18d2ee1 --- /dev/null +++ b/testdata/quarkus/memcached-quarkus-operator/bundle/manifests/memcached-quarkus-operator.clusterserviceversion.yaml @@ -0,0 +1,128 @@ +apiVersion: operators.coreos.com/v1alpha1 +kind: ClusterServiceVersion +metadata: + annotations: + alm-examples: '[]' + capabilities: Basic Install + operators.operatorframework.io/builder: operator-sdk-v1.21.0+git + operators.operatorframework.io/project_layout: quarkus.javaoperatorsdk.io/v1-alpha + name: memcached-quarkus-operator.v0.1.1 + namespace: placeholder +spec: + apiservicedefinitions: {} + customresourcedefinitions: + owned: + - kind: Memcached + name: memcacheds.cache.example.com + version: v1 + description: Memcached Quarkus Operator description. TODO. + displayName: Memcached Quarkus Operator + icon: + - base64data: "" + mediatype: "" + install: + spec: + clusterPermissions: + - rules: + - apiGroups: + - cache.example.com + resources: + - memcacheds + - memcacheds/status + - memcacheds/finalizers + verbs: + - get + - list + - watch + - create + - delete + - patch + - update + - apiGroups: + - apiextensions.k8s.io + resources: + - customresourcedefinitions + verbs: + - get + - list + serviceAccountName: memcached-quarkus-operator-operator + deployments: + - label: + app.kubernetes.io/name: memcached-quarkus-operator-operator + app.kubernetes.io/version: 0.0.1-SNAPSHOT + name: memcached-quarkus-operator-operator + spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: memcached-quarkus-operator-operator + app.kubernetes.io/version: 0.0.1-SNAPSHOT + strategy: {} + template: + metadata: + annotations: + app.quarkus.io/build-timestamp: 2022-06-03 - 17:56:59 +0000 + prometheus.io/path: /q/metrics + prometheus.io/port: "8080" + prometheus.io/scheme: http + prometheus.io/scrape: "true" + labels: + app.kubernetes.io/name: memcached-quarkus-operator-operator + app.kubernetes.io/version: 0.0.1-SNAPSHOT + spec: + containers: + - env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + image: quay.io/lpandhar/memcached-quarkus-operator:v0.1.1 + imagePullPolicy: Always + livenessProbe: + failureThreshold: 3 + httpGet: + path: /q/health/live + port: 8080 + scheme: HTTP + periodSeconds: 30 + successThreshold: 1 + timeoutSeconds: 10 + name: memcached-quarkus-operator-operator + ports: + - containerPort: 8080 + name: http + protocol: TCP + readinessProbe: + failureThreshold: 3 + httpGet: + path: /q/health/ready + port: 8080 + scheme: HTTP + periodSeconds: 30 + successThreshold: 1 + timeoutSeconds: 10 + resources: {} + serviceAccountName: memcached-quarkus-operator-operator + strategy: deployment + installModes: + - supported: false + type: OwnNamespace + - supported: false + type: SingleNamespace + - supported: false + type: MultiNamespace + - supported: true + type: AllNamespaces + keywords: + - memcached-quarkus-operator + links: + - name: Memcached Quarkus Operator + url: https://memcached-quarkus-operator.domain + maintainers: + - email: your@email.com + name: Maintainer Name + maturity: alpha + provider: + name: Provider Name + url: https://your.domain + version: 0.1.1 diff --git a/testdata/quarkus/memcached-quarkus-operator/bundle/metadata/annotations.yaml b/testdata/quarkus/memcached-quarkus-operator/bundle/metadata/annotations.yaml new file mode 100644 index 0000000..b51cc20 --- /dev/null +++ b/testdata/quarkus/memcached-quarkus-operator/bundle/metadata/annotations.yaml @@ -0,0 +1,11 @@ +annotations: + # Core bundle annotations. + operators.operatorframework.io.bundle.mediatype.v1: registry+v1 + operators.operatorframework.io.bundle.manifests.v1: manifests/ + operators.operatorframework.io.bundle.metadata.v1: metadata/ + operators.operatorframework.io.bundle.package.v1: memcached-quarkus-operator + operators.operatorframework.io.bundle.channels.v1: stable + operators.operatorframework.io.bundle.channel.default.v1: stable + operators.operatorframework.io.metrics.builder: operator-sdk-v1.21.0+git + operators.operatorframework.io.metrics.mediatype.v1: metrics+v1 + operators.operatorframework.io.metrics.project_layout: quarkus.javaoperatorsdk.io/v1-alpha diff --git a/testdata/quarkus/memcached-quarkus-operator/memcached-quarkus-operator.iml b/testdata/quarkus/memcached-quarkus-operator/memcached-quarkus-operator.iml deleted file mode 100644 index 8ad72fd..0000000 --- a/testdata/quarkus/memcached-quarkus-operator/memcached-quarkus-operator.iml +++ /dev/null @@ -1,172 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/testdata/quarkus/memcached-quarkus-operator/pom.xml b/testdata/quarkus/memcached-quarkus-operator/pom.xml index 44c4fca..8fb0940 100644 --- a/testdata/quarkus/memcached-quarkus-operator/pom.xml +++ b/testdata/quarkus/memcached-quarkus-operator/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.example memcached-quarkus-operator @@ -64,11 +64,11 @@ - - - maven-compiler-plugin - ${compiler-plugin.version} - + + + maven-compiler-plugin + ${compiler-plugin.version} + diff --git a/testdata/quarkus/memcached-quarkus-operator/src/main/java/com/example/MemcachedReconciler.java b/testdata/quarkus/memcached-quarkus-operator/src/main/java/com/example/MemcachedReconciler.java index f66d39f..0b86d8b 100644 --- a/testdata/quarkus/memcached-quarkus-operator/src/main/java/com/example/MemcachedReconciler.java +++ b/testdata/quarkus/memcached-quarkus-operator/src/main/java/com/example/MemcachedReconciler.java @@ -1,5 +1,10 @@ package com.example; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; + import io.fabric8.kubernetes.api.model.ContainerBuilder; import io.fabric8.kubernetes.api.model.ContainerPortBuilder; import io.fabric8.kubernetes.api.model.LabelSelectorBuilder; @@ -11,12 +16,7 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder; import io.fabric8.kubernetes.api.model.apps.DeploymentSpecBuilder; -import io.fabric8.kubernetes.client.KubernetesClient; -import io.javaoperatorsdk.operator.api.reconciler.Context; -import io.javaoperatorsdk.operator.api.reconciler.Reconciler; -import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import org.apache.commons.collections.CollectionUtils; - import java.util.HashMap; import java.util.List; import java.util.Map; @@ -29,48 +29,51 @@ public MemcachedReconciler(KubernetesClient client) { this.client = client; } + // TODO Fill in the rest of the reconciler @Override - public UpdateControl reconcile(Memcached resource, Context context) { + public UpdateControl reconcile( + Memcached resource, Context context) { + // TODO: fill in logic + Deployment deployment = client.apps() + .deployments() + .inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()) + .get(); + + if (deployment == null) { + Deployment newDeployment = createMemcachedDeployment(resource); + client.apps().deployments().create(newDeployment); + return UpdateControl.noUpdate(); + } + + int currentReplicas = deployment.getSpec().getReplicas(); + int requiredReplicas = resource.getSpec().getSize(); + + if (currentReplicas != requiredReplicas) { + deployment.getSpec().setReplicas(requiredReplicas); + client.apps().deployments().createOrReplace(deployment); + return UpdateControl.noUpdate(); + } + + List pods = client.pods() + .inNamespace(resource.getMetadata().getNamespace()) + .withLabels(labelsForMemcached(resource)) + .list() + .getItems(); + + List podNames = + pods.stream().map(p -> p.getMetadata().getName()).collect(Collectors.toList()); + + + if (resource.getStatus() == null + || !CollectionUtils.isEqualCollection(podNames, resource.getStatus().getNodes())) { + if (resource.getStatus() == null) resource.setStatus(new MemcachedStatus()); + resource.getStatus().setNodes(podNames); + return UpdateControl.updateResource(resource); + } - Deployment deployment = client.apps() - .deployments() - .inNamespace(resource.getMetadata().getNamespace()) - .withName(resource.getMetadata().getName()) - .get(); - - if (deployment == null) { - Deployment newDeployment = createMemcachedDeployment(resource); - client.apps().deployments().create(newDeployment); return UpdateControl.noUpdate(); - } - - int currentReplicas = deployment.getSpec().getReplicas(); - int requiredReplicas = resource.getSpec().getSize(); - - if (currentReplicas != requiredReplicas) { - deployment.getSpec().setReplicas(requiredReplicas); - client.apps().deployments().createOrReplace(deployment); - return UpdateControl.noUpdate(); - } - - List pods = client.pods() - .inNamespace(resource.getMetadata().getNamespace()) - .withLabels(labelsForMemcached(resource)) - .list() - .getItems(); - - List podNames = - pods.stream().map(p -> p.getMetadata().getName()).collect(Collectors.toList()); - - if (resource.getStatus() == null - || !CollectionUtils.isEqualCollection(podNames, resource.getStatus().getNodes())) { - if (resource.getStatus() == null) resource.setStatus(new MemcachedStatus()); - resource.getStatus().setNodes(podNames); - return UpdateControl.updateStatus(resource); - } - - return UpdateControl.noUpdate(); } private Map labelsForMemcached(Memcached m) { @@ -82,44 +85,45 @@ private Map labelsForMemcached(Memcached m) { private Deployment createMemcachedDeployment(Memcached m) { return new DeploymentBuilder() - .withMetadata( - new ObjectMetaBuilder() - .withName(m.getMetadata().getName()) - .withNamespace(m.getMetadata().getNamespace()) - .withOwnerReferences( - new OwnerReferenceBuilder() - .withApiVersion("v1") - .withKind("Memcached") - .withName(m.getMetadata().getName()) - .withUid(m.getMetadata().getUid()) - .build()) - .build()) - .withSpec( - new DeploymentSpecBuilder() - .withReplicas(m.getSpec().getSize()) - .withSelector( - new LabelSelectorBuilder().withMatchLabels(labelsForMemcached(m)).build()) - .withTemplate( - new PodTemplateSpecBuilder() - .withMetadata( - new ObjectMetaBuilder().withLabels(labelsForMemcached(m)).build()) - .withSpec( - new PodSpecBuilder() - .withContainers( - new ContainerBuilder() - .withImage("memcached:1.4.36-alpine") - .withName("memcached") - .withCommand("memcached", "-m=64", "-o", "modern", "-v") - .withPorts( - new ContainerPortBuilder() - .withContainerPort(11211) - .withName("memcached") - .build()) - .build()) - .build()) - .build()) - .build()) - .build(); + .withMetadata( + new ObjectMetaBuilder() + .withName(m.getMetadata().getName()) + .withNamespace(m.getMetadata().getNamespace()) + .withOwnerReferences( + new OwnerReferenceBuilder() + .withApiVersion("v1") + .withKind("Memcached") + .withName(m.getMetadata().getName()) + .withUid(m.getMetadata().getUid()) + .build()) + .build()) + .withSpec( + new DeploymentSpecBuilder() + .withReplicas(m.getSpec().getSize()) + .withSelector( + new LabelSelectorBuilder().withMatchLabels(labelsForMemcached(m)).build()) + .withTemplate( + new PodTemplateSpecBuilder() + .withMetadata( + new ObjectMetaBuilder().withLabels(labelsForMemcached(m)).build()) + .withSpec( + new PodSpecBuilder() + .withContainers( + new ContainerBuilder() + .withImage("memcached:1.4.36-alpine") + .withName("memcached") + .withCommand("memcached", "-m=64", "-o", "modern", "-v") + .withPorts( + new ContainerPortBuilder() + .withContainerPort(11211) + .withName("memcached") + .build()) + .build()) + .build()) + .build()) + .build()) + .build(); } + } From 55a7365e23c47e2755bcd886b33fe72f9e7ed7c9 Mon Sep 17 00:00:00 2001 From: laxmikantbpandhare Date: Fri, 3 Jun 2022 11:30:46 -0700 Subject: [PATCH 2/4] modified tutorial --- docs/tutorial.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/tutorial.md b/docs/tutorial.md index 3ca5538..8d54a7c 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -542,6 +542,14 @@ You can run the operator in a couple of ways. You can run it locally where the operator runs on your development machine and talks to the cluster. Or it can build images of your operator and run it directly in the cluster. + +There are three ways to run the operator: + +* Running the operator in the cluster +* Running locally outside the cluster +* 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 + + In this section we will: * install the CRD @@ -783,3 +791,25 @@ pod/memcached-sample-6c765df685-mfqnz 1/1 Running 0 If you modify the size field of the `memcached-sample.yaml` and re-apply it. The operator will trigger a reconcile and adjust the sample pods to the size given. + +### Deploy your Operator with OLM +First, install [OLM](https://sdk.operatorframework.io/docs/olm-integration/tutorial-bundle/#enabling-olm): + +``` +operator-sdk olm install +``` + +Bundle your operator, then build and push the bundle image. The [bundle](https://github.com/operator-framework/operator-registry/blob/v1.16.1/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. + +``` +make bundle bundle-build bundle-push +``` + +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 complete. + + +``` +operator-sdk run bundle /memcached-operator-bundle:v0.0.1 +``` + +Check out the [docs](https://sdk.operatorframework.io/docs/olm-integration/tutorial-bundle/) for a deep dive into operator-sdk's OLM integration. \ No newline at end of file From 17e11c5fbea101200d08c3950926b4e55f2d2355 Mon Sep 17 00:00:00 2001 From: laxmikantbpandhare Date: Fri, 3 Jun 2022 12:29:08 -0700 Subject: [PATCH 3/4] updated according to review comments --- docs/tutorial.md | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/docs/tutorial.md b/docs/tutorial.md index 8d54a7c..334ebc2 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -799,17 +799,42 @@ First, install [OLM](https://sdk.operatorframework.io/docs/olm-integration/tutor operator-sdk olm install ``` -Bundle your operator, then build and push the bundle image. The [bundle](https://github.com/operator-framework/operator-registry/blob/v1.16.1/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. +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`. + +Before running below command export the variables as shown below. + +``` +$ export USERNAME= +$ export VERSION=0.0.1 +$ export IMG=docker.io/$USERNAME/memcached-operator:v$VERSION // location where your operator image is hosted +$ export BUNDLE_IMG=docker.io/$USERNAME/memcached-operator-bundle:v$VERSION // location where your bundle will be hosted +``` ``` make bundle bundle-build bundle-push ``` -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 complete. +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. ``` operator-sdk run bundle /memcached-operator-bundle:v0.0.1 ``` -Check out the [docs](https://sdk.operatorframework.io/docs/olm-integration/tutorial-bundle/) for a deep dive into operator-sdk's OLM integration. \ No newline at end of file +The result of the above command is as below: + +``` +INFO[0009] Successfully created registry pod: docker-io-013859989-memcached-quarkus-operator-bundle-v0-1-1 +INFO[0009] Created CatalogSource: memcached-quarkus-operator-catalog +INFO[0009] OperatorGroup "operator-sdk-og" created +INFO[0009] Created Subscription: memcached-quarkus-operator-v0-1-1-sub +INFO[0013] Approved InstallPlan install-6n8vm for the Subscription: memcached-quarkus-operator-v0-1-1-sub +INFO[0013] Waiting for ClusterServiceVersion "default/memcached-quarkus-operator.v0.1.1" to reach 'Succeeded' phase +INFO[0013] Waiting for ClusterServiceVersion "default/memcached-quarkus-operator.v0.1.1" to appear +INFO[0020] Found ClusterServiceVersion "default/memcached-quarkus-operator.v0.1.1" phase: Pending +INFO[0021] Found ClusterServiceVersion "default/memcached-quarkus-operator.v0.1.1" phase: Installing +INFO[0051] Found ClusterServiceVersion "default/memcached-quarkus-operator.v0.1.1" phase: Succeeded +INFO[0051] OLM has successfully installed "memcached-quarkus-operator.v0.1.1" +``` + +Check out the [docs](https://sdk.operatorframework.io/docs/olm-integration/tutorial-bundle/) for a deep dive into operator-sdk's OLM integration. From 946a64cfc28ae1e26dc51316a459387669455d40 Mon Sep 17 00:00:00 2001 From: laxmikantbpandhare Date: Fri, 3 Jun 2022 12:35:39 -0700 Subject: [PATCH 4/4] updated according to review comments --- docs/tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorial.md b/docs/tutorial.md index 334ebc2..2e44b5b 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -801,7 +801,7 @@ operator-sdk olm install 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`. -Before running below command export the variables as shown below. +Before running below command export environment variables as shown below. ``` $ export USERNAME=